# Coverage for modules/box__bizhelp/contact/view.py : 46%

## 42 statements

Hot-keys on this page

r m x p toggle line displays

j k next/prev highlighted chunk

0 (zero) top of page

1 (one) first highlighted chunk

1 from flask import Blueprint

2 from flask import flash

3 from flask import redirect

4 from flask import render_template

5 from flask import request

6 from flask import url_for

7 from flask_login import login_required

8

9 from .forms import ContactForm

10 from .models import ContactMessage

11 from shopyo.api.forms import flash_errors

12 from shopyo.api.html import notify_success

13

14 contact_blueprint = Blueprint(

15 "contact",

16 __name__,

17 url_prefix="/contact",

18 template_folder="templates",

19)

20

21

22@contact_blueprint.route("/")

23 def index():

24 context = {}

25 form = ContactForm()

26

27 context.update({"form": form})

28 return render_template("contact/contact_form.html", **context)

29

30

31@contact_blueprint.route("/validate_message", methods=["GET", "POST"])

32@login_required

33 def validate_message():

34 if request.method == "POST":

35 form = ContactForm()

36 if not form.validate_on_submit():

37 flash_errors(form)

38 return redirect(url_for("contact.index"))

39

40 name = form.name.data

41 email = form.email.data

42 message = form.message.data

43

44 contact_message = ContactMessage(name=name, email=email, message=message)

45 contact_message.insert()

46 flash(notify_success("Message submitted!"))

47 return redirect(url_for("contact.index"))

48

49

50@contact_blueprint.route("/dashboard", methods=["GET"], defaults={"page": 1})

51@contact_blueprint.route("/dashboard/<int:page>", methods=["GET"])

52@login_required

53 def dashboard(page):

54 context = {}

55

56 per_page = 10

57 messages = ContactMessage.query.paginate(page, per_page, error_out=False)

58 context.update({"messages": messages})

59 return render_template("contact/dashboard.html", **context)