On Sat, May 25, 2019 at 9:56 AM Theron Luhn <
the...@luhn.com> wrote:
>
> Very nice! Several years ago I asked on this mailing list for some example Pyramid applications, this would have been a great one to look at.
>
> You’ve organized the modules by sections of the website, and the relevant views and models in each section. I usually do the inverse, split my app into views, models, templates, etc. I’d be interested to see what “best practice” is considered, I’ve always wondered how everybody else organizes their apps.
I organize mine by code type:
appname/__init__.py (top-level main, with imports only in functions)
app.py : application-wide things: auth policy, subscribers, layout, etc.
models/
core.py : column type subclasses, full-text search functions, etc
section1.py: models for section 1.
section2.py: models for section 2.
routes.py: Routes. (includeme.)
views:
__init__.py: View configurations. (Includeme. I avoid
@view_config because it's magical.)
section1/: Views for section 1.
__init__.py: Main views/small views for section 1.
alargeview.py: A large view with several private utility functions.
templates: Templates.
site: Site template, section templates, shared template functions, etc.
index.html: Main page template.
section1:
index.html: Section 1 main page.
I use Mako, template inheritance, PostgreSQL, SQLAlchemy,
SQLAlchemy-FullText-Search, and pyramid_redis_sessions.
Frontends I have only moderate experience with, but our frontend
developer organized things by code:
main.js: Top-level ("ready") functions, Backbone models and collections.
section1.js: Backbone views.
I made my own section, an Admin section, and for that I put most
things in admin.js, and if one page had a lot of things I put them all
in a separate file.
The front-end templates are Underscore templates embedded in the HTML
templates. I'm not quite satisfied with this because sometimes there's
a conflict between the Mako, Python, Javascript, and Underscore
syntaxes. Mako uses "<% ... %>" for Python escapes, while Underscore
uses "<% ... %>" for placeholders containing Javascript expressions.
We had to do some elaborate things to get these to coexist, and in one
case I had to pull some Javascript expressions out of the template and
put them into a function in the Underscore dict because they contained
'\:' (a Javascript regex pattern, but an invalid Python string
escape). This was deprecated in Python 3.6 and will be a syntax error
in 3.7, as I discovered when I upgraded PyTest and it showed me the
warnings that had been hidden. I'd like to move the Underscore
templates into different files somewhere, but since the rest of them
are working I've left them alone.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/12FDFC49-945A-40DD-BC0C-5F68AE547730%40luhn.com.
--
Mike Orr <
slugg...@gmail.com>