2 # floof/floof/model/users.py
4 # Copyright (c) 2009 Scribblr
11 from search
import GalleryWidget
14 name
= Field(Unicode(20), unique
=True)
15 display_name
= Field(Unicode(20))
16 uploads
= OneToMany('Art')
17 has_many('identity_urls', of_kind
='IdentityURL')
18 searches
= OneToMany('SavedSearch')
19 # galleries = OneToMany('GalleryWidget')
20 pages
= OneToMany('UserPage', inverse
="owner")
21 primary_page
= OneToOne('UserPage', inverse
="owner")
22 relationships
= OneToMany('UserRelationship', inverse
='user')
23 target_of_relationships
= OneToMany('UserRelationship', inverse
='target_user')
26 def is_valid_name(cls
, name
):
27 """Returns True iff the name is a valid username.
29 Only lowercase letters, numbers, and hyphens are allowed.
31 Names must also be at least one character long, but no more than 20,
32 and cannot start or end with a hyphen.
34 return re
.match('^[-a-z0-9]{1,20}$', name
) \
35 and name
[0] != '-' and name
[-1] != '-'
38 def __unicode__(self
):
44 def __init__(self
, **kwargs
):
45 super(User
, self
).__init__(**kwargs
)
49 # TODO: have this clone a standard starter page
50 self
.primary_page
= UserPage(owner
=self
, title
="default", visible
=True)
51 prepositions
= ['by','for','of']
52 for preposition
in prepositions
:
53 GalleryWidget(page
=self
.primary_page
, string
=preposition
+":me", owner
=self
)
55 #UserPage.clone_primary_template(self)
58 class IdentityURL(Entity
):
59 url
= Field(Unicode(255))
60 belongs_to('user', of_kind
='User')
64 class UserPage(Entity
):
65 default_name
= "default"
67 ### This was a bit more complex than I thought it would be...
68 ### Sure it probably works ok, but I'd rather duct-tape it for now (above)
70 # def get_primary_template(cls):
71 # return cls.get_by(owner=None, title=cls.default_name)
74 # def make_primary_template(cls):
75 # if not cls.get_primary_template():
76 # page = cls(owner=None, title=cls.default_name, visible=True)
77 # prepositions = ['by','for','of']
78 # for preposition in prepositions:
79 # GalleryWidget(page=page, string=preposition+":me")
82 # def clone_primary_template(cls, user):
83 # template = cls.get_primary_template()
84 # new = cls(owner=user, title=template.title)
85 # for gallery in template.galleries:
86 # new.galleries.append(GalleryWidget(user=user, string=gallery.string))
89 # session.add(template)
90 # template.user = user
94 """A user can have multiple pages, though by default they only have one visible.
95 This is so that they can keep some nice themed pages lying around for special occasions.
96 Page templates that provide familiar interfaces will also be UserPage records. Users will
97 see a panel full of them, and they can choose to clone those template pages to their own page list.
98 If more than one is set to visible, there would be tabs. The primary page is indicated in the user model.
101 owner
= ManyToOne('User', inverse
="pages")
102 title
= Field(String
)
104 visible
= Field(Boolean
)
105 galleries
= OneToMany('GalleryWidget')
108 class UserRelationshipTypes(object):
111 class UserRelationship(Entity
):
112 """Represents some sort of connection between users.
114 For the moment, this means "watching". Later, it may mean friending or
117 XXX: Watching should be made more general than this; it should have the
118 power of an arbitrary query per watched artist without being unintelligible
122 user
= ManyToOne('User')
123 target_user
= ManyToOne('User')
124 type = Field(Integer
) # UserRelationshipTypes above