librelist archives

« back to archive

Grouping views in classes, Rails-style

Grouping views in classes, Rails-style

From:
Dun Peal
Date:
2014-11-12 @ 01:00
Hi,

In Rails, views are grouped in controller classes, such that a class
can represent an object - say, User - and particular HTTP routes map
to specific method calls on that class.

For instance, suppose our application manages users. We can create a
User class, and define (or sometimes, get for free as defaults) route
mappings such as:

/user/new => User.new()
/user/edit => User.edit()

What's the best way to do that in Flask?  Alternatively, is there a
different best-practice in Flask to accomplish the same underlying
goal: structure the code and group related views so they are easier to
find and maintain?

Thanks, D.

Re: [flask] Grouping views in classes, Rails-style

From:
Ioannis Pinakoulakis
Date:
2014-11-12 @ 06:49
Take a look at this as well: https://github.com/twilio/flask-restful


12 nov 2014, 02:00, ο/η Dun Peal <dunpealer@gmail.com> έγραψε:

> Hi,
> 
> In Rails, views are grouped in controller classes, such that a class
> can represent an object - say, User - and particular HTTP routes map
> to specific method calls on that class.
> 
> For instance, suppose our application manages users. We can create a
> User class, and define (or sometimes, get for free as defaults) route
> mappings such as:
> 
> /user/new => User.new()
> /user/edit => User.edit()
> 
> What's the best way to do that in Flask?  Alternatively, is there a
> different best-practice in Flask to accomplish the same underlying
> goal: structure the code and group related views so they are easier to
> find and maintain?
> 
> Thanks, D.

Re: [flask] Grouping views in classes, Rails-style

From:
Ioannis Pinakoulakis
Date:
2014-11-12 @ 09:45
Take a look at this as well: https://github.com/twilio/flask-restful 
<https://github.com/twilio/flask-restful>


> On 12 Nov 2014, at 02:00, Dun Peal <dunpealer@gmail.com> wrote:
> 
> Hi,
> 
> In Rails, views are grouped in controller classes, such that a class
> can represent an object - say, User - and particular HTTP routes map
> to specific method calls on that class.
> 
> For instance, suppose our application manages users. We can create a
> User class, and define (or sometimes, get for free as defaults) route
> mappings such as:
> 
> /user/new => User.new()
> /user/edit => User.edit()
> 
> What's the best way to do that in Flask?  Alternatively, is there a
> different best-practice in Flask to accomplish the same underlying
> goal: structure the code and group related views so they are easier to
> find and maintain?
> 
> Thanks, D.

Re: [flask] Grouping views in classes, Rails-style

From:
Dun Peal
Date:
2014-11-12 @ 21:05
Thanks, guys.

As far as I can tell, Blueprints won't enable the specific Rails code
structure I asked for: grouping related methods within a class.

The closest pattern they do enable is grouping them inside a module, such that:

/user/new => user.new()
/user/edit => user.edit()

Where `user` is a module nested under the global application package.

If there's any way to match more closely the pattern I was asking for,
do let me know. Otherwise, I will use this pattern above.

Thanks, D.

On Wed, Nov 12, 2014 at 1:45 AM, Ioannis Pinakoulakis
<giannis.pin@gmail.com> wrote:
> Take a look at this as well: https://github.com/twilio/flask-restful
>
>
> On 12 Nov 2014, at 02:00, Dun Peal <dunpealer@gmail.com> wrote:
>
> Hi,
>
> In Rails, views are grouped in controller classes, such that a class
> can represent an object - say, User - and particular HTTP routes map
> to specific method calls on that class.
>
> For instance, suppose our application manages users. We can create a
> User class, and define (or sometimes, get for f ree as defaults) route
> mappings such as:
>
> /user/new => User.new()
> /user/edit => User.edit()
>
> What's the best way to do that in Flask?  Alternatively, is there a
> different best-practice in Flask to accomplish the same underlying
> goal: structure the code and group related views so they are easier to
> find and maintain?
>
> Thanks, D.
>
>

Re: [flask] Grouping views in classes, Rails-style

From:
Brian O'Connor
Date:
2014-11-13 @ 00:47
Perhaps Flask-Classy might be what you're looking for?

http://pythonhosted.org/Flask-Classy/

On Wed, Nov 12, 2014 at 4:05 PM, Dun Peal <dunpealer@gmail.com> wrote:

