first cut of oil archive model and some exposure via the controller

This commit is contained in:
j 2007-03-20 15:52:10 +00:00
commit cf7248c95d
7 changed files with 168 additions and 41 deletions

View file

@ -1,46 +1,76 @@
# -*- Mode: Python; -*-
# -*- coding: utf-8 -*-
# vi:si:et:sw=2:sts=2:ts=2
from turbogears import controllers, expose
# from model import *
from model import *
from turbogears import identity, redirect
from cherrypy import request, response
# from oilarchive import json
# import logging
# log = logging.getLogger("oilarchive.controllers")
# from oilarchive import json
import oilcache
class View:
@expose(template=".templates.view")
def view(self, item):
return dict(item = item)
def icon(self, item):
response.headerMap['Content-Type'] = "image/png"
return oilcache.icon(item)
@expose()
def default(self, id, *args, **kw):
try:
item = ArchiveItem.byHash(id)
if not args:
return self.view(item)
elif args[0] == 'icon.png':
return self.icon(item)
elif args[0] == 'json':
return item.json
except:
raise redirect("/")
class Root(controllers.RootController):
@expose(template="oilarchive.templates.welcome")
# @identity.require(identity.in_group("admin"))
def index(self):
import time
# log.debug("Happy TurboGears Controller Responding For Duty")
return dict(now=time.ctime())
@expose(template=".templates.welcome")
# @identity.require(identity.in_group("admin"))
def index(self):
import time
# log.debug("Happy TurboGears Controller Responding For Duty")
return dict(now=time.ctime())
@expose(template="oilarchive.templates.login")
def login(self, forward_url=None, previous_url=None, *args, **kw):
@expose(template=".templates.login")
def login(self, forward_url=None, previous_url=None, *args, **kw):
if not identity.current.anonymous \
and identity.was_login_attempted() \
and not identity.get_identity_errors():
raise redirect(forward_url)
if not identity.current.anonymous \
and identity.was_login_attempted() \
and not identity.get_identity_errors():
raise redirect(forward_url)
forward_url=None
previous_url= request.path
forward_url=None
previous_url= request.path
if identity.was_login_attempted():
msg=_("The credentials you supplied were not correct or "
"did not grant access to this resource.")
elif identity.get_identity_errors():
msg=_("You must provide your credentials before accessing "
"this resource.")
else:
msg=_("Please log in.")
forward_url= request.headers.get("Referer", "/")
response.status=403
return dict(message=msg, previous_url=previous_url, logging_in=True,
original_parameters=request.params,
forward_url=forward_url)
if identity.was_login_attempted():
msg=_("The credentials you supplied were not correct or "
"did not grant access to this resource.")
elif identity.get_identity_errors():
msg=_("You must provide your credentials before accessing "
"this resource.")
else:
msg=_("Please log in.")
forward_url= request.headers.get("Referer", "/")
response.status=403
return dict(message=msg, previous_url=previous_url, logging_in=True,
original_parameters=request.params,
forward_url=forward_url)
@expose()
def logout(self):
identity.current.logout()
raise redirect("/")
@expose()
def logout(self):
identity.current.logout()
raise redirect("/")