Example #1
0
def __process_pending(troika):
    if troika.get_phase() == 'pending' and \
       troika.lead is not None and \
       troika.first_learner is not None and \
       troika.second_learner is not None:
        troika.pended = datetime.now()
        if activation_ready(troika):
            __process_activation(troika)
            flash (_(u"Troika activated!"))
        else: 
            if not app.config.get('MAIL_SKIP'):    
                # Send message to all three participants
                msg = __get_troika_message(_(u"Troika \"%(title)s\" is just about to be born!", title=troika.title), troika)
                msg.body = _(u"Congratulations! The Troika \"%(title)s\":", title=troika.title)
                msg.body += "\n\n" + url_for('troika', troika_id=troika.id, _external=True)
                msg.body += "\n\n"
                msg.body += _(u"has now all three participants!")
                msg.body += "\n\n"
                msg.body += _(u"Your job now is to:")
                msg.body += "\n"
                msg.body += _(u"1. decide on the remaining open details for the Troika,")
                msg.body += _(u"2. go to the Troika page and press \"Edit Troika\" (visible for the lead and creator),")
                msg.body += _(u"3. add the missing information and press \"Save Troika\".")
                msg.body += "\n\n"
                msg.body += _(u"Get going!")
                msg.body += "\n\n"
                msg.body += _(u"[insert inspirational quote about balalaikas here]")
                msg.body += "\n\n"
                msg.body += __get_troika_message_signature()
                mail.send(msg)
Example #2
0
def invite():
    url = __check_login(url = get_redirect_target())
    if url: return redirect(url)
    inviteform = InviteForm()
    if inviteform.validate():
        user = get_user(session['email'])
        troika = get_troika(inviteform.troika_id.data)
        if troika is None:
            flash(_(u'Invalid Troika Id'), 'error')
        elif troika.get_phase() == 'complete':
            flash(_(u'Can not invite to a completed Troika'), 'error')
        else:
            msg = Message(_(u"Come join the Troika \"%(title)s\"!", title=troika.title),
                      sender = ("Troika Webmaster", "*****@*****.**"),
                      recipients=[inviteform.email.data])
        
            msg.body = _("%(user)s thought you should join the Troika \"%(title)s\":", user = __get_display_name(user), title=troika.title)
            msg.body += "\n\n" + url_for('troika', troika_id=troika.id, _external=True)
            msg.body += "\n\n"
            
            role_string = None
            if inviteform.role.data == '0':
                if troika.lead is None:
                    role_string = _("the lead")
                else:
                    flash(_(u'Troika already has a lead'), 'error')
            elif inviteform.role.data == '1':
                if troika.first_learner is None:
                    role_string = _("the first learner")
                else:
                    flash(_(u'Troika already has a first learner'), 'error')
            elif inviteform.role.data == '2':
                if troika.second_learner is None:
                    role_string = _("the second learner")
                else:
                    flash(_(u'Troika already has a second learner'), 'error')
            elif inviteform.role.data == '3':
                role_string = _("a participant")
            else:
                flash(_(u'Invalid role: ') + 'inviteform.role', 'error')
            if role_string is not None:  
                msg.body += _("as %(role)s.", role=role_string)
                msg.body += "\n\n" 
                msg.body += _("What do you say?") + "\n\n"
                msg.body += __get_troika_message_signature()
                
                mail.send(msg)
                flash(_(u'Invite sent to %(email)s', email = inviteform.email.data))
    else:
        flash(_(u"Invalid invite form") + ': ' + ', '.join((key + ': ' + value[0]) for key, value in inviteform.errors.items()), 'error')
    return redirect(get_redirect_target())
Example #3
0
def __process_activation(troika):
    troika.activated = datetime.now()
    
    if not app.config.get('MAIL_SKIP'):    
        # Send message to all three participants
        msg = __get_troika_message(_(u"Troika \"%(title)s\" activated!", title=troika.title), troika)
        msg.body = _(u"Congratulations! The Troika \"%(title)s\":", title=troika.title)
        msg.body += "\n\n" + url_for('troika', troika_id=troika.id, _external=True)
        msg.body += "\n\n"
        msg.body += _(u"has now been activated. You can view the participants on the Troika page.")
        msg.body += "\n\n"
        msg.body += _(u"Happy learnings!")
        msg.body += "\n\n"
        msg.body += __get_troika_message_signature()
        mail.send(msg)
Example #4
0
def forgot():
    forgotform = ForgotForm()
    if forgotform.validate():
        reset_link = generate_password_reset_link(forgotform.email.data)
        if reset_link is None:
            flash(_(u'Could not find user with given email'), 'error')
        else:
            msg = Message(_(u"Troikalearning.org password reset"),
                      sender = ("Troika Webmaster", "*****@*****.**"),
                      recipients=[forgotform.email.data])
        
            msg.body = _("Go to the following link to reset your password in the troikalearning.org website:")
            msg.body += "\n\n" + reset_link
            msg.body += "\n\n"
            msg.body += _("If you did not ask for your password to be reset, you can ignore this message.")
            msg.body += "\n\n"
            msg.body += __get_troika_message_signature()    
            mail.send(msg)
            flash(_(u'Password reset instructions sent to %(email)s', email = forgotform.email.data))
    else:
        flash(_(u"Invalid forgot form") + ': ' + ', '.join((key + ': ' + value[0]) for key, value in forgotform.errors.items()), 'error')
    return redirect(get_redirect_target())