Giter Site home page Giter Site logo

pyramid_blogr's Issues

not able to edit the blog entires

Hi,

I am able to create entries in DB, but when i tried to edit the entries, getting the error " ProgrammingError: (pyodbc.ProgrammingError) ('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot update identity column 'id'. (8102) (SQLExecDirectW); [42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Statement(s) could not be prepared. (8180)") [SQL: u'UPDATE entries SET id=?, body=? WHERE entries.id = ?'] [parameters: (u'7', u'for testing in pyramid framework', 7)]".

Please some one help me on this.

Installation, setup, and `$VENV` path are in conflict

@ergo readme.txt conflicts with the tutorial's first two pages:

And those two pages are in conflict with each other because we now use a cookiecutter to get started and the path set for $VENV is wrong, having been set in the first page of the tutorial before the project has been created via cookiecutter in the subsequent step.

It's up to you to choose whether and when to set and use $VENV, ensuring the process and usage is consistent throughout the docs.

Suggestion: authentication form.

The index.mako template in the authentication topic shows the following code:

<%
from pyramid.security import authenticated_userid
user_id = authenticated_userid(request)
%>

I was wondering if it wouldn't be better to put that code in the views.py file instead, and send just the user_id variable to the template? I mean, to keep things in order.

PS: I'm loving your tutorial, I find it way better and clearer than the official one!

Yes,it should work

@view_config(route_name='blog_action', match_param="action=delete", permission='delete')
def blog_delete(request):
    blog_id = int(request.params.get('id', -1))
    entry = BlogRecordService.by_id(blog_id,request)
    if not entry:
        return HTTPNotFound()
    request.dbsession.delete(entry)
    return HTTPFound(location=request.route_url('home'))



<a href="{{ request.route_url('blog_action', action='delete',
        _query={'id':entry.id}) }}">Delete Entry</a>

unable to host in production with Nginx

In a shell:

$ git clone https://github.com/Pylons/pyramid_blogr.git
$ cd pyramid_blogr
$ python3.6 -m venv env
$ ./env/bin/pip3 install pyramid==1.7
$ ./env/bin/pip3 install -e .
$ initialize_pyramid_blogr_db development.ini
$ pserve development.ini

In another shell:

$ cat > nginx.conf <<EOF
events {
    worker_connections  1024;
}

http {
        server {
                listen 3456;
                location / {
                        proxy_pass http://127.0.0.1:6543;
                }
        }
}

daemon off;
EOF
$ nginx -c nginx.conf

Visit localhost:3456 in your web browser.

Notice the form on the page posts to 127.0.0.1:6543, a different host.

Expected the form to post to 127.0.0.1:3456.

AttributeError: add_request_method

(pyramid)piotrektt@BlackSun:~/Projects/pyramid/pyramid_blogr$ pserve --reload development.ini
Starting subprocess with file monitor
Traceback (most recent call last):
File "/home/piotrektt/Projects/pyramid/bin/pserve", line 9, in
load_entry_point('pyramid==1.3.4', 'console_scripts', 'pserve')()
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 47, in main
return command.run()
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 290, in run
relative_to=base, global_conf=vars)
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/pyramid/scripts/pserve.py", line 318, in loadapp
return loadapp(app_spec, name=name, relative_to=relative_to, *_kw)
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 247, in loadapp
return loadobj(APP, uri, name=name, *_kw)
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 272, in loadobj
return context.create()
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 710, in create
return self.object_type.invoke(self)
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/paste/deploy/loadwsgi.py", line 146, in invoke
return fix_call(context.object, context.global_conf, *_context.local_conf)
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/paste/deploy/util.py", line 55, in fix_call
val = callable(_args, **kw)
File "/home/piotrektt/Projects/pyramid/pyramid_blogr/pyramid_blogr/init.py", line 11, in main
config = Configurator(settings=settings)
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/pyramid/config/init.py", line 304, in init
exceptionresponse_view=exceptionresponse_view,
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/pyramid/config/init.py", line 426, in setup_registry
self.include(inc)
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/pyramid/config/init.py", line 737, in include
c(configurator)
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/pyramid_tm/init.py", line 138, in includeme
config.add_request_method('pyramid_tm.create_tm', name='tm', reify=True)
File "/home/piotrektt/Projects/pyramid/local/lib/python2.7/site-packages/pyramid/config/init.py", line 775, in getattr
raise AttributeError(name)
AttributeError: add_request_method

Suggestion: Adding remove posts functionality

It would be nice to add remove posts functionality. To improve this example.

Thanks!

in views.py

@view_config(route_name='blog_action', match_param="action=delete", permission='delete')
def blog_delete(request):
    entry_id = request.params.get('id', -1)
    entry = Entry.by_id(entry_id)
    if not entry:
        return HTTPNotFound()
    DBSession.delete(entry)
    return HTTPFound(location=request.route_url('home'))

at the end of view_blog.mako before

<code>
<a href="${request.route_url('blog_action', action='delete',
_query=(('id',entry.id),))}">Delete Entry</a>
</code>

in security.py

(Allow, Authenticated, 'delete'),

with big thanks to DimmuR

Consider re-organizing by component?

This is another very minor nit. I don't know if your goal with this repo is to really help people with "best practices". If so, here's a suggestion that really tortures the application of best practices.

IMO, we need to do a better job of encouraging code organization by component (e.g. pyramid_blogr/blog/models, pyramid_blogr/blog/views) instead of machinery (pyramid_blogr/models/blog, pyramid_blogr/views/blog). Then, each component has an init that does an includeme, pulled into the master init via config.include() with a route prefix.

This demo would only have "home" and "blog". Maybe login. So it is certainly torturing the idea. But at the same time, such a small application might be the best place to introduce this.

Does not work with Python 3

At the start fo the tutorial it should be mentioned that it works only with Python 2, because webhelpers is not available for Python 3. That's also a bit sad, since it is a good tutorial for newbies, but newbies should better start with Python 3.

Refactor to feature context and route factories

@ergo This ticket is to give you a heads-up on a direction we're going.

As discussed in email, getting a context via a route factory is a great way to both simplify views and tap into powerful framework features. It's a significant advantage for Pyramid, one we should showcase. This repo has been on a stead march to show "best practices" in Pyramid+SQLAlchemy, so let's start here.

This is just kind of an uber-ticket, to record a conversation. I will break it into individual steps, each with a ticket and PR. While I think I know what I'm doing, it won't surprise me if @mmerickel and @ergo correct me. :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.