Example #1
0
def message_send():
    form = forms.MessageSendForm(to=request.args.get('to', ''),
                                 subject=request.args.get('subject', ''))

    if form.validate_on_submit():
        to = UserProfile.query(UserProfile.email.IN(map(lambda un: un.strip(), form.to.data.split(',')))).fetch(1000)

        if form.subject.data:
            item = None
            try:
                item = Item.get_by_id(long(form.subject.data))
            except ValueError: pass
            if not item:
                flash(_LT('Subject must be a valid item ID.'), 'error')
                return redirect(url_for('message_send'))

            if item.seller_id != to[0].get_id() or len(to) > 1:
                flash(_LT('Messages about items can only be sent to their sellers!'), 'error')
                return redirect(item.url())

        message_key, conv_key = Message.send(current_user, to, form.subject.data, form.message.data)
        return redirect(url_for('message_conversation', id=conv_key.id()) + '#message_%s' % message_key.id())

    return render_template('message/send.html', message_send_form=form,
                           title=_T('Send Message'))
Example #2
0
def user(id):
    user_profile = UserProfile.get_or_404(id)
    app_config_form = None
    if current_user.has_role('admin'):
        app_config_form = forms.AppConfigForm(search_rate=user_profile.appconfig.get('search'))
        app_config_form.itemfetch_rate.data = user_profile.appconfig.get('item')
        app_config_form.migrate_rate.data = user_profile.appconfig.get('user_import')
        app_config_form.message_rate.data = user_profile.appconfig.get('send_message')
        app_config_form.suggest_rate.data = user_profile.appconfig.get('search_suggestions')
        app_config_form.ratings_rate.data = user_profile.appconfig.get('review')


    if user_profile.editable_by(current_user):
        user_profile_form = forms.UserProfileForm(name=user_profile.display_name,
                                                  bio=user_profile.bio or '',
                                                  ga_id=user_profile.ga_id,
                                                  app_key=user_profile.app_key)
        if user_profile_form.validate_on_submit():
            user_profile.name = user_profile_form.name.data
            user_profile.bio = user_profile_form.bio.data
            user_profile.ga_id = user_profile_form.ga_id.data
            if user_profile.app_key != user_profile_form.app_key.data:
                user_profile.reset_app_key()
                user_profile_form.app_key.data = user_profile.app_key
            user_profile.put()
            flash(_LT('Your profile has been updated!'), 'success')
    else:
        user_profile_form = None

    return render_template('user/user.html', user_profile=user_profile, user_profile_form=user_profile_form,
                           title=user_profile.display_name, app_config_form=app_config_form)
Example #3
0
def feedback_add(key):
    k = ndb.Key(urlsafe=key)

    form = forms.FeedbackForm()

    if form.validate_on_submit():
        Feedback.add_or_update(k, current_user.key, form.rating.data, form.feedback.data)
        flash(_LT('Your feedback has been submitted. Thanks!'), 'success')
        return redirect(request.args.get('next', url_for('item_index')))

    return redirect(url_for('item', id=k.id(), slug=k.get().slug))
Example #4
0
 def for_user(cls, user):
     """
     Returns a UserProfile object for a GAE User (and creates it if it doesn't exist)
     :param user: a User object
     :return: a UserProfile object
     """
     user_profile = cls.get_by_id(user.user_id())
     if not user_profile:
         user_profile = UserProfile(id=user.user_id(), email=user.email(), name=user.nickname())
         # HACK (this shouldn't be done here!)
         flash(_LT('Hi there! Your user account has just been created, so why not go to your profile (top right) '
                   'and set things up?'))
         user_profile.put()
     return user_profile
Example #5
0
def collection_create():
    collection_form = forms.CollectionForm()
    # XXX This could potentially be a problem, but given the current scale of the app, it shouldn't
    # cause much trouble.
    # NOTE: Because we populate the choices here and validate_on_submit later, even if the user
    # modifies the options by hand, they'll still be verified against these choices.
    collection_form.item_ids.choices = [(item.key.id(), '#%s - %s' % (item.key.id(), item.title)) for item in
                                        Item.query(Item.seller_id == current_user.get_id()).fetch(100000)]

    if collection_form.validate_on_submit():
        c = Collection()
        c.title = collection_form.title.data
        c.description = collection_form.description.data
        c.author = current_user
        c.item_keys = [ndb.Key(Item, id) for id in collection_form.item_ids.data]
        k = c.put()

        flash(_LT('Your collection has been created successfully!'), 'success')
        return redirect(url_for('collection', id=k.id()))

    return render_template('collection/create.html', collection_form=collection_form,
                           title=_T('Create Collection'))
Example #6
0
 def validate_username(self, field):
     if field.data != current_user.username:
         raise ValidationError(_LT('The username entered must match your username exactly.'))
Example #7
0
 def validate_email(self, field):
     from models import User
     u = User.query(User.email == field.data).get()
     if u:
         raise ValidationError(_LT('Sorry, but this email is already in use'))
Example #8
0
 def validate_username(self, field):
     from models import User
     u = User.query(User.username == field.data).get()
     if u:
         raise ValidationError(_LT('Sorry, but this username is already in use.'))