From: Eevee Date: Mon, 28 Dec 2009 06:50:02 +0000 (-0800) Subject: Added a bunch of NOT NULLs. X-Git-Url: http://git.veekun.com/zzz-floof.git/commitdiff_plain/42398bc94b95b5a115396f14c3c1dde6fb6808a5 Added a bunch of NOT NULLs. --- diff --git a/floof/model/comments.py b/floof/model/comments.py index ef3a948..08fa847 100644 --- a/floof/model/comments.py +++ b/floof/model/comments.py @@ -17,12 +17,12 @@ def indent_comments(comments): """ 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) @@ -30,7 +30,7 @@ def indent_comments(comments): # 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 @@ -52,8 +52,8 @@ class Discussion(Entity): 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. @@ -62,11 +62,11 @@ class Comment(Entity): # 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. diff --git a/floof/model/ratings.py b/floof/model/ratings.py index 6b5850a..ab850b1 100644 --- a/floof/model/ratings.py +++ b/floof/model/ratings.py @@ -3,9 +3,9 @@ from art import Art 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 @@ -23,4 +23,4 @@ class RatingMixin(object): return rating.score return Rating.default -Art.__bases__ += (RatingMixin,) \ No newline at end of file +Art.__bases__ += (RatingMixin,) diff --git a/floof/model/search.py b/floof/model/search.py index 7e04ae7..598999d 100644 --- a/floof/model/search.py +++ b/floof/model/search.py @@ -3,9 +3,9 @@ from elixir import * 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 @@ -13,8 +13,8 @@ class SavedSearch(Entity): 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) @@ -45,4 +45,4 @@ class GalleryWidget(Entity): # # 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) diff --git a/floof/model/tags.py b/floof/model/tags.py index b0a7072..c3ea907 100644 --- a/floof/model/tags.py +++ b/floof/model/tags.py @@ -3,9 +3,9 @@ from art import Art 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: @@ -13,7 +13,7 @@ class Tag(Entity): 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): diff --git a/floof/model/users.py b/floof/model/users.py index f2a6a75..6643702 100644 --- a/floof/model/users.py +++ b/floof/model/users.py @@ -11,8 +11,8 @@ from elixir import * 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') @@ -51,13 +51,13 @@ class User(Entity): 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 @@ -119,7 +119,7 @@ class UserRelationship(Entity): 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