From cbd2b3abb58e9b0798bd6838f26a1a90554ce4d9 Mon Sep 17 00:00:00 2001 From: Aaron Raddon Date: Tue, 13 May 2008 10:27:51 -0700 Subject: [PATCH] fleshed out a migration tool for new features, implemented for archive feature --- blog.py | 30 ++++++++++++++++++++++++------ model.py | 28 ++++++++++++++++++---------- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/blog.py b/blog.py index 33570ef..7d5c2ad 100644 --- a/blog.py +++ b/blog.py @@ -2,7 +2,8 @@ from functools import wraps import wsgiref.handlers -from google.appengine.ext.webapp import template +from google.appengine.ext.webapp import template, \ + WSGIApplication from google.appengine.api import users import webapp as webapp2 from google.appengine.ext import webapp @@ -44,6 +45,7 @@ class BaseController(webapp2.RequestHandler): def __init__(self): self.template = 'index.html' self.blog = Blog.all().fetch(1) + #self.app_version = WSGIApplication.active_instance if self.blog == []: pass else: @@ -115,7 +117,7 @@ def get(self,slug=None): class ArchivePage(BasePublicPage): def get(self,monthyear=None): entries = Entry.all().filter('monthyear', monthyear).\ - filter("published =", True).order('-date') + filter("published =", True).filter('entrytype','post').order('-date') self.render('views/index.html',{'entries':entries}) @@ -215,12 +217,28 @@ class AdminList(BaseController): @requires_admin def get(self,entrytype='post',template_vals={}): entries = Entry.all().filter('entrytype =',entrytype).order('-date') - archive = Archive.all() - #for a in archive: - # a.delete() self.render('views/admin.html',{'entries':entries}) +class AdminMigrate(BaseController): + @requires_admin + def get(self,to_version='1.15'): + if to_version == '1.16': + archives = Archive.all() + for a in archives: + a.delete() + entries = Entry.all().filter('entrytype =','post') + for e in entries: + e.update_archive() + e.monthyear = e.date.strftime('%b-%Y') + e.put() + print 'update to %s' % (e.monthyear) + archive = Archive.all() + self.blog.blogversion = to_version + self.blog.put() + + + class AdminLinks(BaseController): @requires_admin def get(self,linktype='blogroll'): @@ -251,7 +269,7 @@ def main(): ('/admin/entry/(.*)', AdminEntry), ('/admin/links/(.*)', AdminLinks), ('/admin/setup', AdminConfig), - ('/admin/migrate', AdminMigrate), + ('/admin/migrate/(.*)', AdminMigrate), ('/tag/(.*)', TagPage), ('/atom', FeedHandler), (r'/page/(.*)', PublicPage), diff --git a/model.py b/model.py index b39cf26..51c397e 100644 --- a/model.py +++ b/model.py @@ -14,6 +14,7 @@ class Blog(db.Model): title = db.StringProperty(multiline=False) subtitle = db.StringProperty(multiline=False) entrycount = db.IntegerProperty(default=0) + blogversion = db.StringProperty(multiline=False,default='1.15') layout = db.StringProperty(multiline=False,default='2cola',choices=[ '3cola', '3colb', '2cola','2colb']) theme = db.StringProperty(multiline=False,default='freshpress.css') @@ -79,6 +80,21 @@ def set_tags(self, tags): tagswcommas = property(get_tags,set_tags) + def update_archive(self): + """Checks to see if there is a month-year entry for the + month of current blog, if not creates it and increments count""" + my = datetime.now().strftime('%b-%Y') # May-2008 + 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() + + def save(self): """ Use this instead of self.put(), as we do some other work here @@ -89,16 +105,8 @@ def save(self): 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() + + self.update_archive() #b = self.blog #print b.tags #for tag in self.tagsnew: