Ejemplo n.º 1
0
def troika(troika_id):
    troika = get_troika(troika_id);
    access = False
    activate = False
    user = None
    if 'email' in session:
        user = get_user(session['email'])
        access = get_troika_access_right(user, troika)
        activate = activatable(user, troika, app.config.get('ACTIVATABLE_BEFORE_THREE'))
    
    troikaform = TroikaForm(language=troika.language)
    language_name = [item for item in troikaform.language.choices if item[0] == troika.language][0][1]

    address_text = troika.address
    if address_text is None:
        address_text = troika.address_addendum
    elif troika.address_addendum is not None:
        address_text += " - " + troika.address_addendum
    if address_text is None:
        address_text = _(u'Not set')

    entry = {'access': access,
             'activate': activate,
             'id': troika.id,
             'phase': troika.get_phase(),
             'title': troika.title,
             'description': Markup(markdown.markdown(troika.description)),
             'address': address_text,
             'language': language_name,
             'start_time': __get_formatted_datetime(troika.start_time,"%d.%m.%Y %H:%M") if troika.start_time is not None else _(u"Not set"),
             'end_time': __get_formatted_datetime(troika.end_time,"%d.%m.%Y %H:%M") if troika.end_time is not None else _(u"Not set"),
             'max_participants': troika.max_participants if troika.max_participants is not None else _(u"Not set"),
             'is_full': __is_full(troika),
             'participating': __participating(user, troika),
             'lead': __get_display_name(troika.lead) if troika.lead != None else None,
             'first_learner': __get_display_name(troika.first_learner) if troika.first_learner != None else None,
             'second_learner': __get_display_name(troika.second_learner) if troika.second_learner != None else None,
             'participants': [dict(id=participant.id, \
                                full_name=__get_display_name(participant)) \
                                for participant in troika.participants] if troika.participants is not None else None
             }
    inviteform_lead = InviteForm(role='0', troika_id = troika.id)
    inviteform_first = InviteForm(role='1', troika_id = troika.id)
    inviteform_second = InviteForm(role='2', troika_id = troika.id)
    inviteform_participant = InviteForm(role='3', troika_id = troika.id)
    # show the troika with the given id
    return render_template('troika.html', 
                           troika=entry,
                           inviteform_lead=inviteform_lead,
                           inviteform_first=inviteform_first,
                           inviteform_second=inviteform_second,
                           inviteform_participant=inviteform_participant)
Ejemplo n.º 2
0
def activate_troika(troika_id):
    url = __check_login(url = url_for('activate_troika', troika_id = troika_id))
    if url: return redirect(url)

    troika = get_troika(troika_id);
    user = get_user(session['email'])
    if activatable(user, troika, app.config.get('ACTIVATABLE_BEFORE_THREE')):
        if troika.start_time < datetime.now() and user.role != 'admin':
            flash(_(u'Start time is in the past, change it before activating Troika'), 'error')
            return redirect(url_for('troika', troika_id=troika_id))            
        __process_activation(troika)
        save_troika(troika)
        flash(_(u"Troika %(title)s activated", title=troika.title))
        return redirect(url_for('troika', troika_id=troika_id))
    else:
        flash(_(u'Troika can only be activated by the creator or lead after all required information is set'), 'error')
        return redirect(url_for('troika', troika_id=troika_id))