/
views.py
89 lines (68 loc) · 2.57 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from flask import render_template, request, redirect, json, flash
from flask.helpers import url_for
import requests
import json
import csv
import os
from dotenv import load_dotenv
from pathlib import Path
from bot import Github_Bot
ENV_PATH = Path(".") / ".env"
load_dotenv(dotenv_path=ENV_PATH)
FAV_PROJ_DB_PATH = "static/db/landing_page_projects.csv"
CERT_DB_PATH = "static/db/certs.csv"
SKILLS_PATH = "data.json"
def admin_page_view():
github_bot = Github_Bot()
github_repos = github_bot.get_public_repo()
if request.method == "POST":
if request.form.get("landing_page_submit"):
# Edit Fav Projects to pin
landing_page_items = request.form.getlist("landing_page")
with open(FAV_PROJ_DB_PATH, "w", newline="") as file:
writer = csv.writer(file)
for item in range(len(landing_page_items)):
writer.writerow([landing_page_items[item]])
if request.form.get("skill_submit"):
# Add New Skill
new_skill = request.form.get("new_skill")
skill_category = request.form.get("skill_category")
with open(SKILLS_PATH, "r+") as jsonfile:
data = json.load(jsonfile)
data["skills"]["skills"][skill_category].append(new_skill)
jsonfile.truncate(0)
jsonfile.seek(0)
json.dump(data, jsonfile)
return redirect(url_for("success"))
context = {"content": github_repos}
return render_template("admin.html", **context)
def index_page_view():
f = open(SKILLS_PATH, "r")
data = json.load(f)
f.close()
github_bot = Github_Bot()
github_repos = github_bot.get_public_repo()
projects_data = []
with open(FAV_PROJ_DB_PATH, "r") as file:
reader = csv.reader(file)
for row in reader:
projects_data.append(row[0])
cert_data = []
with open(CERT_DB_PATH, "r") as file:
reader = csv.reader(file)
for row in reader:
cert_data.append(row)
if request.method == "POST":
name = str(request.form["name"])
email = str(request.form["email"])
contact = str(request.form["contact"])
message = str(request.form["message"])[:500]
captcha_response = request.form["g-recaptcha-response"]
context = {
"content": github_repos,
"projects_data": projects_data,
"cert_data": cert_data,
"skill_category": data["skills"]["categories"],
"skills_data": data["skills"]["skills"],
}
return render_template("v3.html", **context)