Pylons / pyramid_blogr

Pyramid_blogr is an example implementation of Flaskr app with Pyramid Web Framework
72 stars 39 forks source link

Suggestion: Adding remove posts functionality #6

Closed ghost closed 5 years ago

ghost commented 11 years ago

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

stevepiercy commented 8 years ago

@ghost would you please submit a PR with these suggested changes? This would be the best step to use:

http://pyramid-blogr.readthedocs.org/en/latest/blog_create_and_update_view.html

I've recently overhauled the docs so that it is easier to find the files that need to be updated, and I was recently writing up a list of missing features, and noticed this issue report.

Thank you!

stevepiercy commented 8 years ago

This issue needs some modifications to the code. The file names have been modified, entry_id needs to be renamed to blog_id and cast to an int, we've renamed a class from Entry to BlogRecordService, and we're now using Jinja2 instead of Mako. Otherwise, it works. I think I'll keep this issue open as a way to rope in a new contributor at an upcoming Santa Cruz Python Meetup.

kenlittleton commented 5 years ago

Updated code to delete post...

Add to 'views/blog.py':

@view_config(
    route_name="blog_action",
    match_param="action=delete",
    renderer="pyramid_blogr:templates/edit_blog.jinja2",
    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"))

In 'templates/view_blog.jinja2', after the "Edit entry" link:

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

In 'security.py', append to the "__acl__" list:

(Allow, Authenticated, "delete"),
stevepiercy commented 5 years ago

@kenlittleton would you please create a PR with your suggested changes?

ergo commented 5 years ago

Hello everyone, I think maybe we should let the reader implement the delete action on their own as home exercise? Also if I'm supposed to merge PR #67 this would also require changing documentation and code in all steps of the tutorial. Adding functionality to blog itself is not a problem, this application is not being meant to be an actual blog platform, but to teach basics of project building with pyramid.

ergo commented 5 years ago

@stevepiercy @kenlittleton I don't want to discourage anyone working on this though, maybe we can leave this as an example how delete can be implemented. Maybe there are some other areas that we can expand the tutorial in the future.

stevepiercy commented 5 years ago

Sorry, I missed this https://docs.pylonsproject.org/projects/pyramid-blogr/en/1.10.x/summary.html#new-features and I overlooked the impact to docs and source code.

To elaborate for @kenlittleton, the PR cannot be merged in its current state. Both the docs and source code from the "6. Adding and editing blog entries" step onward would need to be updated. @ergo if those changes were made, would it be acceptable to merge?

If we don't want to update the tutorial and all its subsequent steps, I think the "Open" status of this issue is misleading and encouraged the PR. Perhaps closing both this issue and the related PR would indicate there is an example solution?

ergo commented 5 years ago

Yes I'll accept the PR after all @kenlittleton did all the work and there is nothing wrong with it. It just misses all the docs and source changes. So I leave this up to Ken to continue working on this and update all the steps forward.

kenlittleton commented 5 years ago

I apologize but I'm not comfortable making changes to the published tutorial documentation. I would prefer @stevepiercy's suggestion of closing both the issue and the PR. The new_features link in the summary should suffice to allow one to find the code.

ergo commented 5 years ago

Ok, no problem, thanks for the effort. The blame is on me for leaving the issue unattended.