sub.connect('delete_tag', '/art/{art_id}/tag/{id}')
sub.connect('create_tag', '/art/{art_id}/tag')
+ with map.submapper(controller='relation') as sub:
+ sub.connect('create_relation', '/art/{art_id}/relations/{kind}/create', action="create")
+ # TODO: conditions: kind = by|for|of|character?
+
map.resource('tag','tags', controller="tag",
parent_resource=dict(member_name='art', collection_name='art'))
# Yeah, parent resources are specified kinda dumb-ly. Would be better if you could pass in the
--- /dev/null
+import logging
+
+from pylons import request, response, session, tmpl_context as c, h, url
+from pylons.controllers.util import abort, redirect
+
+from floof.lib.base import BaseController, render
+
+log = logging.getLogger(__name__)
+
+from floof.model.art import Art, UserRelation
+from floof.model.users import User
+import elixir
+
+class RelationController(BaseController):
+ def create(self, art_id, kind):
+ art = h.get_object_or_404(Art, id=art_id)
+ user = h.get_object_or_404(User, name=request.params['username'])
+ ## TODO: actually, this should act like a form validation.
+
+ prior_relation = UserRelation.get_by(art=art, user=user)
+ if prior_relation:
+ abort(404) ## should be a validation error
+
+ relation = UserRelation(user=user, kind=kind, art=art, creator=c.user)
+ elixir.session.commit()
+ redirect(url('show_art', id=art_id))
+
+ def index(self):
+ # Return a rendered template
+ #return render('/relation.mako')
+ # or, return a response
+ return 'Hello World'
tags = OneToMany('Tag')
discussion = ManyToOne('Discussion')
+ user_relations = OneToMany('UserRelation')
+
+
def set_file(self, file):
self.hash = save_file("art", file)
self.original_filename = file.filename
class UserRelation(Entity):
- related = ManyToOne("User")
+ user = ManyToOne("User")
art = ManyToOne("Art")
- type = Field(String) # by for of
+ kind = Field(String) # by for of
+ creator = ManyToOne("User")
+ confirmed_by_related_user = Field(Boolean)
+
+ # it is useful to record which authority figure on a given artwork
+ # confirmed the validity of this relation.
+ confirmed_by_authority = ManyToOne("User")
+
+ def __init__(self, **kwargs):
+ super(UserRelation, self).__init__(**kwargs)
+ assert self.user and self.art and self.kind and self.creator
+
+
+ if self.creator == self.user:
+ self.confirmed_by_related_user = True
+ # TODO: implement authorities
+ # if self.creator in self.art.authorities
+ # self.confirmed_by_authority = self.creator
+
+ def __unicode__(self):
+ return "%s: %s" % (self.kind, self.related_user)
+
# class CharacterRelation(Entity):
${h.end_form()}
% endif
+<h2>Relations</h2>
+<ul>
+% for relation in c.art.user_relations:
+<li>${relation.kind}: ${relation.user}
+% endfor
+</ul>
+
+<h2>Add Relations</h2>
+${h.form (h.url("create_relation", kind="by", art_id=c.art.id))}
+By: ${h.text('username')}
+${h.submit('add','Add')}
+${h.end_form()}
+
+
<img class="full" src="${c.art.get_path()}">
${comments.comment_block(c.art.discussion.comments)}
--- /dev/null
+from floof.tests import *
+
+class TestRelationController(TestController):
+
+ def test_index(self):
+ response = self.app.get(url(controller='relation', action='index'))
+ # Test response...