Esempio n. 1
0
def update_group(n):
    g = get_or_404(Group.objects, number=n)

    # Update name if given. Note that we don't update the number because
    # that's weird and I don't want to think through the ramifications.
    if 'name' in flask.request.json:
        g.update(set__name=flask.request.json['name'])

    # For each talk we have to remove it from an exsting group, if neccisary,
    # add it to this group, and make sure to mark it grouped.
    for talk_id in flask.request.json.get('talks', []):
        g.add_talk_id(talk_id)

    return flask.jsonify(doc2dict(g, fields=('number', 'name')))
Esempio n. 2
0
def _jsonify_talks(tl):
    return flask.jsonify(objects=[
        doc2dict(t, fields=('talk_id', 'title')) for t in tl
    ])
Esempio n. 3
0
def api_groups():
    return flask.jsonify(objects=[
        doc2dict(g, fields=('number', 'name'))
        for g in Group.objects.all()
    ])
Esempio n. 4
0
def new_group():
    g = Group.objects.create(name=flask.request.json['name'])
    for talk_id in flask.request.json['talks']:
        g.add_talk_id(talk_id)
    return flask.jsonify(doc2dict(g, fields=('number', 'name')))
else:
    p.error("Pass either --id or --status; I won't email all authors.")

# Read and parse the template.
try:
    template = io.open(args.template, encoding='utf8').read()
    subject_line, body_template = template.split('\n\n', 1)
except IOError:
    p.error("Template doesn't exist.")
except ValueError:
    p.error("Template is malformed; must be 'Subject: ...\n\nBody ...")
if not subject_line.startswith('Subject:'):
    p.error("Template doesn't start with 'Subject: ...")
subject_template = subject_line.replace('Subject:', '').strip()

# Send ye olde emailes.
for talk in talks:
    t = doc2dict(talk)
    sys.stdout.write(u"Emailing {speaker_email} about #{talk_id} - {title} ... ".format(**t))
    sys.stdout.flush()
    subject = subject_template.format(**t)
    message = body_template.format(**t)
    if args.test:
        mail.send_mail(subject=subject, message=message, from_email=args.from_email, recipient_list=[args.test])
        print "OK - sent test email instead."
        break
    if not args.dry_run:
        mail.send_mail(subject=subject, message=message, from_email=args.from_email, recipient_list=[talk.speaker_email])
        time.sleep(args.sleep)
    print "OK"