Skip to content

Commit

Permalink
fleshed out a migration tool for new features, implemented for archiv…
Browse files Browse the repository at this point in the history
…e feature
  • Loading branch information
Aaron Raddon authored and Aaron Raddon committed May 13, 2008
1 parent c5d3e3a commit cbd2b3a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
30 changes: 24 additions & 6 deletions blog.py
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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})


Expand Down Expand Up @@ -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'):
Expand Down Expand Up @@ -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),
Expand Down
28 changes: 18 additions & 10 deletions model.py
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down

0 comments on commit cbd2b3a

Please sign in to comment.