From: Nick Retallack Date: Tue, 1 Dec 2009 09:18:21 +0000 (-0800) Subject: merged. Oh no, we have two different user relationship models. Mine's in relations... X-Git-Url: http://git.veekun.com/zzz-floof.git/commitdiff_plain/f263f51648eef9739caa92e19ec45b32d7a1e49e merged. Oh no, we have two different user relationship models. Mine's in relations.py, and is used for stuff like by/for/of, most of which isn't implemented yet --- f263f51648eef9739caa92e19ec45b32d7a1e49e diff --cc floof/controllers/art.py index be75ee7,b8406ed..41298c8 --- a/floof/controllers/art.py +++ b/floof/controllers/art.py @@@ -8,58 -8,14 +8,61 @@@ from floof.lib.base import BaseControll log = logging.getLogger(__name__) import elixir -from floof.model.art import Art, Rating +from floof.model.users import User +from floof.model import Art, Rating, UserRelation from floof.model.comments import Discussion + from floof.model.users import User, UserRelationship + from sqlalchemy import func from sqlalchemy.exceptions import IntegrityError + from sqlalchemy.orm.exc import NoResultFound +from wtforms.validators import ValidationError +from wtforms import * + + +class ArtUploadForm(Form): + by = TextField('Artists') + file = FileField('Upload') + url = TextField('Link') + + # TODO: make this general purpose + def validate_file(self, field): + if field.data == u'': + raise ValidationError('File is required') + + # Also make this into a general User List field validator + """ PLEASE NOTE! I just realized that I need to have a __str__ method on User + to get it to write the usernames back in the form when it redisplays them, since + this validator turns them into user objects instead. This fact actually sounds dangerous + to me in the future, since it means I proably shouldn't be changing the data input + by the user right here in the validator, or the user will see the post-mangled data instead + of what they actually typed. Hm. + + One solution to this could be to only look up the users after normal validation is over, + and then manually add validation errors to the form if that fails. But I think that kind of + sucks. Perhaps the ideology in Formish, where they keep Validation and Conversion as + separate tasks, is a better way of doing it? That way there is less risk of changing the user's + input -- you do that at the conversiot stage -- yet it is still encapsulated in the form workflow. + Hm. But that means I'd have to query for the users in the validation step and throw them away, + or something equally stupid. Guess there's no perfect solution here, but I thought it was + worth discussing. + + Btw, this is meant to be used by a field with multi user autocompletion on it (like on stackoverflow tags), + so the user should never actually submit anything invalid unless they disable javascript and force it. + """ + def validate_by(self, field): + if not field.data: + raise ValidationError("Needs at least one creator") + user_names = field.data.split() + users = [] + # TODO: Could totally do a filter__in here instead of picking them out individually + for user_name in user_names: + user = User.get_by(name=user_name) + if not user: + raise ValidationError("Couldn't find user %s" % user_name) + users.append(user) + field.data = users class ArtController(BaseController): def __before__(self, id=None): diff --cc floof/model/users.py index 4f83a75,af4bfba..7601cf5 --- a/floof/model/users.py +++ b/floof/model/users.py @@@ -56,9 -56,22 +58,23 @@@ class UserPage(Entity) visible = Field(Boolean) galleries = OneToMany('GalleryWidget') - - - - - # class ArtRelation(Entity): - # + + + class UserRelationshipTypes(object): + IS_WATCHING = 1 + + class UserRelationship(Entity): + """Represents some sort of connection between users. + + For the moment, this means "watching". Later, it may mean friending or + ignoring. + + XXX: Watching should be made more general than this; it should have the + power of an arbitrary query per watched artist without being unintelligible + to users. + """ + + user = ManyToOne('User') + target_user = ManyToOne('User') + type = Field(Integer) # UserRelationshipTypes above ++