diff --git a/Sakhniuk Kostiantyn/workshop2/WorkShop 2 Flask.pdf b/Sakhniuk Kostiantyn/workshop2/WorkShop 2 Flask.pdf new file mode 100644 index 0000000..618109e Binary files /dev/null and b/Sakhniuk Kostiantyn/workshop2/WorkShop 2 Flask.pdf differ diff --git a/Sakhniuk Kostiantyn/workshop2/forms.py b/Sakhniuk Kostiantyn/workshop2/forms.py new file mode 100644 index 0000000..9e3f1f3 --- /dev/null +++ b/Sakhniuk Kostiantyn/workshop2/forms.py @@ -0,0 +1,15 @@ +from flask_wtf import FlaskForm +from wtforms import StringField, SubmitField + +class ProductForm(FlaskForm): + product_name = StringField('product_name') + type = StringField('type') + vendor = StringField('vendor') + cost = StringField('cost') + submit = SubmitField('Submit') + +class VendorForm(FlaskForm): + vendor_name = StringField('vendor_name') + products = StringField('products') + link = StringField('link') + submit = SubmitField('Submit') \ No newline at end of file diff --git a/Sakhniuk Kostiantyn/workshop2/main.py b/Sakhniuk Kostiantyn/workshop2/main.py new file mode 100644 index 0000000..fbb61ea --- /dev/null +++ b/Sakhniuk Kostiantyn/workshop2/main.py @@ -0,0 +1,53 @@ +from flask import Flask, render_template, request, redirect, url_for +from forms import * + +app = Flask(__name__) +app.config['SECRET_KEY'] = '5930142' + +product_dict = {'product_name': 'Intel Core i9-9900K', + 'type': 'processor', + 'vendor': 'Bob', + 'cost': 15000} + +vendor_dict = {'vendor_name': 'Bob', + 'products': 'Intel Core i9-9900K,Intel Core i9-9900K', + 'link': 'none' + } + +@app.route('/api/', methods=['GET']) +def apiget(action): + if action == "product": + return render_template("product.html", product=product_dict) + elif action == "vendor": + return render_template("vendor.html", vendor=vendor_dict) + elif action == "all": + return render_template("all.html", product=product_dict, vendor=vendor_dict) + else: + return render_template("404.html", action_value=action) + +@app.route('/api/product', methods=['GET', 'POST']) +def api_product(): + form = ProductForm() + if form.is_submitted(): + result = request.form + product_dict['product_name'] = result['product_name'] + product_dict['type'] = result['type'] + product_dict['vendor'] = result['vendor'] + product_dict['cost'] = result['cost'] + return redirect(url_for('apiget', action="all")) + return render_template('product.html', form=form) + +@app.route('/api/vendor', methods=['GET', 'POST']) +def api_vendor(): + form = VendorForm() + if form.is_submitted(): + result = request.form + vendor_dict['vendor_name'] = result['vendor_name'] + vendor_dict['products'] = result['products'] + vendor_dict['link'] = result['link'] + return redirect(url_for('apiget', action="all")) + return render_template('vendor.html', form=form) + + +if __name__ == '__main__': + app.run() \ No newline at end of file diff --git a/Sakhniuk Kostiantyn/workshop2/templates/404.html b/Sakhniuk Kostiantyn/workshop2/templates/404.html new file mode 100644 index 0000000..e3ebb90 --- /dev/null +++ b/Sakhniuk Kostiantyn/workshop2/templates/404.html @@ -0,0 +1,14 @@ +{% extends "basis.html" %} +{% block head %} + + 404 page +{% endblock %} + +{% block header%} +

Error 404

+{% endblock %} + +{% block content%} +

Uncorrect action: {{action_value}}.

+

Correct values: (product, vendor, all).

+{% endblock %} \ No newline at end of file diff --git a/Sakhniuk Kostiantyn/workshop2/templates/all.html b/Sakhniuk Kostiantyn/workshop2/templates/all.html new file mode 100644 index 0000000..6015f8e --- /dev/null +++ b/Sakhniuk Kostiantyn/workshop2/templates/all.html @@ -0,0 +1,41 @@ +{% extends "basis.html" %} + +{% block head %} + + all +{% endblock %} + +{% block content%} +
+
+

Vendor table

+ + {% for key, value in product.items() %} + + + + + {% endfor %} +
+ {{key}} + + {{value}} +
+
+
+

Vendor table

+ + {% for key, value in vendor.items() %} + + + + + {% endfor %} +
+ {{key}} + + {{value}} +
+
+
+{% endblock %} \ No newline at end of file diff --git a/Sakhniuk Kostiantyn/workshop2/templates/basis.html b/Sakhniuk Kostiantyn/workshop2/templates/basis.html new file mode 100644 index 0000000..f7e6400 --- /dev/null +++ b/Sakhniuk Kostiantyn/workshop2/templates/basis.html @@ -0,0 +1,14 @@ + + + + {% block head %} + {% endblock %} + + + + {% block header %} + {% endblock %} + {% block content %} + {% endblock%} + + \ No newline at end of file diff --git a/Sakhniuk Kostiantyn/workshop2/templates/product.html b/Sakhniuk Kostiantyn/workshop2/templates/product.html new file mode 100644 index 0000000..2152ce9 --- /dev/null +++ b/Sakhniuk Kostiantyn/workshop2/templates/product.html @@ -0,0 +1,34 @@ +{% extends "basis.html" %} + +{% block head %} + + Product +{% endblock%} + +{% block header %} +{% endblock%} + +{% block content %} +

Product form

+
+

+ {{ form.product_name.label }}
+ {{ form.product_name(size=30) }} +

+

+ {{ form.type.label }}
+ {{ form.type(size=30) }} +

+

+ {{ form.vendor.label }}
+ {{ form.vendor(size=30) }} +

+

+ {{ form.cost.label }}
+ {{ form.cost(size=30) }} +

+ +

{{ form.submit() }}

+
+ +{% endblock %} \ No newline at end of file diff --git a/Sakhniuk Kostiantyn/workshop2/templates/vendor.html b/Sakhniuk Kostiantyn/workshop2/templates/vendor.html new file mode 100644 index 0000000..d698d1c --- /dev/null +++ b/Sakhniuk Kostiantyn/workshop2/templates/vendor.html @@ -0,0 +1,29 @@ +{% extends "basis.html" %} + +{% block head %} + + Vednor +{% endblock%} + +{% block header %} +{% endblock%} + +{% block content %} +

Vendor form

+
+

+ {{ form.vendor_name.label }}
+ {{ form.vendor_name(size=30) }} +

+

+ {{ form.products.label }}
+ {{ form.products(size=30) }} +

+

+ {{ form.link.label }}
+ {{ form.link(size=30) }} +

+

{{ form.submit() }}

+
+ +{% endblock %} \ No newline at end of file