X-Git-Url: http://git.veekun.com/zzz-floof.git/blobdiff_plain/dcf6146e9914ff3c166f242b72f04a8934d65148..03c8b0becd6264301a64e9201588c60c9b588ad1:/floof/controllers/art.py diff --git a/floof/controllers/art.py b/floof/controllers/art.py index 5b347b3..0b89d98 100644 --- a/floof/controllers/art.py +++ b/floof/controllers/art.py @@ -1,15 +1,15 @@ import logging -from pylons import config, request, response, session, tmpl_context as c, h +from pylons import config, request, response, session, tmpl_context as c from pylons.controllers.util import abort, redirect from pylons import url from floof.lib.base import BaseController, render log = logging.getLogger(__name__) -from floof.lib import file_storage as storage -from floof.model.users import User -from floof.model import Art, Rating, UserRelation +from floof.lib import file_storage as storage, helpers as h +from floof.model import Art, Rating, ArtUser +from floof.model.art import ArtUserType from floof.model.comments import Discussion from floof.model.users import User, UserRelationship @@ -18,7 +18,6 @@ import elixir import os.path import PIL import PIL.Image -from sqlalchemy import func from sqlalchemy.exceptions import IntegrityError from sqlalchemy.orm.exc import NoResultFound from wtforms.validators import ValidationError @@ -27,6 +26,7 @@ from wtforms import * class ArtUploadForm(Form): by = TextField('Artists') + by_me = BooleanField('me') file = FileField('Upload') url = TextField('Link') @@ -35,38 +35,6 @@ class ArtUploadForm(Form): 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): @@ -127,8 +95,17 @@ class ArtController(BaseController): ) c.art.discussion = Discussion(count=0) - for artist in c.form.by.data: - UserRelation(user=artist, kind="by", creator=c.user, art=c.art) + # <<<<<<< HEAD + # if c.form.by_me and c.user not in c.form.by.data: + # UserRelation(user=c.user, creator=c.user, kind="by", art=c.art) + # + # for artist in c.form.by.data: + # UserRelation(user=artist, creator=c.user, kind="by", art=c.art) + # ======= + # For the moment, cheerfully assume that people are uploading their own + # art + ArtUser(art=c.art, user=c.user, type=ArtUserType.BY) + # >>>>>>> origin/master try: @@ -170,8 +147,7 @@ class ArtController(BaseController): def watchstream(self, name): """Watchstream for a certain user.""" try: - c.watching_user = User.query.filter(func.lower(User.name) == name) \ - .one() + c.watching_user = User.get_by(name=name) except NoResultFound: abort(404)