Created
July 12, 2012 08:21
-
-
Save c4pt0r/3096658 to your computer and use it in GitHub Desktop.
mongo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import jsonrpclib | |
from mongoengine import * | |
connect('dict') | |
class Page(Document): | |
created_at = db.DateTimeField(default=datetime.datetime.now, required=True) | |
word = db.StringField(max_length=255, required=True, unique = True) | |
content = db.StringField(required = True) | |
key = db.ListField(required = True) | |
founder = db.StringField(required = True) | |
editors = db.ListField(required = True) | |
version = db.IntField() | |
def __unicode__(self): | |
return self.word | |
meta = { | |
'indexes': ['key', 'word', 'founder', 'editors'], | |
} | |
class PageHistory(Document): | |
page = ReferenceField("Page") | |
history = db.ListField(required = True) | |
def get_page(fileds = [], **argv): | |
if len(fileds) > 0: | |
return [item for item in Page.objects(**argv).only(*fields)] | |
else: | |
return [item for item in Page.objects(**argv)] | |
def get_editor_count(usr): | |
found = Page.objects(founder = usr).count() | |
edit = Page.objects(editors = usr).count() | |
return found + edit | |
def put_page(key, item): | |
def check_item(): | |
#TODO | |
return True | |
if check_item() == False: | |
return (False, {'ret': -1, 'msg': 'data format not valid'}) | |
obj = Page(**item) | |
obj.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment