-
Notifications
You must be signed in to change notification settings - Fork 12
/
model.py
111 lines (95 loc) · 3.94 KB
/
model.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from google.appengine.api import users
from google.appengine.ext import db
from datetime import datetime
class Cache(db.Model):
cachekey = db.StringProperty(multiline=False)
content = db.TextProperty()
class Blog(db.Model):
owner = db.UserProperty()
description = db.TextProperty()
baseurl = db.StringProperty(multiline=False,default='http://yourapp.appspot.com')
urlpath = db.StringProperty(multiline=False)
title = db.StringProperty(multiline=False)
subtitle = db.StringProperty(multiline=False)
entrycount = db.IntegerProperty(default=0)
layout = db.StringProperty(multiline=False,default='2cola',choices=[
'3cola', '3colb', '2cola','2colb'])
theme = db.StringProperty(multiline=False,default='freshpress.css')
area1 = db.TextProperty(default='')
area2 = db.TextProperty(default='')
area3 = db.TextProperty(default='')
archivehtml = db.TextProperty(default='')
tags = db.TextProperty(default='{}')
analyticsjs = db.StringProperty(multiline=True,default='')
def save(self):
self.put()
def initialsetup(self):
self.title = 'Your Blog Title'
self.subtitle = 'Your Blog Subtitle'
self.area1 = '<h3>Lower Left Title</h3>\nContent in lower left'
self.area2 = '<h3>Center Bottom Box</h3>\nContent in center footer'
self.area3 = '<h3>Right Footer</h3>\nContent in footer right'
class Archive(db.Model):
blog = db.ReferenceProperty(Blog)
monthyear = db.StringProperty(multiline=False)
"""March-08"""
entrycount = db.IntegerProperty(default=1)
date = db.DateTimeProperty(auto_now_add=True)
class Tag(db.Model):
blog = db.ReferenceProperty(Blog)
tag = db.StringProperty(multiline=False)
tagcount = db.IntegerProperty(default=0)
class Link(db.Model):
blog = db.ReferenceProperty(Blog)
href = db.StringProperty(multiline=False,default='')
linktype = db.StringProperty(multiline=False,default='blogroll')
linktext = db.StringProperty(multiline=False,default='')
class Entry(db.Model):
author = db.UserProperty()
blog = db.ReferenceProperty(Blog)
published = db.BooleanProperty(default=False)
content = db.TextProperty(default='')
title = db.StringProperty(multiline=False,default='')
date = db.DateTimeProperty(auto_now_add=True)
tags = db.ListProperty(db.Category)
slug = db.StringProperty(multiline=False,default='')
monthyear = db.StringProperty(multiline=False)
entrytype = db.StringProperty(multiline=False,default='post',choices=[
'post','page'])
commentcount = db.IntegerProperty(default=0)
def get_tags(self):
'''comma delimted list of tags'''
return ','.join([tag for tag in self.tags])
def set_tags(self, tags):
if tags:
tagstemp = [db.Category(tag.strip()) for tag in tags.split(',')]
self.tagsnew = [tag for tag in tagstemp if not tag in self.tags]
self.tags = tagstemp
tagswcommas = property(get_tags,set_tags)
def save(self):
"""
Use this instead of self.put(), as we do some other work here
"""
#TODO for each tag ensure it has a tag
# update # entry count if new
if not self.is_saved():
self.blog.entrycount += 1
self.blog.save()
my = datetime.now().strftime('%b-%Y')
archive = Archive.all().filter('monthyear',my).fetch(10)
if archive == []:
archive = Archive(blog=self.blog,monthyear=my)
self.monthyear = my
archive.put()
else:
# ratchet up the count
archive[0].entrycount += 1
archive[0].put()
#b = self.blog
#print b.tags
#for tag in self.tagsnew:
# if not b.tags.has_key(tag):
# b.tags.update({tag:1})
# else:
# b.tags.update({tag:b.tags[tag]+1})
self.put()