-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
51 lines (36 loc) · 1.36 KB
/
models.py
File metadata and controls
51 lines (36 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import cgi
import os
import uuid
import logging
from google.appengine.ext import db
class Pub(db.Model):
pub_id = db.StringProperty(required=True)
title = db.StringProperty(required=True)
author = db.StringProperty(required=True)
content = db.TextProperty(required=True)
date_published = db.DateTimeProperty(auto_now_add=True)
twitter_user = db.StringProperty(required=False)
bitly_user = db.StringProperty(required=False)
@staticmethod
def create_pub(title_arg, author_arg, content_arg):
newPub = Pub(pub_id= getUniqueId(), title=title_arg, content=content_arg, author=author_arg)
newPub.put()
return newPub
@staticmethod
def get_by_id(pub_id):
logging.info('Models.py - pub_id: %s' % pub_id)
return Pub.all().filter('pub_id = ', pub_id).get()
@staticmethod
def get_by_title(title):
return Pub.all().filter('title = ', title).get()
@staticmethod
def get_by_author(author):
return Pub.all().filter('author = ', author).get()
def getUniqueId():
"""Generate 4 character hex endcoded string as
a random identifier for offer, with collision detection"""
pub_id = uuid.uuid4().hex[:4]
existingPub = Pub.get_by_id(pub_id)
if existingPub:
generate_uuid()
return pub_id