On Sat, May 25, 2019 at 9:56 AM Theron Luhn <[email protected]> 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.
>
> What’s your experience with type hints/mypy? I was looking into using them
> in my applications, but decided it wouldn’t be worth it because Pyramid does
> not yet have support (there’s an open issue being discussed) and SQLAlchemy’s
> support is nascent (but very exciting!).
>
> — Theron
>
>
>
> On May 25, 2019, at 4:52 AM, Nejc Zupan <[email protected]> wrote:
>
> Hey all!
>
> TL;DR: I’m working on a RealWorld.io backend implementation in Pyramid. I’d
> like to ask fellow pharaohs and mummies to review my code so that I don’t
> teach
> people bad patterns: https://github.com/niteoweb/pyramid-realworld-example-app
>
> RealWorld.io is a community effort of implementing a Medium.com clone app in a
> number of interchangeable frontend and backend frameworks. People can then use
> these implementations to compare different stacks and to learn about best
> practices for a chosen framework.
>
> There already exist several Python backend implementations: Django, Flask,
> Serverless Python on AWS, etc. But not one for Pyramid!
>
> So I've built it! I chose to use SQLAlchemy as my ORM and pyramid_openapi3 to
> handle the API things. The example has 100% tests & types coverage, a bunch
> of linters, etc. It's basically a dump of best practices that we have
> developed
> internally in Niteo in recent years.
>
> And there's the catch: our best practices might be outright wrong. I don't
> want
> to teach people bad patterns. So I'm asking for code review before I submit
> the repository to the "official" list of RealWorld implementations.
>
> Please review the code in
> https://github.com/niteoweb/pyramid-realworld-example-app
> and let me know what could be improved. Either as a reply to this email, as
> issues on the repo, or even better, as pull requests.
>
>
> Thanks a ton!
> z.
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pylons-discuss/B152285B-BAFC-48A0-9DCE-0AA11939E635%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "pylons-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/pylons-discuss/12FDFC49-945A-40DD-BC0C-5F68AE547730%40luhn.com.
> For more options, visit https://groups.google.com/d/optout.
--
Mike Orr <[email protected]>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pylons-discuss/CAH9f%3Duq%2BQsQCu%2BMui72bggGAehmpTqC9oJOxNtQxbc83eBmSKg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.