From ea3d7fcf702e372eac978d61b9af9dbad46543bb Mon Sep 17 00:00:00 2001 From: Nick Retallack Date: Sun, 6 Dec 2009 19:55:15 -0800 Subject: [PATCH] makes default user pages full of by/for/of. duct-taped, doesn't really clone something --- floof/controllers/account.py | 3 +++ floof/lib/tags.py | 3 +++ floof/model/search.py | 12 ++++++++++++ floof/model/users.py | 40 +++++++++++++++++++++++++++++++++++----- floof/websetup.py | 12 ++++++++---- 5 files changed, 61 insertions(+), 9 deletions(-) diff --git a/floof/controllers/account.py b/floof/controllers/account.py index 2073d44..b48dc25 100644 --- a/floof/controllers/account.py +++ b/floof/controllers/account.py @@ -16,6 +16,8 @@ from floof.model.users import IdentityURL, User log = logging.getLogger(__name__) +from floof.model import UserPage + class AccountController(BaseController): openid_store = FileOpenIDStore('/var/tmp') @@ -122,6 +124,7 @@ class AccountController(BaseController): # Create db records user = User(name=username, display_name=username) user.identity_urls.append(IdentityURL(url=identity_url)) + elixir.session.commit() # Log in diff --git a/floof/lib/tags.py b/floof/lib/tags.py index d2adafc..e75629e 100644 --- a/floof/lib/tags.py +++ b/floof/lib/tags.py @@ -90,6 +90,9 @@ def add_tags(art, tag_string, user): if prefix == 'by': # XXX this needs supporting. silently ignore for now continue + + if tag_text == 'me': + tag_text = c.user.name # Must be 3-50 alphanumeric characters if not re.match('^[a-z0-9]{3,50}$', tag_text): diff --git a/floof/model/search.py b/floof/model/search.py index f03de51..7e04ae7 100644 --- a/floof/model/search.py +++ b/floof/model/search.py @@ -15,6 +15,18 @@ class SavedSearch(Entity): class GalleryWidget(Entity): page = ManyToOne('UserPage') search = ManyToOne(SavedSearch) + + def __init__(self, string=None, **kwargs): + owner = kwargs.get('owner', None) + if string: + self.search = SavedSearch(author=owner, string=string) + + page = kwargs.get('page', None) + if owner and not page: + page = author.primary_page + + super(GalleryWidget, self).__init__(**kwargs) + # NOTE: no longer needed now that we have pages, I guess. # displayer = ManyToOne('User') # determines whose page should it should show up on diff --git a/floof/model/users.py b/floof/model/users.py index a6f3a6d..f2a6a75 100644 --- a/floof/model/users.py +++ b/floof/model/users.py @@ -48,10 +48,11 @@ class User(Entity): # 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) + prepositions = ['by','for','of'] + for preposition in prepositions: + GalleryWidget(page=self.primary_page, string=preposition+":me", owner=self) + + #UserPage.clone_primary_template(self) class IdentityURL(Entity): @@ -59,8 +60,37 @@ class IdentityURL(Entity): belongs_to('user', of_kind='User') - +from copy import copy class UserPage(Entity): + default_name = "default" + + ### This was a bit more complex than I thought it would be... + ### Sure it probably works ok, but I'd rather duct-tape it for now (above) + # @classmethod + # def get_primary_template(cls): + # return cls.get_by(owner=None, title=cls.default_name) + # + # @classmethod + # def make_primary_template(cls): + # if not cls.get_primary_template(): + # page = cls(owner=None, title=cls.default_name, visible=True) + # prepositions = ['by','for','of'] + # for preposition in prepositions: + # GalleryWidget(page=page, string=preposition+":me") + # + # @classmethod + # def clone_primary_template(cls, user): + # template = cls.get_primary_template() + # new = cls(owner=user, title=template.title) + # for gallery in template.galleries: + # new.galleries.append(GalleryWidget(user=user, string=gallery.string)) + # + # + # session.add(template) + # template.user = user + # template.id = None + # return template + """A user can have multiple pages, though by default they only have one visible. 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 diff --git a/floof/websetup.py b/floof/websetup.py index a4e935f..be104da 100644 --- a/floof/websetup.py +++ b/floof/websetup.py @@ -22,13 +22,17 @@ def setup_app(command, conf, vars): ### Sample data # Users from floof.model.users import IdentityURL, User - identity_url = IdentityURL(url=u'http://eevee.livejournal.com/') - user = User(name=u'eevee') - user.identity_urls.append(identity_url) + if not User.query.filter_by(name=u'eevee').count: + identity_url = IdentityURL(url=u'http://eevee.livejournal.com/') + user = User(name=u'eevee') + user.identity_urls.append(identity_url) + + ### Make the canonical user-page + from floof.model import UserPage + UserPage.make_primary_template() model.Session.commit() - ### Filesystem stuff # Only necessary if we're using the filesystem for storage. # And we are! -- 2.7.4