Depend on wtforms.
[zzz-floof.git] / floof / model / users.py
1 #
2 # floof/floof/model/users.py
3 #
4 # Copyright (c) 2009 Scribblr
5 #
6
7 # from elixir import Entity, Field, Unicode, belongs_to, has_many
8 from elixir import *
9 from search import GalleryWidget
10
11 class User(Entity):
12 name = Field(Unicode(20))
13 uploads = OneToMany('Art')
14 has_many('identity_urls', of_kind='IdentityURL')
15 searches = OneToMany('SavedSearch')
16 # galleries = OneToMany('GalleryWidget')
17 pages = OneToMany('UserPage', inverse="owner")
18 primary_page = OneToOne('UserPage', inverse="owner")
19 relationships = OneToMany('UserRelationship', inverse='user')
20 target_of_relationships = OneToMany('UserRelationship', inverse='target_user')
21
22
23 def __unicode__(self):
24 return self.name
25
26 def __str__(self):
27 return self.name
28
29 def __init__(self, **kwargs):
30 super(User, self).__init__(**kwargs)
31
32
33
34 # TODO: have this clone a standard starter page
35 self.primary_page = UserPage(owner=self, title="default", visible=True)
36
37 # a starter gallery, just for fun
38 gallery = GalleryWidget(owner=self, string="awesome")
39 self.primary_page.galleries.append(gallery)
40
41
42 class IdentityURL(Entity):
43 url = Field(Unicode(255))
44 belongs_to('user', of_kind='User')
45
46
47
48 class UserPage(Entity):
49 """A user can have multiple pages, though by default they only have one visible.
50 This is so that they can keep some nice themed pages lying around for special occasions.
51 Page templates that provide familiar interfaces will also be UserPage records. Users will
52 see a panel full of them, and they can choose to clone those template pages to their own page list.
53 If more than one is set to visible, there would be tabs. The primary page is indicated in the user model.
54 """
55
56 owner = ManyToOne('User', inverse="pages")
57 title = Field(String)
58
59 visible = Field(Boolean)
60 galleries = OneToMany('GalleryWidget')
61
62
63 class UserRelationshipTypes(object):
64 IS_WATCHING = 1
65
66 class UserRelationship(Entity):
67 """Represents some sort of connection between users.
68
69 For the moment, this means "watching". Later, it may mean friending or
70 ignoring.
71
72 XXX: Watching should be made more general than this; it should have the
73 power of an arbitrary query per watched artist without being unintelligible
74 to users.
75 """
76
77 user = ManyToOne('User')
78 target_user = ManyToOne('User')
79 type = Field(Integer) # UserRelationshipTypes above
80