From: Eevee Date: Wed, 9 Dec 2009 03:28:55 +0000 (-0800) Subject: Removed some reliance on the logged-in user. X-Git-Url: http://git.veekun.com/zzz-floof.git/commitdiff_plain/03c8b0becd6264301a64e9201588c60c9b588ad1?ds=sidebyside Removed some reliance on the logged-in user. Userpages assumed someone was logged in. by/for/of:me used the logged-in user rather than the owner and depended on pylons. --- diff --git a/floof/controllers/account.py b/floof/controllers/account.py index 6459791..0b58078 100644 --- a/floof/controllers/account.py +++ b/floof/controllers/account.py @@ -122,6 +122,10 @@ class AccountController(BaseController): h.flash(u'This username is not valid.') return self.register() + if username in ['me']: + h.flash(u'This username is reserved.') + return self.register() + # Create db records user = User(name=username, display_name=username) user.identity_urls.append(IdentityURL(url=identity_url)) diff --git a/floof/controllers/search.py b/floof/controllers/search.py index 8617966..63e20ec 100644 --- a/floof/controllers/search.py +++ b/floof/controllers/search.py @@ -21,7 +21,7 @@ class SearchController(BaseController): return self.save() c.query = request.params.get('query', '') - c.artwork = parse(c.query).all() + c.artwork = parse(c.query, me=c.user).all() return render('/index.mako') # TODO: login required diff --git a/floof/controllers/tag.py b/floof/controllers/tag.py index 5d13789..1ceaf7c 100644 --- a/floof/controllers/tag.py +++ b/floof/controllers/tag.py @@ -27,7 +27,12 @@ class TagController(BaseController): c.art = h.get_object_or_404(Art, id=art_id) tag_string = request.params.get('tags', '') - add_tags(c.art, tag_string, c.user) + add_tags( + art=c.art, + tag_string=tag_string, + adding_user=c.user, + me=c.user, + ) # Add or remove tags redirect(url('show_art', id=c.art.id)) diff --git a/floof/controllers/users.py b/floof/controllers/users.py index 7c24c0f..4c9bb9c 100644 --- a/floof/controllers/users.py +++ b/floof/controllers/users.py @@ -27,11 +27,12 @@ class UsersController(BaseController): except NoResultFound: abort(404) - rels = UserRelationship.query.filter_by( - user_id=c.user.id, - target_user_id=c.this_user.id, - ).all() + if c.user: + rels = UserRelationship.query.filter_by( + user_id=c.user.id, + target_user_id=c.this_user.id, + ).all() - c.relationships = [_.type for _ in rels] + c.relationships = [_.type for _ in rels] return render('/users/view.mako') diff --git a/floof/lib/base.py b/floof/lib/base.py index b42d2be..c93803b 100644 --- a/floof/lib/base.py +++ b/floof/lib/base.py @@ -21,6 +21,7 @@ class BaseController(WSGIController): try: c.user = User.query.get(session['user_id']) except: + c.user = None pass def __call__(self, environ, start_response): diff --git a/floof/lib/tags.py b/floof/lib/tags.py index 134ba6f..2a9beaf 100644 --- a/floof/lib/tags.py +++ b/floof/lib/tags.py @@ -3,14 +3,14 @@ import elixir from dbhelpers import find_or_create import re -from pylons import c - -def parse(search_string): +def parse(search_string, me): """Parses a search query, and returns a query object on Art. Queries can contain: - Regular tags: foo - User relations: by:kalu, of:eevee, for:ootachi + - User relations relative to some user: by:me + Note that this necessitates a `me` parameter. Later: - Negative versions of anything above: -by:eevee, -dongs @@ -28,11 +28,12 @@ def parse(search_string): # This is a special tag; at the moment, by/for/of to indicate # related users prefix, tag = tag.split(':', 1) - if tag == 'me': - tag = c.user.name - # XXX what to do if this fails? abort? return empty query? - target_user = User.get_by(name=tag) + if tag == 'me': + target_user = me + else: + # XXX what to do if this fails? abort? return empty query? + target_user = User.get_by(name=tag) if prefix == 'by': rel = ArtUserType.BY @@ -57,7 +58,7 @@ def parse(search_string): return q -def add_tags(art, tag_string, user): +def add_tags(art, tag_string, adding_user, me): """Takes a string that looks like a tag query, and effectively modifies the art's tags to match it. """ diff --git a/floof/templates/users/view.mako b/floof/templates/users/view.mako index 3bff21a..40d2e07 100644 --- a/floof/templates/users/view.mako +++ b/floof/templates/users/view.mako @@ -7,7 +7,7 @@ % if c.this_user == c.user: ## Nothing <% pass %>\ -% else: +% elif c.user: ${h.form(url(controller='user_settings', action='rel_toggle', name=c.user.name.lower()), method='POST')}

@@ -19,10 +19,12 @@ ${h.form(url(controller='user_settings', action='rel_toggle', name=c.user.name.l % endif +

+${h.end_form()} % endif <%! from floof.lib.tags import parse %> % for gallery in c.this_user.primary_page.galleries:

${gallery.string}

-${macros.thumbs(parse(gallery.search.string))} +${macros.thumbs(parse(gallery.search.string, me=c.this_user))} % endfor