コード例 #1
0
ファイル: views.py プロジェクト: ciex/motor
def persona_context():
    """Makes current_persona available in templates"""
    user = users.get_current_user()
    if user:
        persona = Persona.get_by_id(user.user_id())
    else:
        persona = None

    return dict(current_persona=persona)
コード例 #2
0
ファイル: views.py プロジェクト: ciex/motor
def index():
    # ----Render a list of the current user's movements and their current cycles
    current_persona = Persona.get_by_id(users.get_current_user().user_id())
    movements = Movement.query()
    movements_with_forms = []
    for m in movements:
        m.form = GoalForm()
        m.form.movement_id.data = m.key.id()
        m.form.cycle.data = m.get_next_cycle()
        m.user_is_member = (current_persona.key in m.members)
        movements_with_forms.append(m)
    return render_template('index.html', movements=movements)
コード例 #3
0
ファイル: views.py プロジェクト: ciex/motor
def join_movement(movement_id):
    if request.method == "POST":
        movement = Movement.get_by_id(movement_id)
        user = users.get_current_user()
        persona = Persona.get_by_id(user.user_id())
        if persona.key in movement.members:
            movement.members.remove(persona.key)
            movement.put()
            flash("You left the movement '{}'".format(movement.name), 'info')
        else:
            movement.members.append(persona.key)
            movement.put()
            flash("You joined the movement '{}'".format(movement.name), 'success')
    return redirect(request.referrer)
コード例 #4
0
ファイル: views.py プロジェクト: ciex/motor
def goal_view(goal_id=None):
    if goal_id:
        # ---- Delete a goal and redirect to http ref
        goal = Goal.get_by_id(goal_id) if goal_id else None
        if not goal:
            flash('The goal with the id {} could not be found'.format(goal_id), 'error')
        else:
            if goal.movement.get().get_current_cycle() >= goal.cycle:
                flash('You can only delete goals for future cycles', 'error')
            else:
                goal.key.delete()
                flash("Goal has been deleted", 'info')
        return redirect(request.referrer or url_for('index'))
    else:
        # ---- Create a new goal and redirect http ref
        form = GoalForm(request.form)
        if form.validate_on_submit():
            author = Persona.get_by_id(users.get_current_user().user_id())
            if not author:
                flash("You user account was not found", "error")
                return redirect(request.referrer)

            movement = Movement.get_by_id(int(form.movement_id.data))
            if not movement:
                flash("The movement '{}' was not found".format(form.movement_id.data), 'error')
                return redirect(request.referrer)

            if len(form.desc.data) > 500:
                # Remove non-ascii characters
                flash("Goals can have at most 500 characters. Your goal: {}".format(
                    "".join(i for i in form.desc.data if ord(i) < 128)), "error")
                return redirect(request.referrer)

            goal = Goal(
                movement=movement.key,
                author=author.key,
                cycle=int(form.cycle.data) if form.cycle.data else None,
                desc=form.desc.data
            )
            try:
                goal.put()
                goal_id = goal.key.id()
                flash("Goal successfully created", 'success')
                return redirect(request.referrer or url_for('index'))
            except CapabilityDisabledError:
                flash("Sorry, datastore is currently in read-only mode", 'error')
                return redirect(request.referrer or url_for('index'))
        else:
            flash("Invalid form submitted", "error")
            return redirect(request.referrer)
コード例 #5
0
ファイル: views.py プロジェクト: ciex/motor
def persona_view(persona_id=None):
    # ---- Render a persona profile
    persona = Persona.get_by_id(persona_id)
    return render_template('persona.html', persona=persona)