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)
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"))
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
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
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
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
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)
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)
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"))
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
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)
def create_app(self): app = ParentTest.create_app(self) from app.model.Guest import Guest Guest.create_table() return app
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"))
def list_guest(): guest_list = Guest.scan() return render_template('guest_list.html', guests=guest_list, title=_("Guest list"))
def load_user(user_id): if request.blueprint == "admin": if user_id == "admin": return Admin() if request.blueprint == "rsvp": return Guest.find(user_id)
def _generate_random_guest(): from app.model.Guest import Guest name = petname.generate() return Guest(email=f"{name}@mockmail.com", name=name.replace('-', ' ').title())
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