- spider can read archives now
- items are indexed and queryArchive sort of works items get a socre element - port some sort / session things from oxdb - transparent png reflections
This commit is contained in:
parent
d4c2fe794f
commit
0d3592374d
8 changed files with 408 additions and 65 deletions
|
|
@ -6,10 +6,13 @@ from turbogears import controllers, expose, validate, error_handler
|
|||
from model import *
|
||||
from turbogears import identity, redirect
|
||||
from cherrypy import request, response
|
||||
import cherrypy
|
||||
|
||||
# import logging
|
||||
# log = logging.getLogger("oilarchive.controllers")
|
||||
|
||||
# from oilarchive import json
|
||||
from oilarchive import json
|
||||
|
||||
import oilcache
|
||||
from forms import forms
|
||||
from sortname import sortname
|
||||
|
|
@ -20,8 +23,12 @@ class View:
|
|||
return dict(item = item)
|
||||
|
||||
def icon(self, item):
|
||||
response.headerMap['Content-Type'] = "image/png"
|
||||
return oilcache.icon(item)
|
||||
response.headerMap['Content-Type'] = "image/jpeg"
|
||||
return oilcache.loadIcon(item)
|
||||
|
||||
def icon_reflection(self, item):
|
||||
response.headerMap['Content-Type'] = "image/jpeg"
|
||||
return oilcache.loadIconReflection(item)
|
||||
|
||||
@expose()
|
||||
def default(self, id, *args, **kw):
|
||||
|
|
@ -29,8 +36,10 @@ class View:
|
|||
item = ArchiveItem.byHashId(id)
|
||||
if not args:
|
||||
return self.view(item)
|
||||
elif args[0] == 'icon.png':
|
||||
elif args[0] == 'icon.jpg':
|
||||
return self.icon(item)
|
||||
elif args[0] == 'icon_reflection.jpg':
|
||||
return self.icon_reflection(item)
|
||||
elif args[0] == 'json':
|
||||
return item.json
|
||||
|
||||
|
|
@ -96,13 +105,6 @@ class Root(controllers.RootController):
|
|||
admin = Admin()
|
||||
api = Api()
|
||||
|
||||
@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=".templates.login")
|
||||
def login(self, forward_url=None, previous_url=None, *args, **kw):
|
||||
if not identity.current.anonymous \
|
||||
|
|
@ -132,3 +134,98 @@ class Root(controllers.RootController):
|
|||
def logout(self):
|
||||
identity.current.logout()
|
||||
raise redirect("/")
|
||||
|
||||
def default_search_values(self):
|
||||
return dict(q = '', f = 'all', s = 'title', o = 0, n = 60, l = 'all', v = 'icon', length = 0)
|
||||
|
||||
_sort_map = {
|
||||
'id': 'imdb',
|
||||
'director': 'director_html',
|
||||
'writer': 'writer_html',
|
||||
'language': 'language_html',
|
||||
'releasedate': 'release_date',
|
||||
'cast': 'cast_html',
|
||||
'genre': 'genre_html',
|
||||
'keywords': 'keywords_html',
|
||||
'connections': 'connections_sort',
|
||||
'title': 'title_sort',
|
||||
'country': 'country_html',
|
||||
'producer': 'producer_html',
|
||||
'summary': 'plot',
|
||||
'trivia': 'plot',
|
||||
'date': 'latest_file_date',
|
||||
'year': 'release_date',
|
||||
}
|
||||
|
||||
def get_sort(self, s):
|
||||
s = str(self._sort_map.get(s, s))
|
||||
if s in ('release_date', 'size', 'pub_date'):
|
||||
s = '-%s' % s
|
||||
return s
|
||||
|
||||
_field_map = {
|
||||
'title': ArchiveItem.q.title,
|
||||
'author': ArchiveItem.q.author,
|
||||
}
|
||||
|
||||
_search_map = {
|
||||
'summary': 'plot',
|
||||
'trivia': 'plot',
|
||||
'releasedate': 'release_date',
|
||||
'script': 'year',
|
||||
'title': 'year',
|
||||
'director': 'year'
|
||||
}
|
||||
|
||||
@expose(template=".templates.iconview")
|
||||
def search(self, q = '', f = None, s = None, o = -1, n = None, l = None, v = None):
|
||||
search = cherrypy.session.get('search', self.default_search_values())
|
||||
if not v:
|
||||
v = search['v']
|
||||
if not l:
|
||||
l = search['l']
|
||||
if not n:
|
||||
n = search['n']
|
||||
if o == -1:
|
||||
o = search['o']
|
||||
if not s:
|
||||
s = search['s']
|
||||
if not f:
|
||||
f = search['f']
|
||||
|
||||
o = int(o)
|
||||
n = int(n)
|
||||
|
||||
search = dict(q = q, f = f, s = s, o = o, n = n, l = l, v = v)
|
||||
|
||||
tg_template = ".templates.iconview"
|
||||
if v == 'list':
|
||||
tg_template = ".templates.listview"
|
||||
if v == 'quote':
|
||||
tg_template = ".templates.quoteview"
|
||||
|
||||
orderBy = [self.get_sort(s), 'title_sort', 'title']
|
||||
items = []
|
||||
if q:
|
||||
items = queryArchive(q)
|
||||
//items = ArchiveItems.select(LIKE(ArchiveItems.q.text, '%' + q + '%'), orderBy = orderBy)
|
||||
sort = s
|
||||
if sort.startswith('-'):
|
||||
sort = sort[1:]
|
||||
sort = self._search_map.get(sort, sort)
|
||||
sort = self._sort_map.get(sort, sort)
|
||||
print sort
|
||||
if type(items) == list:
|
||||
search['length'] = len(items)
|
||||
else:
|
||||
search['length'] = items.count()
|
||||
cherrypy.session['search'] = search
|
||||
return dict(items = items[o:o+n], sort = sort, search = search, tg_template = tg_template)
|
||||
|
||||
@expose(template=".templates.listview")
|
||||
# @identity.require(identity.in_group("admin"))
|
||||
def default(self, hashID = '', **args):
|
||||
if hashID and len(hashID) == 32:
|
||||
return self.view(hashID, args)
|
||||
return self.search(**args)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue