示例#1
0
def admin_approve(key):
    if key and key in app.config['ACCESSKEY_APPROVE']:
        p = Participant.query.get(request.form['id'])
        if not p:
            status = "No such user"
        else:
            if 'action.undo' in request.form:
                p.approved = False
                status = 'Undone!'
                # Remove from MailChimp
                if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
                    mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
                    try:
                        mc.listUnsubscribe(
                            id = app.config['MAILCHIMP_LIST_ID'],
                            email_address = p.email,
                            send_goodbye = False,
                            send_notify = False,
                            )
                        pass
                    except MailChimpError, e:
                        status = e.msg
                db.session.commit()
            elif 'action.approve' in request.form:
                p.approved = True
                status = "Tada!"
                mailsent = False
                # 1. Make user account and activate it
                user = makeuser(p)
                user.active = True
                # 2. Add to MailChimp
                if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
                    mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
                    try:
                        mc.listSubscribe(
                            id = app.config['MAILCHIMP_LIST_ID'],
                            email_address = p.email,
                            merge_vars = {'FULLNAME': p.fullname,
                                          'JOBTITLE': p.jobtitle,
                                          'COMPANY': p.company,
                                          'TWITTER': p.twitter,
                                          'PRIVATEKEY': user.privatekey,
                                          'UID': user.uid},
                            double_optin = False
                            )
                    except MailChimpError, e:
                        status = e.msg
                        if e.code == 214: # Already subscribed
                            mailsent = True
                # 3. Send notice of approval
                if not mailsent:
                    msg = Message(subject="Your registration has been approved",
                                  recipients = [p.email])
                    msg.body = render_template("approve_notice.md", p=p)
                    msg.html = markdown(msg.body)
                    with app.open_resource("static/doctypehtml5.ics") as ics:
                        msg.attach("doctypehtml5.ics", "text/calendar", ics.read())
                    mail.send(msg)
                db.session.commit()
示例#2
0
def approve(key):
    if key and key in app.config['ACCESSKEY_APPROVE']:
        p = Participant.query.get(request.form['id'])
        if not p:
            status = 'No such user'
        else:
            if 'action.undo' in request.form:
                p.approved = False
                status = 'Undone!'
                # Remove from MailChimp
                if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
                    mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
                    try:
                        mc.listUnsubscribe(
                            id = app.config['MAILCHIMP_LIST_ID'],
                            email_address = p.email,
                            send_goodbye = False,
                            send_notify = False,
                            )
                        pass
                    except MailChimpError, e:
                        status = e.msg
                db.session.commit()
            elif 'action.approve' in request.form:
                p.approved = True
                status = "Tada!"
                mailsent = False
                # 1. Add to MailChimp
                if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
                    mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
                    try:
                        mc.listSubscribe(
                            id = app.config['MAILCHIMP_LIST_ID'],
                            email_address = p.email,
                            merge_vars = {'FULLNAME': p.fullname,
                                          'JOBTITLE': p.jobtitle,
                                          'COMPANY': p.company,
                                          'TWITTER': p.twitter},
                            double_optin = False
                            )
                    except MailChimpError, e:
                        status = e.msg
                        if e.code == 214: # Already subscribed
                            mailsent = True
                # 2. Send notice of approval
                if not mailsent:
                    msg = Message(subject="Your registration has been approved",
                                  recipients = [p.email])
                    msg.body = render_template("approve_notice.md", p=p)
                    msg.html = markdown(msg.body)
                    mail.send(msg)
                db.session.commit()
示例#3
0
def admin_approve(edition):
    if request.method == 'GET':
        tz = timezone(app.config['TIMEZONE'])
        return render_template('approve.html', participants=Participant.query.filter_by(edition=edition),
                               utc=utc, tz=tz, enumerate=enumerate, edition=edition)
    elif request.method == 'POST':
        p = Participant.query.get(request.form['id'])
        if not p:
            status = "No such user"
        else:
            if 'action.undo' in request.form:
                p.approved = False
                p.user = None
                status = 'Undone!'
                # Remove from MailChimp
                if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
                    mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
                    try:
                        mc.listUnsubscribe(
                            id = app.config['MAILCHIMP_LIST_ID'],
                            email_address = p.email,
                            send_goodbye = False,
                            send_notify = False,
                            )
                        pass
                    except MailChimpError, e:
                        status = e.msg
                db.session.commit()
            elif 'action.approve' in request.form:
                if p.approved:
                    status = "Already approved"
                else:
                    # Check for dupe participant (same email, same edition)
                    dupe = False
                    for other in Participant.query.filter_by(edition=p.edition, email=p.email):
                        if other.id != p.id:
                            if other.user:
                                dupe = True
                                break
                    if dupe == False:
                        p.approved = True
                        status = "Tada!"
                        # 1. Make user account and activate it
                        user = makeuser(p)
                        user.active = True
                        # 2. Add to MailChimp
                        if MailChimp is not None and app.config['MAILCHIMP_API_KEY'] and app.config['MAILCHIMP_LIST_ID']:
                            mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
                            addmailchimp(mc, p)
                        # 3. Send notice of approval
                        msg = Message(subject="Your registration has been approved",
                                      recipients = [p.email])
                        msg.body = render_template("approve_notice_%s.md" % edition, p=p)
                        msg.html = markdown(msg.body)
                        with app.open_resource("static/doctypehtml5-%s.ics" % edition) as ics:
                            msg.attach("doctypehtml5.ics", "text/calendar", ics.read())
                        mail.send(msg)
                        db.session.commit()
                    else:
                        status = "Dupe"
            else:
                status = 'Unknown action'
示例#4
0
def admin_approve(edition):
    if request.method == 'GET':
        tz = timezone(app.config['TIMEZONE'])
        return render_template(
            'approve.html',
            participants=Participant.query.filter_by(edition=edition),
            utc=utc,
            tz=tz,
            enumerate=enumerate,
            edition=edition)
    elif request.method == 'POST':
        p = Participant.query.get(request.form['id'])
        if not p:
            status = "No such user"
        else:
            if 'action.undo' in request.form:
                p.approved = False
                p.user = None
                status = 'Undone!'
                # Remove from MailChimp
                if MailChimp is not None and app.config[
                        'MAILCHIMP_API_KEY'] and app.config[
                            'MAILCHIMP_LIST_ID']:
                    mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
                    try:
                        mc.listUnsubscribe(
                            id=app.config['MAILCHIMP_LIST_ID'],
                            email_address=p.email,
                            send_goodbye=False,
                            send_notify=False,
                        )
                        pass
                    except MailChimpError, e:
                        status = e.msg
                db.session.commit()
            elif 'action.approve' in request.form:
                if p.approved:
                    status = "Already approved"
                else:
                    # Check for dupe participant (same email, same edition)
                    dupe = False
                    for other in Participant.query.filter_by(edition=p.edition,
                                                             email=p.email):
                        if other.id != p.id:
                            if other.user:
                                dupe = True
                                break
                    if dupe == False:
                        p.approved = True
                        status = "Tada!"
                        # 1. Make user account and activate it
                        user = makeuser(p)
                        user.active = True
                        # 2. Add to MailChimp
                        if MailChimp is not None and app.config[
                                'MAILCHIMP_API_KEY'] and app.config[
                                    'MAILCHIMP_LIST_ID']:
                            mc = MailChimp(app.config['MAILCHIMP_API_KEY'])
                            addmailchimp(mc, p)
                        # 3. Send notice of approval
                        msg = Message(
                            subject="Your registration has been approved",
                            recipients=[p.email])
                        msg.body = render_template("approve_notice_%s.md" %
                                                   edition,
                                                   p=p)
                        msg.html = markdown(msg.body)
                        with app.open_resource("static/doctypehtml5-%s.ics" %
                                               edition) as ics:
                            msg.attach("doctypehtml5.ics", "text/calendar",
                                       ics.read())
                        mail.send(msg)
                        db.session.commit()
                    else:
                        status = "Dupe"
            else:
                status = 'Unknown action'