Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/models/db.py
diff options
context:
space:
mode:
authorJames Boisture <jboisture@jboisture-laptop.(none)>2010-07-29 18:05:01 (GMT)
committer James Boisture <jboisture@jboisture-laptop.(none)>2010-07-29 18:05:01 (GMT)
commit09e3eea7a72e9e2300b639f0356100c7b83b5dfb (patch)
treed3608997517daa0ae5f98e5bf5ba95c8e29520b9 /models/db.py
parentb817158f554f7b3342ecfe3ce24d04e91abed3c3 (diff)
made a lot of major changes because it has been a long time since I commited last. There are many new features. Also added app.yaml file which should be placed in the web2py directly in order for the URL to work properly.
Diffstat (limited to 'models/db.py')
-rw-r--r--models/db.py43
1 files changed, 39 insertions, 4 deletions
diff --git a/models/db.py b/models/db.py
index 6ce4922..a7c7732 100644
--- a/models/db.py
+++ b/models/db.py
@@ -1,22 +1,53 @@
+import uuid
+import time
+import pickle
+
+class RESIZE:
+ def __init__(self,nx=250,ny=32,error_message='not an image'):
+ (self.nx,self.ny,self.error_message)=(nx,ny,error_message)
+ def __call__(self,value):
+ import google.appengine.api as api
+ import cStringIO
+ try:
+ avatar = api.images.resize(value.file.read(), self.nx)
+ value.file = cStringIO.StringIO(avatar)
+ return (value,None)
+ except:
+ return (value,self.error_message)
+
+
if request.env.web2py_runtime_gae:
db = DAL('gae')
session.connect(request,response,db=db)
else:db = DAL("sqlite://storage.db")
+db.define_table('upload_key',
+ Field('upload_key', length=64, default=uuid.uuid4()),
+ Field('user'))
+
db.define_table('image',
Field('file', 'upload', requires=[IS_NOT_EMPTY(error_message="Please select a file to upload"), IS_UPLOAD_FILENAME(extension='ta', error_message="Must be a Turtle Art file")]),
- Field('title', requires=[IS_NOT_EMPTY(error_message="You must include a title"), IS_NOT_IN_DB(db, 'image.title', error_message="Title is already taken")]),
+ Field('title', requires=[IS_NOT_EMPTY(error_message="You must include a title")]),
Field('image_id'),
Field('creator', requires=IS_NOT_EMPTY(error_message="You must include your name")),
Field('description', 'text'),
- Field('views'),
- Field('newimage', 'upload', requires=[IS_NOT_EMPTY(error_message="Please select a image to upload"), IS_UPLOAD_FILENAME(extension='png', error_message="Must be a PNG image")]))
+ Field('views',default = 0),
+ Field('newimage', 'upload', requires=[IS_NOT_EMPTY(error_message="Please select a image to upload"), IS_UPLOAD_FILENAME(extension='png', error_message="Must be a PNG image")]),
+ Field('avatar',default = None),
+ Field('small_image','upload',requires=RESIZE()),
+ Field('favorite_users','text',default=pickle.dumps([]), writable=False, readable=False),
+ Field('upload_key', requires= [IS_NOT_IN_DB(db, 'image.upload_key'), IS_IN_DB(db, 'upload_key.upload_key', error_message="key not in database")]),
+ Field('Submit_Time', default = time.time()))
+
+
+
db.define_table('comment',
Field('image_id', db.image),
Field('author'),
Field('body', 'text'))
+
from gluon.tools import Auth
auth = Auth(globals(),db)
auth_table = db.define_table(
@@ -27,7 +58,11 @@ auth_table = db.define_table(
readable=False, label='Password'),
Field('registration_key', length=128, default= "",
writable=False, readable=False),
- Field('reset_password_key', length=128, default="",readable=False))
+ Field('favorites','text',default=pickle.dumps([]), writable=False, readable=False),
+ Field('requests','text',default=pickle.dumps([]), writable=False, readable=False),
+ Field('friends','text',default=pickle.dumps([]), writable=False, readable=False),
+ Field('avatar', default = None,writable=False,readable=False),
+ Field('reset_password_key', length=128, default="",readable=False, writable=False))
db.comment.image_id.requires = IS_IN_DB(db, db.image.image_id, '%(title)s')
db.comment.author.requires = IS_NOT_EMPTY()