/
views.py
38 lines (32 loc) · 1.09 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from pyramid.httpexceptions import HTTPFound
from pyramid.view import view_defaults
from pyramid_zodbconn import get_connection
from ..interfaces import ISite
from ..sdi import (
mgmt_view,
check_csrf_token,
)
@view_defaults(
name='manage_db',
context=ISite,
renderer='templates/manage_db.pt',
permission='manage database')
class ManageDatabase(object):
def __init__(self, context, request):
self.context = context
self.request = request
@mgmt_view(request_method='GET', tab_title='Manage DB')
def view(self):
return {}
@mgmt_view(request_method='POST', request_param='pack')
def pack(self):
check_csrf_token(self.request)
conn = get_connection(self.request)
try:
days = int(self.request.POST['days'])
except:
self.request.session.flash('Invalid number of days', 'error')
conn.db().pack(days=days)
self.request.session.flash('Database packed to %s days' % days)
return HTTPFound(location=self.request.mgmt_path(
self.context, '@@manage_db'))