1a4127865b51c4ed02e46ced7b142e83140e2fdc
3 from floof
.lib
.dbhelpers
import find_or_create
, update_or_create
7 # look into how ondelete works. This just sets a database property.
8 art
= ManyToOne('Art', ondelete
='cascade')
9 tagger
= ManyToOne('User', ondelete
='cascade')
10 tagtext
= ManyToOne('TagText')
12 def __unicode__(self
):
15 return unicode(self
.tagtext
)
18 class TagText(Entity
):
19 text
= Field(Unicode(50)) # gotta enforce this somehow
20 tags
= OneToMany('Tag')
22 def __unicode__(self
):
26 class TagMixin(object):
27 def add_tags(self
, tags
, user
):
28 for text
in tags
.split():
31 tagtext
= TagText
.get_by(text
=text
[1:])
33 tag
= Tag
.get_by(art
=self
, tagger
=user
, tagtext
=tagtext
)
35 elixir
.session
.delete(tag
)
39 raise "Long Tag!" # can we handle this more gracefully?
40 # sqlite seems happy to store strings much longer than the supplied limit...
42 # elixir should really have its own find_or_create.
43 tagtext
= find_or_create(TagText
, text
=text
)
44 tag
= find_or_create(Tag
, art
=self
, tagger
=user
, tagtext
=tagtext
)
46 Art
.__bases__
+= (TagMixin
, )