Resources and content best practices

77 views
Skip to first unread message

Emmanuel Cazenave

unread,
Oct 6, 2014, 4:16:12 AM10/6/14
to substanc...@googlegroups.com
Hi there,

I'm trying to use substanced to build  a simple cms like application.
I'm having a hard time to figure out how to define my data model, I'll give an example regrading the homepage of my app.

Among other things I want to display a title and a text on the homepage.
 
Options 1: 
 
As the homepage data is kind of a root in the resources hierarchies I can define a 'DisplayableFolder' content type which inherit from 'substanced.folder.Folder' plus a 'title' and 'text' field. Then my 'home_view' callable will get call with an instance of 'DisplayableFolder'  as context when a user hit http://myapp.com
Is it ok to do it that way because it seems wrong to add 'text' and 'title' data to a mapping type like  'substanced.folder.Folder' ?

Options 2:

My 'home_view' callable gets called with a  'substanced.folder.Folder' instance as context and I manually iterate on its children to get for example a Document instance (Document would inherit from Persistent as you do in substanced documentation) and will get a titlte and a text from that Document instance.
It feels also a little bit wrong because it seems to break the Traversal idea of "the context I get in my view callable is really the data I need in that situation"

I'd like to have your opinion on that, or maybe if could link to some code that would be great.

Thank you.




David Glick (Glick Software)

unread,
Oct 6, 2014, 11:51:13 AM10/6/14
to substanc...@googlegroups.com
I think it's fine for a content type to both be a mapping and have its own properties (option 1).
--
You received this message because you are subscribed to the Google Groups "substanced-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to substanced-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tres Seaver

unread,
Oct 6, 2014, 12:29:27 PM10/6/14
to substanc...@googlegroups.com
On 10/06/2014 04:16 AM, Emmanuel Cazenave wrote:
> Hi there,
>
> I'm trying to use substanced to build a simple cms like application.
> I'm having a hard time to figure out how to define my data model, I'll give
> an example regrading the homepage of my app.
>
> Among other things I want to display a title and a text on the homepage.
>
> Options 1:
>
> As the homepage data is kind of a root in the resources hierarchies I can
> define a 'DisplayableFolder' content type which inherit from
> 'substanced.folder.Folder' plus a 'title' and 'text' field. Then my
> 'home_view' callable will get call with an instance of 'DisplayableFolder'
> as context when a user hit http://myapp.com
> Is it ok to do it that way because it seems wrong to add 'text' and 'title'
> data to a mapping type like 'substanced.folder.Folder' ?

If you define your own type for the root, deriving from
substanced.folder.Folder, it is perfectly normal to give it extra schema.
E.g., see the demo app's BlogSchema:


https://github.com/Pylons/substanced/blob/master/demos/blog/blog/resources.py#L159

used by the custom Blog (derived from Root) content type:

https://github.com/Pylons/substanced/blob/master/demos/blog/blog/resources.py#L189

> Options 2:
>
> My 'home_view' callable gets called with a 'substanced.folder.Folder'
> instance as context and I manually iterate on its children to get for
> example a Document instance (Document would inherit from Persistent as you
> do in substanced documentation) and will get a titlte and a text from that
> Document instance.

If you think a given document (e.g., 'index.html') as the "default page"
for a folder, then I would have the homepage_view() function just redirect
to the document.



Tres.
--
===================================================================
Tres Seaver +1 540-429-0999 tse...@palladion.com
Palladion Software "Excellence by Design" http://palladion.com

Emmanuel Cazenave

unread,
Oct 7, 2014, 5:02:12 AM10/7/14
to substanc...@googlegroups.com
Ok, thanks for your answers guys !
Reply all
Reply to author
Forward
0 new messages