> Thanks, guys.
>
> As far as I can tell, Blueprints won't enable the specific Rails code
> structure I asked for: grouping related methods within a class.
>
> The closest pattern they do enable is grouping them inside a module, such
> that:
>
> /user/new => user.new()
> /user/edit => user.edit()
>
> Where `user` is a module nested under the global application package.
>
> If there's any way to match more closely the pattern I was asking for,
> do let me know. Otherwise, I will use this pattern above.
>
> Thanks, D.
>
> On Wed, Nov 12, 2014 at 1:45 AM, Ioannis Pinakoulakis
> <giannis.pin@gmail.com> wrote:
> > Take a look at this as well: https://github.com/twilio/flask-restful
> >
> >
> > On 12 Nov 2014, at 02:00, Dun Peal <dunpealer@gmail.com> wrote:
> >
> > Hi,
> >
> > In Rails, views are grouped in controller classes, such that a class
> > can represent an object - say, User - and particular HTTP routes map
> > to specific method calls on that class.
> >
> > For instance, suppose our application manages users. We can create a
> > User class, and define (or sometimes, get for f ree as defaults) route
> > mappings such as:
> >
> > /user/new => User.new()
> > /user/edit => User.edit()
> >
> > What's the best way to do that in Flask?  Alternatively, is there a
> > different best-practice in Flask to accomplish the same underlying
> > goal: structure the code and group related views so they are easier to
> > find and maintain?
> >
> > Thanks, D.
> >
> >
>



-- 
Brian O'Connor

Re: [flask] Grouping views in classes, Rails-style

From:
Dun Peal
Date:
2014-11-13 @ 03:48
Yup, thanks, that's exactly what I was looking for.

At first glance, it looks like a more-or-less straightforward port of
the way Rails code is set up.

On Wed, Nov 12, 2014 at 4:47 PM, Brian O'Connor <gatzby3jr@gmail.com> wrote:
> Perhaps Flask-Classy might be what you're looking for?
>
> http://pythonhosted.org/Flask-Classy/
>
> On Wed, Nov 12, 2014 at 4:05 PM, Dun Peal <dunpealer@gmail.com> wrote:
>>
>> Thanks, guys.
>>
>> As far as I can tell, Blueprints won't enable the specific Rails code
>> structure I asked for: grouping related methods within a class.
>>
>> The closest pattern they do enable is grouping them inside a module, such
>> that:
>>
>> /user/new => user.new()
>> /user/edit => user.edit()
>>
>> Where `user` is a module nested under the global application package.
>>
>> If there's any way to match more closely the pattern I was asking for,
>> do let me know. Otherwise, I will use this pattern above.
>>
>> Thanks, D.
>>
>> On Wed, Nov 12, 2014 at 1:45 AM, Ioannis Pinakoulakis
>> <giannis.pin@gmail.com> wrote:
>> > Take a look at this as well: https://github.com/twilio/flask-restful
>> >
>> >
>> > On 12 Nov 2014, at 02:00, Dun Peal <dunpealer@gmail.com> wrote:
>> >
>> > Hi,
>> >
>> > In Rails, views are grouped in controller classes, such that a class
>> > can represent an object - say, User - and particular HTTP routes map
>> > to specific method calls on that class.
>> >
>> > For instance, suppose our application manages users. We can create a
>> > User class, and define (or sometimes, get for f ree as defaults) route
>> > mappings such as:
>> >
>> > /user/new => User.new()
>> > /user/edit => User.edit()
>> >
>> > What's the best way to do that in Flask?  Alternatively, is there a
>> > different best-practice in Flask to accomplish the same underlying
>> > goal: structure the code and group related views so they are easier to
>> > find and maintain?
>> >
>> > Thanks, D.
>> >
>> >
>
>
>
>
> --
> Brian O'Connor

Re: [flask] Grouping views in classes, Rails-style

From:
Aaron Crowder
Date:
2014-11-12 @ 02:58
Flask blueprints might be what you are looking for:
http://flask.pocoo.org/docs/0.10/blueprints/

On Tue Nov 11 2014 at 6:04:18 PM Dun Peal <dunpealer@gmail.com> wrote:

> Hi,
>
> In Rails, views are grouped in controller classes, such that a class
> can represent an object - say, User - and particular HTTP routes map
> to specific method calls on that class.
>
> For instance, suppose our application manages users. We can create a
> User class, and define (or sometimes, get for free as defaults) route
> mappings such as:
>
> /user/new => User.new()
> /user/edit => User.edit()
>
> What's the best way to do that in Flask?  Alternatively, is there a
> different best-practice in Flask to accomplish the same underlying
> goal: structure the code and group related views so they are easier to
> find and maintain?
>
> Thanks, D.
>