from floof.lib.file_storage import get_path, save_file
from floof.lib.dbhelpers import find_or_create, update_or_create
+ import floof.model.comments
class Art(Entity):
title = Field(Unicode(120))
uploader = ManyToOne('User', required=True)
tags = OneToMany('Tag')
-
- # def __init__(self, **kwargs):
- # # I wanted to check for the existence of the file, but...
- # # for some reason this FieldStorage object always conditions as falsey.
- # # self.hash = save_file("art", kwargs.pop('file'))
- # super(Art, self).__init__(**kwargs)
- # # this is what super is doing, pretty much.
- # # for key, value in kwargs.items():
- # # setattr(self, key, value)
- # left for posterity.
+ discussion = ManyToOne('Discussion')
def set_file(self, file):
self.hash = save_file("art", file)
if tag:
elixir.session.delete(tag)
- else:
+ else:
if len(text) > 50:
raise "Long Tag!" # can we handle this more gracefully?
# sqlite seems happy to store strings much longer than the supplied limit...
def rate(self, score, user):
return update_or_create(Rating, {"rater":user, "art":self}, {"score":score})
-
+
def user_score(self, user):
rating = Rating.get_by(rater=user, art=self)
if rating:
tagger = ManyToOne('User', ondelete='cascade')
tagtext = ManyToOne('TagText')
- # this text setter is no longer useful since I changed the way Art#add_tags works
- # but I'll leave it in here just for several minutes nostalgia.
- # def set_text(self, text):
- # self.tagtext = TagText.get_by(text=text)
- # if not self.tagtext:
- # self.tagtext = TagText(text=text)
- #
- # text = property(lambda self: self.tagtext.text, set_text)
-
def __unicode__(self):
if not self.tagtext:
return "(broken)"
def __unicode__(self):
return self.text
-
+
class Rating(Entity):
art = ManyToOne('Art', ondelete='cascade')
rater = ManyToOne('User', ondelete='cascade')
score = Field(Integer)
-
- # @score.setter
- # def score(self, value):
-
+
options = {-1:"sucks", 0:"undecided", 1:"good", 2:"great"}
default = 0
- # options = ["sucks","neutral","good","great"]
-
-
Rating.reverse_options = dict (zip(Rating.options.values(), Rating.options.keys()))
-
+
+
+
- # pass
+class UserRelation(Entity):
+ related = ManyToOne("User")
+ art = ManyToOne("Art")
+ type = Field(String) # by for of
+
+
+# class CharacterRelation(Entity):
++# pass
class SavedSearch(Entity):
string = Field(Unicode) # I tried calling this query, but it broke elixir
author = ManyToOne('User')
-
+ fork = ManyToOne("SavedSearch")
+
def __unicode__(self):
return self.string
-
+
@property
def results(self):
return do_search(self.string)
# NOTE: no longer needed now that we have pages, I guess.
# displayer = ManyToOne('User') # determines whose page should it should show up on
# # Could be no-ones, if it's just a template.
-
+
# Needs some fields for position on your page
@property
def string(self):
return self.search
-
+
@string.setter
def string(self, value):
# TODO: should we delete the possibly orphaned saved search?
# if not self.displayer:
# # 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)
-
pages = OneToMany('UserPage', inverse="owner")
primary_page = OneToOne('UserPage', inverse="owner")
-
+
def __unicode__(self):
return self.name
def __init__(self, **kwargs):
super(User, self).__init__(**kwargs)
-
-
-
+
+
+
# TODO: have this clone a standard starter page
self.primary_page = UserPage(owner=self, title="default", visible=True)
-
+
# a starter gallery, just for fun
gallery = GalleryWidget(owner=self, string="awesome")
self.primary_page.galleries.append(gallery)
This is so that they can keep some nice themed pages lying around for special occasions.
Page templates that provide familiar interfaces will also be UserPage records. Users will
see a panel full of them, and they can choose to clone those template pages to their own page list.
- If more than one is set to visible, there would be tabs.
-
- """
-
+ If more than one is set to visible, there would be tabs. The primary page is indicated in the user model.
-
+ """
+
owner = ManyToOne('User', inverse="pages")
title = Field(String)
-
+
visible = Field(Boolean)
- galleries = OneToMany('GalleryWidget')
+ galleries = OneToMany('GalleryWidget')
+
+
+
+
+# class ArtRelation(Entity):
+#