# Coverage for modules/box__bizhelp/page/view.py : 55%

## 51 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 import json

2 import os

3

4 from flask import Blueprint

5 from flask import redirect

6 from flask import render_template

7 from flask import request

8 from flask import url_for

9 from flask_login import login_required

10

11 from .forms import PageForm

12 from .models import Page

13 from shopyo.api.forms import flash_errors

14

15 dirpath = os.path.dirname(os.path.abspath(__file__))

16 module_info = {}

17

18 with open(dirpath + "/info.json") as f:

19 module_info = json.load(f)

20

21 globals()["{}_blueprint".format(module_info["module_name"])] = Blueprint(

22 "{}".format(module_info["module_name"]),

23 __name__,

24 template_folder="templates",

25 url_prefix=module_info["url_prefix"],

26)

27

28

29 module_blueprint = globals()["{}_blueprint".format(module_info["module_name"])]

30

31 module_name = module_info["module_name"]

32

33 sidebar = [{"text": "sample", "icon": "fa fa-table", "url": ""}]

34

35 module_settings = {"sidebar": sidebar}

36

37

38@module_blueprint.route("/")

39 def index():

40 context = {}

41 pages = Page.query.all()

42

43 context.update({"pages": pages})

44 return render_template("page/all_pages.html", **context)

45

46

47@module_blueprint.route("/<page_id>/<slug>")

48 def view_page(page_id, slug):

49 context = {}

50 page = Page.query.get(page_id)

51

52 context.update({"page": page})

53 return render_template("page/view_page.html", **context)

54

55

56@module_blueprint.route(module_info["dashboard"])

57@login_required

58 def dashboard():

59 context = {}

60 form = PageForm()

61

62 context.update({"form": form, "module_name": module_name})

63 context.update(module_settings)

64 return render_template("page/dashboard.html", **context)

65

66

67@module_blueprint.route("/check_pagecontent", methods=["GET", "POST"])

68@login_required

69 def check_pagecontent():

70 if request.method == "POST":

71 form = PageForm()

72 if not form.validate_on_submit():

73 flash_errors(form)

74 return redirect(url_for(f"{module_name}.dashboard"))

75 toaddpage = Page(

76 slug=form.slug.data,

77 content=form.content.data,

78 title=form.title.data,

79 )

80 toaddpage.insert()

81 return redirect(url_for(f"{module_name}.dashboard"))