8000 Delete static page (HHU #427) by JessicaBachmann · Pull Request #566 · liqd/adhocracy · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jul 11, 2019. It is now read-only.

Delete static page (HHU #427) #566

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/adhocracy/config/routing.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ def make_map(config):
map.connect('/static/{key}_{lang}',
controller='static', action='edit',
conditions=dict(method=['GET', 'HEAD']))
map.connect('/static/{key}_{lang}/ask_delete',
controller='static', action='ask_delete',
conditions=dict(method=['GET', 'HEAD']))
map.connect('/static/{key}_{lang}/delete',
controller='static',
action='delete',
conditions=dict(method=['POST', 'DELETE']))
map.connect('/static/{key}_{lang}',
controller='static', action='update',
conditions=dict(method=['POST']))
Expand Down
24 changes: 24 additions & 0 deletions src/adhocracy/controllers/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,30 @@ def edit(self, key, lang, errors=None):
return htmlfill.render(render('/static/edit.html', data),
defaults=defaults, errors=errors)

@guard_perms
def delete(self, key, lang):
backend = get_backend()
sp = backend.get(key, lang)
if not sp:
return ret_abort(_('Cannot find static page to delete'), code=404)
sp.delete()
helpers.flash(_('Page deleted'), 'notice')
return redirect(helpers.base_url('/static/'))

@guard_perms
def ask_delete(self, key, lang, errors=None):
backend = get_backend()
sp = backend.get(key, lang)
if not sp:
return ret_abort(_('Cannot find static page to delete'), code=404)
data = {'staticpage': sp}
defaults = {
'title': sp.title,
'body': sp.body,
}
return htmlfill.render(render('/static/ask_delete.html', data),
defaults=defaults, errors=errors)

@guard_perms
@csrf.RequireInternalRequest(methods=['POST'])
def update(self, key, lang):
Expand Down
4 changes: 4 additions & 0 deletions src/adhocracy/model/staticpage.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def create(cls, key, lang, title, body):
meta.Session.commit()
return s

def delete(self):
meta.Session.delete(self)
meta.Session.commit()

@classmethod
def all(cls):
q = meta.Session.query(cls)
Expand Down
28 changes: 28 additions & 0 deletions src/adhocracy/templates/static/ask_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<%inherit file="/template.html" />
<%namespace name="components" file="/components.html"/>

<%def name="title()">${_("Delete Page")}</%def>
<%def name="breadcrumbs()">
${b.static(_("Delete"))}
</%def>

<%block name="main_content">

<div class="mainbar">
<h2>
${_('Delete %(key)s (%(langname)s)') % {'key': c.staticpage.key,
'langname': h.staticpage.get_lang_info(c.staticpage.lang)['name']}}</h1>
</h2>
<form name="delete" class="inplace" method="POST"
action="${h.entity_url(c.staticpage)}/delete">
${h.field_token()|n}
<div class="warning_box">
${_("Are you sure you want to delete this static page?")|n}
</div>
<center>
<input type="submit" class="delete" value="${_('Confirm')}" />
</center>
</form>
</div>

</%block>
5 changes: 4 additions & 1 deletion src/adhocracy/templates/static/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@ <h1>${_('Edit %(key)s (%(langname)s)') % {'key': c.staticpage.key,
</form>

<a href="${h.base_url('/static/', instance=None)}">${_('Back to the list')}</a>
<br>

</%block>
<td><a href="${h.entity_url(c.staticpage)}/ask_delete">${_('Delete page')}</a></td>

</%block>
0