- sortnames, json api and function and minimal admin interface
- start of admin interface for archives - highlight function
This commit is contained in:
parent
75eae7b7de
commit
d4c2fe794f
16 changed files with 290 additions and 84 deletions
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=2:sts=2:ts=2
|
||||
|
||||
from turbogears import controllers, expose
|
||||
from turbogears import controllers, expose, validate, error_handler
|
||||
from model import *
|
||||
from turbogears import identity, redirect
|
||||
from cherrypy import request, response
|
||||
|
|
@ -11,7 +11,8 @@ from cherrypy import request, response
|
|||
|
||||
# from oilarchive import json
|
||||
import oilcache
|
||||
|
||||
from forms import forms
|
||||
from sortname import sortname
|
||||
|
||||
class View:
|
||||
@expose(template=".templates.view")
|
||||
|
|
@ -36,9 +37,64 @@ class View:
|
|||
except:
|
||||
raise redirect("/")
|
||||
|
||||
class Admin:
|
||||
@expose('.templates.admin_index')
|
||||
def index(self):
|
||||
return dict()
|
||||
|
||||
@expose('.templates.admin_archives')
|
||||
def archives(self, tg_errors=None):
|
||||
if tg_errors:
|
||||
flash("There was a problem with the form!")
|
||||
return dict(
|
||||
add_archive = forms.add_archive,
|
||||
archives = Archive.select(orderBy = "archiveName"),
|
||||
)
|
||||
|
||||
@expose()
|
||||
@validate(form = forms.add_archive)
|
||||
@error_handler(archives)
|
||||
def archives_add(self, **data):
|
||||
new = Archive(
|
||||
archiveName = data['archiveName'],
|
||||
archiveType = data['archiveType'],
|
||||
archiveUrl = data['archiveUrl'],
|
||||
ttl = int(data['ttl']),
|
||||
)
|
||||
raise redirect('archives')
|
||||
|
||||
@expose('.templates.admin_sortnames')
|
||||
def sortnames(self, tg_errors=None):
|
||||
if tg_errors:
|
||||
flash("There was a problem with the form!")
|
||||
q = SortName.select(orderBy="name")
|
||||
names = "\n".join([i.name for i in q])
|
||||
sortnames_values = dict(names = names)
|
||||
return dict(sortnames_values = sortnames_values, sortnames_form = forms.sortnames)
|
||||
|
||||
@expose()
|
||||
@validate(form = forms.sortnames)
|
||||
@error_handler(sortnames)
|
||||
def sortnames_save(self, **data):
|
||||
names = data['names']
|
||||
if names:
|
||||
for b in SortName.select():
|
||||
SortName.delete(b.id)
|
||||
names = names.split('\n')
|
||||
for name in names:
|
||||
SortName(name = name)
|
||||
raise redirect('sortnames')
|
||||
|
||||
class Api:
|
||||
@expose()
|
||||
def sortname(self, name):
|
||||
sname = sortname(name)
|
||||
return dict(sortname = sname, name = name)
|
||||
|
||||
class Root(controllers.RootController):
|
||||
view = View()
|
||||
admin = Admin()
|
||||
api = Api()
|
||||
|
||||
@expose(template=".templates.welcome")
|
||||
# @identity.require(identity.in_group("admin"))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue