bacdfe621cd368502c293ea747ef35684245b5d0
2 # floof/floof/model/users.py
4 # Copyright (c) 2009 Scribblr
11 from search
import GalleryWidget
14 name
= Field(Unicode(20))
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)
52 # a starter gallery, just for fun
53 gallery
= GalleryWidget(owner
=self
, string
="awesome")
54 self
.primary_page
.galleries
.append(gallery
)
57 class IdentityURL(Entity
):
58 url
= Field(Unicode(255))
59 belongs_to('user', of_kind
='User')
63 class UserPage(Entity
):
64 """A user can have multiple pages, though by default they only have one visible.
65 This is so that they can keep some nice themed pages lying around for special occasions.
66 Page templates that provide familiar interfaces will also be UserPage records. Users will
67 see a panel full of them, and they can choose to clone those template pages to their own page list.
68 If more than one is set to visible, there would be tabs. The primary page is indicated in the user model.
71 owner
= ManyToOne('User', inverse
="pages")
74 visible
= Field(Boolean
)
75 galleries
= OneToMany('GalleryWidget')
78 class UserRelationshipTypes(object):
81 class UserRelationship(Entity
):
82 """Represents some sort of connection between users.
84 For the moment, this means "watching". Later, it may mean friending or
87 XXX: Watching should be made more general than this; it should have the
88 power of an arbitrary query per watched artist without being unintelligible
92 user
= ManyToOne('User')
93 target_user
= ManyToOne('User')
94 type = Field(Integer
) # UserRelationshipTypes above