"""
last_comment = None
- indent = 0
+ indent = 0
right_ancestry = []
for comment in comments:
# If this comment is a child of the last, bump the nesting level
if last_comment and comment.left < last_comment.right:
- indent = indent + 1
+ indent = indent + 1
# Remember current ancestory relevant to the root
right_ancestry.append(last_comment)
# broken out of, back out a level
for i in xrange(len(right_ancestry) - 1, -1, -1):
if comment.left > right_ancestry[i].right:
- indent = indent - 1
+ indent = indent - 1
right_ancestry.pop(i)
# Cache parent comment
comments = OneToMany('Comment', order_by='left')
class Comment(Entity):
- time = Field(DateTime, default=datetime.datetime.now)
- text = Field(Unicode(65536))
+ time = Field(DateTime, default=datetime.datetime.now, required=True)
+ text = Field(Unicode(65536), required=True)
# Comments are a tree, and are stored as a nested set, because:
# - It's easy to get a subtree with a single query.
# The only real disadvantage is that adding a comment requires a quick
# update of all the following comments (in post-order), but that's rare
# enough that it shouldn't be a problem.
- left = Field(Integer, index=True)
- right = Field(Integer)
+ left = Field(Integer, index=True, required=True)
+ right = Field(Integer, required=True)
- discussion = ManyToOne('Discussion')
- user = ManyToOne('User')
+ discussion = ManyToOne('Discussion', required=True)
+ user = ManyToOne('User', required=True)
def __init__(self, parent=None, **kwargs):
"""Constructor override to set left/right correctly on a new comment.
from floof.lib.dbhelpers import find_or_create, update_or_create
class Rating(Entity):
- art = ManyToOne('Art', ondelete='cascade')
- rater = ManyToOne('User', ondelete='cascade')
- score = Field(Integer)
+ art = ManyToOne('Art', ondelete='cascade', required=True)
+ rater = ManyToOne('User', ondelete='cascade', required=True)
+ score = Field(Integer, required=True)
options = {-1:"sucks", 0:"undecided", 1:"good", 2:"great"}
default = 0
return rating.score
return Rating.default
-Art.__bases__ += (RatingMixin,)
\ No newline at end of file
+Art.__bases__ += (RatingMixin,)
class SavedSearch(Entity):
- string = Field(Unicode) # I tried calling this query, but it broke elixir
- author = ManyToOne('User')
- fork = ManyToOne("SavedSearch")
+ string = Field(Unicode, required=True)
+ author = ManyToOne('User', required=True)
+ fork = ManyToOne("SavedSearch", required=True)
def __unicode__(self):
return self.string
class GalleryWidget(Entity):
- page = ManyToOne('UserPage')
- search = ManyToOne(SavedSearch)
+ page = ManyToOne('UserPage', required=True)
+ search = ManyToOne(SavedSearch, required=True)
def __init__(self, string=None, **kwargs):
owner = kwargs.get('owner', None)
# # TODO: may have to refactor this into an init if the key ordering is inconvenienc
# raise "Oh no! This gallery needs a displayer to set on the saved search."
- self.search = SavedSearch(author=getattr(self,"author",None), string=value)
+ self.search = SavedSearch(author=getattr(self, "author", None), string=value)
class Tag(Entity):
# look into how ondelete works. This just sets a database property.
- art = ManyToOne('Art', ondelete='cascade')
- tagger = ManyToOne('User', ondelete='cascade')
- tagtext = ManyToOne('TagText')
+ art = ManyToOne('Art', ondelete='cascade', required=True)
+ tagger = ManyToOne('User', ondelete='cascade', required=True)
+ tagtext = ManyToOne('TagText', required=True)
def __unicode__(self):
if not self.tagtext:
return unicode(self.tagtext)
class TagText(Entity):
- text = Field(Unicode(50)) # gotta enforce this somehow
+ text = Field(Unicode(50), required=True) # gotta enforce this somehow
tags = OneToMany('Tag')
def __unicode__(self):
from search import GalleryWidget
class User(Entity):
- name = Field(Unicode(20), unique=True)
- display_name = Field(Unicode(20))
+ name = Field(Unicode(20), unique=True, required=True)
+ display_name = Field(Unicode(20), required=True)
uploads = OneToMany('Art')
has_many('identity_urls', of_kind='IdentityURL')
searches = OneToMany('SavedSearch')
prepositions = ['by','for','of']
for preposition in prepositions:
GalleryWidget(page=self.primary_page, string=preposition+":me", owner=self)
-
+
#UserPage.clone_primary_template(self)
class IdentityURL(Entity):
- url = Field(Unicode(255))
- belongs_to('user', of_kind='User')
+ url = Field(Unicode(255), required=True)
+ user = ManyToOne('User', required=True)
from copy import copy
to users.
"""
- user = ManyToOne('User')
- target_user = ManyToOne('User')
+ user = ManyToOne('User', required=True)
+ target_user = ManyToOne('User', required=True)
type = Field(Integer) # UserRelationshipTypes above