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)
def edit_troika(troika_id): url = __check_login(url = url_for('edit_troika', troika_id = troika_id)) if url: return redirect(url) troikaerrors = [] troikaform = TroikaForm(prefix="troika") # Find out if the logged in user has rights to edit/delete troika = get_troika(troika_id); user = get_user(session['email']) access = get_troika_access_right(user, troika) if not access: flash(_(u'Only the creator or the lead can edit the Troika'), 'error') return redirect(url_for('troika', troika_id=troika_id)) if request.method == 'GET': # Add default values troikaform.title.data = troika.title troikaform.description.data = troika.description troikaform.address.data = troika.address troikaform.address_addendum.data = troika.address_addendum troikaform.language.data = troika.language troikaform.start_date.data = troika.start_time troikaform.start_time_hours.data = __get_formatted_datetime(troika.start_time,"%H") troikaform.start_time_minutes.data = __get_formatted_datetime(troika.start_time,"%M") troikaform.duration.data = __get_duration(troika.start_time, troika.end_time) troikaform.max_participants.data = troika.max_participants elif troikaform.validate_on_submit(): if request.form["action"] == _(u"Save Troika"): # Validate times if troikaform.start_date.data is not None and (troikaform.start_time_hours.data is None or troikaform.start_time_minutes.data is None or troikaform.duration.data is None): troikaerrors.append(_(u"When a date is set, you must also give values for hours, minutes and duration")) else: start_time = __get_start_datetime(troikaform.start_date.data, troikaform.start_time_hours.data, troikaform.start_time_minutes.data) if user.role != 'admin' and start_time is not None and start_time < datetime.now(): troikaerrors.append(_(u"Start time for the Troika must be in the future")) else: # Update info troika.title = troikaform.title.data troika.description = troikaform.description.data troika.address = troikaform.address.data if troikaform.address.data != "" else None troika.address_addendum = troikaform.address_addendum.data if troikaform.address_addendum.data != "" else None troika.language = troikaform.language.data troika.start_time = start_time troika.end_time = __get_end_datetime(troika.start_time, troikaform.duration.data) troika.max_participants = troikaform.max_participants.data # Activate automatically when all information is given if activation_ready(troika): __process_activation(troika) flash (_(u"Troika activated!")) save_troika(troika) flash(_(u'Troika saved')) return redirect(url_for('troika', troika_id=troika_id)) elif request.form["action"] == _(u"Delete Troika"): title = troika.title delete_troika(troika) flash(_(u"Troika \"%(title)s\" deleted", title=title)) return redirect(url_for('troikas')) if troikaform.errors: for key, value in troikaform.errors.items(): troikaerrors.append(key + ': ' + value[0]) return render_template('edit_troika.html', troikaform=troikaform, troikaerrors=troikaerrors, access=access)