- 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
|
|
@ -7,6 +7,10 @@ from datetime import datetime
|
|||
from turbogears.database import PackageHub
|
||||
from sqlobject import *
|
||||
from turbogears import identity
|
||||
from scrapeit import read_url
|
||||
import simplejson
|
||||
|
||||
from oilspider import jsonLoadArchiveItem, jsonPrepareArchiveItem, jsonImportArchiveItem
|
||||
|
||||
hub = PackageHub("oilarchive")
|
||||
__connection__ = hub
|
||||
|
|
@ -14,9 +18,11 @@ __connection__ = hub
|
|||
|
||||
class ArchiveItem(SQLObject):
|
||||
hashId = UnicodeCol(alternateID = True, length=128)
|
||||
archiveId = UnicodeCol()
|
||||
title = UnicodeCol()
|
||||
description = UnicodeCol()
|
||||
author = UnicodeCol()
|
||||
authorSort = UnicodeCol(default = '')
|
||||
text = UnicodeCol() #Fulltext
|
||||
url = UnicodeCol()
|
||||
downloadURL = UnicodeCol()
|
||||
|
|
@ -27,7 +33,13 @@ class ArchiveItem(SQLObject):
|
|||
rights = IntCol() #-> int: 0 (free) - 5 (unfree)
|
||||
archiveName = UnicodeCol()
|
||||
archiveType = UnicodeCol()
|
||||
created = DateTimeCol(default=datetime.now)
|
||||
|
||||
def _set_author(self, value):
|
||||
self._SO_set_author(value)
|
||||
if not self.author_sort:
|
||||
self.author_sort = value
|
||||
|
||||
def _get_year(self):
|
||||
return self.releaseDate.strftime('%Y')
|
||||
|
||||
|
|
@ -42,12 +54,46 @@ class ArchiveItem(SQLObject):
|
|||
pubDate = self.pubDate,
|
||||
size = self.size,
|
||||
)
|
||||
|
||||
def update(self, data):
|
||||
for key in data:
|
||||
setattr(self, key, values[key])
|
||||
|
||||
def Archive(SQLObject):
|
||||
archiveName = UnicodeCol()
|
||||
url = UnicodeCol()
|
||||
archiveType = UnicodeCol()
|
||||
|
||||
class Archive(SQLObject):
|
||||
archiveName = UnicodeCol(alternateID = True, length = 1000)
|
||||
archiveUrl = UnicodeCol()
|
||||
archiveType = UnicodeCol(default=u'')
|
||||
ttl = IntCol(default = "15")
|
||||
pubDate = DateTimeCol(default=datetime.now)
|
||||
created = DateTimeCol(default=datetime.now)
|
||||
|
||||
def _get_pubDateTimestamp(self):
|
||||
return time.mktime(self.pubDate.timetuple())
|
||||
|
||||
def _get_update_url(self):
|
||||
return "%s?pubDate=%s" % (self.archiveUrl, self.pubDateTimestamp)
|
||||
|
||||
def data_url(self, id):
|
||||
return "%s?id=%s" % (self.archiveUrl, id)
|
||||
|
||||
def update(self):
|
||||
result = simplejson.loads(read_url(self.update_url))
|
||||
for id in result:
|
||||
data = jsonLoadArchiveItem(read_url(self.data_url(id)))
|
||||
q = ArchiveItem.select(AND(
|
||||
ArchiveItem.q.ArchiveId == id,
|
||||
ArchiveItem.q.ArchiveName == self.ArchiveName))
|
||||
if q.count() == 0:
|
||||
data = jsonPrepareArchiveItem(id, data)
|
||||
jsonImportArchiveItem(data)
|
||||
else:
|
||||
q[0].update(data)
|
||||
|
||||
|
||||
class SortName(SQLObject):
|
||||
name =UnicodeCol(length=1000, alternateID=True)
|
||||
|
||||
# identity models.
|
||||
class Visit(SQLObject):
|
||||
class sqlmeta:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue