first cut of oil archive model and some exposure via the controller
This commit is contained in:
parent
2bb49ff965
commit
cf7248c95d
7 changed files with 168 additions and 41 deletions
|
@ -1,22 +1,52 @@
|
||||||
|
# -*- Mode: Python; -*-
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=2:sts=2:ts=2
|
||||||
|
|
||||||
from turbogears import controllers, expose
|
from turbogears import controllers, expose
|
||||||
# from model import *
|
from model import *
|
||||||
from turbogears import identity, redirect
|
from turbogears import identity, redirect
|
||||||
from cherrypy import request, response
|
from cherrypy import request, response
|
||||||
# from oilarchive import json
|
|
||||||
# import logging
|
# import logging
|
||||||
# log = logging.getLogger("oilarchive.controllers")
|
# 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):
|
class Root(controllers.RootController):
|
||||||
@expose(template="oilarchive.templates.welcome")
|
@expose(template=".templates.welcome")
|
||||||
# @identity.require(identity.in_group("admin"))
|
# @identity.require(identity.in_group("admin"))
|
||||||
def index(self):
|
def index(self):
|
||||||
import time
|
import time
|
||||||
# log.debug("Happy TurboGears Controller Responding For Duty")
|
# log.debug("Happy TurboGears Controller Responding For Duty")
|
||||||
return dict(now=time.ctime())
|
return dict(now=time.ctime())
|
||||||
|
|
||||||
@expose(template="oilarchive.templates.login")
|
@expose(template=".templates.login")
|
||||||
def login(self, forward_url=None, previous_url=None, *args, **kw):
|
def login(self, forward_url=None, previous_url=None, *args, **kw):
|
||||||
|
|
||||||
if not identity.current.anonymous \
|
if not identity.current.anonymous \
|
||||||
and identity.was_login_attempted() \
|
and identity.was_login_attempted() \
|
||||||
and not identity.get_identity_errors():
|
and not identity.get_identity_errors():
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
# -*- Mode: Python; -*-
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=2:sts=2:ts=2
|
||||||
# A JSON-based API(view) for your app.
|
# A JSON-based API(view) for your app.
|
||||||
# Most rules would look like:
|
# Most rules would look like:
|
||||||
#
|
#
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
|
# -*- Mode: Python; -*-
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=2:sts=2:ts=2
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from turbogears.database import PackageHub
|
from turbogears.database import PackageHub
|
||||||
from sqlobject import *
|
from sqlobject import *
|
||||||
from turbogears import identity
|
from turbogears import identity
|
||||||
|
@ -6,6 +11,43 @@ from turbogears import identity
|
||||||
hub = PackageHub("oilarchive")
|
hub = PackageHub("oilarchive")
|
||||||
__connection__ = hub
|
__connection__ = hub
|
||||||
|
|
||||||
|
|
||||||
|
class ArchiveItem(SQLObject):
|
||||||
|
hash = UnicodeCol(alternateId = True)
|
||||||
|
title = UnicodeCol()
|
||||||
|
description = UnicodeCol()
|
||||||
|
author = UnicodeCol()
|
||||||
|
text = UnicodeCol() #Fulltext
|
||||||
|
url = UnicodeCol()
|
||||||
|
downloadURL = UnicodeCol()
|
||||||
|
icon = UnicodeCol()
|
||||||
|
releaseDate = DateTimeCol()
|
||||||
|
pubDate = DateTimeCol()
|
||||||
|
size = IntCol()
|
||||||
|
rights = IntCol() #-> int: 0 (free) - 5 (unfree)
|
||||||
|
archiveName = UnicodeCol()
|
||||||
|
archiveType = UnicodeCol()
|
||||||
|
|
||||||
|
def _get_year(self):
|
||||||
|
return self.releaseDate.strftime('%Y')
|
||||||
|
|
||||||
|
def _get_json(self):
|
||||||
|
return dict(
|
||||||
|
title = self.title,
|
||||||
|
description = self.description,
|
||||||
|
author = self.author,
|
||||||
|
url = self.url,
|
||||||
|
icon = '/view/%s/icon' % self.hash,
|
||||||
|
releaseDate = self.releaseDate,
|
||||||
|
pubDate = self.pubDate,
|
||||||
|
size = self.size,
|
||||||
|
)
|
||||||
|
|
||||||
|
def Archive(SQLObject):
|
||||||
|
archiveName = UnicodeCol()
|
||||||
|
url = UnicodeCol()
|
||||||
|
archiveType = UnicodeCol()
|
||||||
|
|
||||||
# identity models.
|
# identity models.
|
||||||
class Visit(SQLObject):
|
class Visit(SQLObject):
|
||||||
class sqlmeta:
|
class sqlmeta:
|
||||||
|
|
35
oilarchive/oilcache.py
Normal file
35
oilarchive/oilcache.py
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
# -*- Mode: Python; -*-
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=2:sts=2:ts=2
|
||||||
|
|
||||||
|
import os
|
||||||
|
from os.path import abspath, exists, join
|
||||||
|
|
||||||
|
from scrapeit.utils import read_url
|
||||||
|
|
||||||
|
cache_root = join(abspath(__file__), 'cache')
|
||||||
|
|
||||||
|
|
||||||
|
def load_file(f_name):
|
||||||
|
f = open(f_name)
|
||||||
|
data = f.read()
|
||||||
|
f.close()
|
||||||
|
return data
|
||||||
|
|
||||||
|
def save_file(f_name, data):
|
||||||
|
f = open(f_name, 'w')
|
||||||
|
f.write(data)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
def icon(item):
|
||||||
|
icon_root = join(cache_root, 'icon')
|
||||||
|
if not exists(icon_root):
|
||||||
|
os.makedirs(icon_root)
|
||||||
|
icon = join(icon_root, "%s.png" % item.hash)
|
||||||
|
if exists(icon):
|
||||||
|
data = laod_file(icon)
|
||||||
|
else:
|
||||||
|
data = read_url(item.icon)
|
||||||
|
save_file(icon, data)
|
||||||
|
return data
|
||||||
|
|
|
@ -2,11 +2,11 @@
|
||||||
|
|
||||||
version = "1.0"
|
version = "1.0"
|
||||||
|
|
||||||
# description = "Your plan to rule the world"
|
description="Oil21 Archive",
|
||||||
# long_description = "More description about your plan"
|
author="Oil21",
|
||||||
# author = "Your Name Here"
|
author_email="info@oil21.org",
|
||||||
# email = "YourEmail@YourDomain"
|
url="http://oil21.org",
|
||||||
# copyright = "Vintage 2006 - a good year indeed"
|
copyright = "no copyright 2007"
|
||||||
|
|
||||||
# if it's open source, you might want to specify these
|
# if it's open source, you might want to specify these
|
||||||
# url = "http://yourcool.site/"
|
# url = "http://yourcool.site/"
|
||||||
|
|
17
oilarchive/templates/view.kid
Normal file
17
oilarchive/templates/view.kid
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:py="http://purl.org/kid/ns#"
|
||||||
|
py:extends="'master.kid'">
|
||||||
|
<head>
|
||||||
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
|
||||||
|
<title>Oil Archive</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
|
||||||
|
<div class="item">
|
||||||
|
<img class="itemIcon" src="/view/${item.hash}/icon.png" />
|
||||||
|
<div class="author">${item.author}</div>
|
||||||
|
<div class="title">${item.title}</div>
|
||||||
|
<div class="description">${item.description}</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -3,7 +3,7 @@
|
||||||
py:extends="'master.kid'">
|
py:extends="'master.kid'">
|
||||||
<head>
|
<head>
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" py:replace="''"/>
|
||||||
<title>Welcome to TurboGears</title>
|
<title>Oil Archive</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue