axiomstore.py :  » Web-Frameworks » Nevow » Nevow-0.10.0 » examples » blogengine » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Nevow 
Nevow » Nevow 0.10.0 » examples » blogengine » axiomstore.py
from iblogengine import IBlog
from zope.interface import implements
from axiom import item,store,attributes,sequence
from epsilon.extime import Time

class Post(item.Item):
    typeName = "BlogenginePost"
    schemaVersion = 1

    id = attributes.integer(indexed=True, allowNone=False)
    created = attributes.timestamp(indexed=True)
    modified = attributes.timestamp(indexed=True)
    title = attributes.text(indexed=True, allowNone=False)
    author = attributes.text(indexed=True, allowNone=False)
    category = attributes.text(indexed=True)
    content = attributes.text(indexed=True)

    def __init__(self, **kw):
        now = Time()
        kw.update({'created':now,
                   'modified':now})
        super(Post, self).__init__(**kw)

    def setModified(self):
        self.modified = Time()

class Blog(item.Item, item.InstallableMixin):
    implements(IBlog)

    typeName = "BlogengineBlog"
    schemaVersion = 1

    posts = attributes.reference()
    next_id = attributes.integer(default=0)
    
    def __init__(self, **kw):
        super(Blog, self).__init__(**kw)
        self.posts = sequence.List(store=self.store)
        post = Post(store=self.store,
                    id=self.getNextId(),
                    author=u'mike',
                    title=u'FIRST POST!!!!',
                    category=u'Test',
                    content=u'I guess it worked.')
        self.addNewPost(post)

    def installOn(self, other):
        super(Blog, self).installOn(other)
        other.powerUp(self, IBlog)

    def addNewPost(self, post):
        # Why even let posts manage their own ids?  Oh well.
        assert post.id == self.next_id,\
               "Bad post ID; is %r, should be %r" % (post.id, self.next_id)
        self.posts.append(post)
        self.next_id += 1

    def getPosts(self, how_many = None):
        """Return the latest 'how_many' posts, in reverse database order.

        XXX Really, it should be based on modtime.  Which is broken.
        """
        if how_many is None or how_many > self.next_id:
            how_many = self.next_id
        return (self.getOne(self.next_id-id-1) for id in range(how_many))

    def getOne(self, id):
        return self.posts[id]

    def getNextId(self):
        return self.next_id
    
def initialize(storename):
    s = store.Store(storename)
    s.findOrCreate(Blog).installOn(s)
    return s
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.