public
Description: A Google App Engine based blogging platform using python
Homepage: http://aaronspotlatch.appspot.com/page/potlatchblog
Clone URL: git://github.com/araddon/potlatchblog.git
fleshed out a migration tool for new features, implemented for archive feature
Aaron Raddon (author)
Tue May 13 10:27:51 -0700 2008
commit  cbd2b3abb58e9b0798bd6838f26a1a90554ce4d9
tree    6fb7cd7a35d40b1bc75c4feefb67477d251b82e7
parent  c5d3e3a87d345535e639be89bdec340ebfccb8ab
...
2
3
4
5
 
 
6
7
8
...
44
45
46
 
47
48
49
...
115
116
117
118
 
119
120
121
...
215
216
217
218
219
220
221
222
223
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
224
225
226
...
251
252
253
254
 
255
256
257
...
2
3
4
 
5
6
7
8
9
...
45
46
47
48
49
50
51
...
117
118
119
 
120
121
122
123
...
217
218
219
 
 
 
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
...
269
270
271
 
272
273
274
275
0
@@ -2,7 +2,8 @@ import cgi, os
0
 from functools import wraps
0
 import wsgiref.handlers
0
 
0
-from google.appengine.ext.webapp import template
0
+from google.appengine.ext.webapp import template, \
0
+    WSGIApplication
0
 from google.appengine.api import users
0
 import webapp as webapp2
0
 from google.appengine.ext import webapp
0
@@ -44,6 +45,7 @@ class BaseController(webapp2.RequestHandler):
0
     def __init__(self):
0
         self.template = 'index.html'
0
         self.blog = Blog.all().fetch(1)
0
+        #self.app_version = WSGIApplication.active_instance
0
         if self.blog == []:
0
             pass
0
         else:
0
@@ -115,7 +117,7 @@ class PublicPage(BasePublicPage):
0
 class ArchivePage(BasePublicPage):
0
     def get(self,monthyear=None):
0
         entries = Entry.all().filter('monthyear', monthyear).\
0
-            filter("published =", True).order('-date')
0
+            filter("published =", True).filter('entrytype','post').order('-date')
0
         self.render('views/index.html',{'entries':entries})
0
     
0
 
0
@@ -215,12 +217,28 @@ class AdminList(BaseController):
0
     @requires_admin
0
     def get(self,entrytype='post',template_vals={}):
0
         entries = Entry.all().filter('entrytype =',entrytype).order('-date')
0
-        archive = Archive.all()
0
-        #for a in archive:
0
-        #    a.delete()
0
         self.render('views/admin.html',{'entries':entries})
0
     
0
 
0
+class AdminMigrate(BaseController):
0
+    @requires_admin
0
+    def get(self,to_version='1.15'):
0
+        if to_version == '1.16':
0
+            archives = Archive.all()
0
+            for a in archives:
0
+                a.delete()
0
+            entries = Entry.all().filter('entrytype =','post')
0
+            for e in entries:
0
+                e.update_archive()
0
+                e.monthyear = e.date.strftime('%b-%Y')
0
+                e.put()
0
+                print 'update to %s' % (e.monthyear)
0
+            archive = Archive.all()
0
+            self.blog.blogversion = to_version
0
+            self.blog.put()
0
+    
0
+
0
+
0
 class AdminLinks(BaseController):
0
     @requires_admin
0
     def get(self,linktype='blogroll'):
0
@@ -251,7 +269,7 @@ def main():
0
                      ('/admin/entry/(.*)', AdminEntry),
0
                      ('/admin/links/(.*)', AdminLinks),
0
                      ('/admin/setup', AdminConfig),
0
-                     ('/admin/migrate', AdminMigrate),
0
+                     ('/admin/migrate/(.*)', AdminMigrate),
0
                      ('/tag/(.*)', TagPage),
0
                      ('/atom', FeedHandler),
0
                      (r'/page/(.*)', PublicPage),
...
14
15
16
 
17
18
19
...
79
80
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
83
84
...
89
90
91
92
93
94
95
96
97
98
99
100
101
 
 
102
103
104
...
14
15
16
17
18
19
20
...
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
...
105
106
107
 
 
 
 
 
 
 
 
 
 
108
109
110
111
112
0
@@ -14,6 +14,7 @@ class Blog(db.Model):
0
     title = db.StringProperty(multiline=False)
0
     subtitle = db.StringProperty(multiline=False)
0
     entrycount = db.IntegerProperty(default=0)
0
+    blogversion = db.StringProperty(multiline=False,default='1.15')
0
     layout = db.StringProperty(multiline=False,default='2cola',choices=[
0
         '3cola', '3colb', '2cola','2colb'])
0
     theme = db.StringProperty(multiline=False,default='freshpress.css')
0
@@ -79,6 +80,21 @@ class Entry(db.Model):
0
     
0
     tagswcommas = property(get_tags,set_tags)
0
     
0
+    def update_archive(self):
0
+        """Checks to see if there is a month-year entry for the
0
+        month of current blog, if not creates it and increments count"""
0
+        my = datetime.now().strftime('%b-%Y') # May-2008
0
+        archive = Archive.all().filter('monthyear',my).fetch(10)
0
+        if archive == []:
0
+            archive = Archive(blog=self.blog,monthyear=my)
0
+            self.monthyear = my
0
+            archive.put()
0
+        else:
0
+            # ratchet up the count
0
+            archive[0].entrycount += 1
0
+            archive[0].put()
0
+        
0
+    
0
     def save(self):
0
         """
0
         Use this instead of self.put(), as we do some other work here
0
@@ -89,16 +105,8 @@ class Entry(db.Model):
0
         if not self.is_saved():
0
             self.blog.entrycount += 1
0
             self.blog.save()
0
-            my = datetime.now().strftime('%b-%Y')
0
-            archive = Archive.all().filter('monthyear',my).fetch(10)
0
-            if archive == []:
0
-                archive = Archive(blog=self.blog,monthyear=my)
0
-                self.monthyear = my
0
-                archive.put()
0
-            else:
0
-                # ratchet up the count
0
-                archive[0].entrycount += 1
0
-                archive[0].put()
0
+            
0
+            self.update_archive()
0
         #b = self.blog
0
         #print b.tags
0
         #for tag in self.tagsnew:

Comments