Ejemplo n.º 1
0
def email_sender():
    form = EmailForm()
    form.recipients.choices.extend([(str(g.id), g.name) for g in Guest.scan()])
    if form.validate_on_submit():
        footer = _(
            "Your RSVP link: ") + f"{request.url_root}rsvp/{{id}}" + "\n"
        footer += _(
            "Unsubscribe and delete my data: "
        ) + f"{request.url_root}rsvp/unsubscribe/{{id}}?email={{email}}"
        emailsender = EmailSender(os.getenv("SENDER_SMTP_SERVER"),
                                  os.getenv("SENDER_EMAIL_ADDRESS"),
                                  os.getenv("SMTP_USER"),
                                  os.getenv("SMTP_PASSWORD"),
                                  footer_template=footer)

        if "all" in form.recipients.data:
            guests = Guest.scan()
        else:
            guests = Guest.find_multi_id(form.recipients.data)
        success, failed = emailsender.send_emails(guests, form.subject.data,
                                                  form.body.data)
        if success:
            flash(
                str(len(success)) + _(" E-mails sent successfully"), "success")
        if failed:
            flash(str(len(failed)) + _(" E-mails couldn't be sent"), "warning")

    return render_template('email_sender.html',
                           title=_('Send mail'),
                           form=form)
Ejemplo n.º 2
0
def add_guest():
    form = GuestForm()
    if form.validate_on_submit():
        guest = Guest()
        form.fill_model(guest)
        guest.save()
        return redirect(url_for("admin.list_guest"))
    return render_template('guest_form.html', form=form, title=_("Add guest"))
Ejemplo n.º 3
0
 def create_app(self):
     app = ParentTest.create_app(self)
     from app.model.Guest import Guest
     Guest.create_table()
     app.config['LOGIN_DISABLED'] = False
     app.config["ADMIN_PASSWORD_HASH"] = generate_password_hash(
         "testing-password")
     return app
Ejemplo n.º 4
0
 def import_csv(data: str) -> bool:
     reader = csv.DictReader(io.StringIO(data),
                             delimiter=',',
                             quotechar='"')
     with Guest.batch_write():
         for row in reader:
             guest = Guest(**row)
             guest.save()
         return True
Ejemplo n.º 5
0
 def create_app(self):
     with self.env:
         from config import Config
         from tests import context
         app = context.app.create_app(Config)
         app.config['LIVESERVER_PORT'] = 0
         app.config[
             'ADMIN_PASSWORD_HASH'] = "pbkdf2:sha256:150000$nC4kA7sN$89c5edf694d455af7f1ff29ac46c77bddfd0069e8e806a29037ca33ee488070f"  # password
         from app.model.Guest import Guest
         Guest.create_table()
         return app
Ejemplo n.º 6
0
 def export_csv() -> io.StringIO:
     guest_list = Guest.scan()
     outputfile = io.StringIO()
     fields = Guest.get_attributes().keys()
     writer = csv.DictWriter(outputfile,
                             fieldnames=fields,
                             delimiter=',',
                             quotechar='"')
     writer.writeheader()
     for guest in guest_list:
         writer.writerow(guest.attribute_values)
     return outputfile
Ejemplo n.º 7
0
def admin_dashboard():
    guest_list = [guest for guest in Guest.scan()]

    max_guests = int(os.getenv("MAX_GUEST_COUNT", 200))
    return render_template("admin_dashboard.html",
                           title=_("Admin page"),
                           guest_list=guest_list,
                           max_guests=max_guests)
Ejemplo n.º 8
0
def unsubscribe(guest_id):
    email = request.args.get('email')
    guest = Guest.find(guest_id)
    if guest and email == guest.email:
        print(f"Guest {guest.id} removed")
        guest.delete()
        return render_template('unsubscribe.html')
    else:
        abort(404)
Ejemplo n.º 9
0
def edit_guest(guest_id):
    form = GuestForm()
    guest = Guest.find(guest_id) or abort(404)
    if form.validate_on_submit():
        form.fill_model(guest)
        guest.filled_by_admin = True
        guest.save()
        return redirect(url_for("admin.list_guest"))
    form.set_model(guest)
    return render_template('guest_form.html', form=form, title=_("Edit guest"))
Ejemplo n.º 10
0
 def fill_model(self, guest: Guest):
     guest.name = self.name.data
     guest.email = self.email.data
     guest.notes = self.notes.data
     guest.number_of_guests = self.number_of_guests.data
     guest.food_allergies = self.food_allergies.data
     guest.will_attend = self.will_attend.data
     guest.favourite_music = self.favourite_music.data
     return guest
Ejemplo n.º 11
0
def rsvp_captcha():
    guest_id = urlparse(request.args.get("next", "").split('/')[-1]).path

    if not guest_id:
        abort(404)
    form = RSVPCaptchaForm()

    if form.validate_on_submit() or not current_app.config["USE_RECAPTCHA_FOR_GUEST"]:
        guest = Guest.find(guest_id)
        if guest:
            login_user(guest, remember=True)
            return redirect(url_for("rsvp.rsvp_page", guest_id=guest_id))
        else:
            abort(404)
    else:
        return render_template('rsvp_captcha.html', title=_('Wedding'), form=form)
Ejemplo n.º 12
0
 def create_app(self):
     app = ParentTest.create_app(self)
     from app.model.Guest import Guest
     Guest.create_table()
     return app
Ejemplo n.º 13
0
def delete_guest(guest_id):
    guest = Guest.find(guest_id) or abort(404)
    guest.delete()
    flash(_("Guest {} removed".format(guest.name)))
    return redirect(url_for("admin.list_guest"))
Ejemplo n.º 14
0
def list_guest():
    guest_list = Guest.scan()
    return render_template('guest_list.html',
                           guests=guest_list,
                           title=_("Guest list"))
Ejemplo n.º 15
0
def load_user(user_id):
    if request.blueprint == "admin":
        if user_id == "admin":
            return Admin()
    if request.blueprint == "rsvp":
        return Guest.find(user_id)
Ejemplo n.º 16
0
 def _generate_random_guest():
     from app.model.Guest import Guest
     name = petname.generate()
     return Guest(email=f"{name}@mockmail.com",
                  name=name.replace('-', ' ').title())
Ejemplo n.º 17
0
 def create_app(self):
     app = ParentTest.create_app(self)
     from app.model.Guest import Guest
     Guest.create_table()
     app.config['LOGIN_DISABLED'] = False
     return app