From ccbf5825828b0f96e30288f4d0c89e746ad7b2d4 Mon Sep 17 00:00:00 2001 From: Stefan Dworschak Date: Mon, 21 Mar 2022 20:51:13 +0000 Subject: [PATCH 1/8] Restructring the app --- .env_sample | 0 README.md | 13 ++- app/__init__.py | 8 +- app/api_users.py | 2 +- app/cluster_model.py | 5 +- app/config.py | 7 +- app/functions/company_web_scraper.py | 31 ++++++ app/index.py | 1 - app/main.py | 7 ++ app/organisations.py | 104 ++++++++++++++++++ {static => app/static}/js/scripts.js | 0 app/templates/base.html | 31 +++--- app/templates/navbar.html | 26 +++++ .../organisations/create_organisation.html | 68 ++++++++++++ .../organisations/edit_organisation.html | 72 ++++++++++++ .../organisations/organisations_list.html | 59 ++++++++++ demo_data.json => data/demo_data.json | 0 env.py.sample | 9 ++ run.py | 11 +- templates/create_organisation.html | 68 ------------ templates/edit_organisation.html | 72 ------------ templates/organisations_list.html | 59 ---------- 22 files changed, 423 insertions(+), 230 deletions(-) delete mode 100644 .env_sample create mode 100644 app/functions/company_web_scraper.py create mode 100644 app/main.py create mode 100644 app/organisations.py rename {static => app/static}/js/scripts.js (100%) create mode 100644 app/templates/navbar.html create mode 100644 app/templates/organisations/create_organisation.html create mode 100644 app/templates/organisations/edit_organisation.html create mode 100644 app/templates/organisations/organisations_list.html rename demo_data.json => data/demo_data.json (100%) create mode 100644 env.py.sample delete mode 100644 templates/create_organisation.html delete mode 100644 templates/edit_organisation.html delete mode 100644 templates/organisations_list.html diff --git a/.env_sample b/.env_sample deleted file mode 100644 index e69de29..0000000 diff --git a/README.md b/README.md index df1a12d..9bf6c48 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,17 @@ A Collaborative Open-Source Project where we are looking for a way to put regional Irish IT businesses into clusters based on their services/products. The information about their services/products should be found on their website, but are not in a format it can be used for applications. +# Prerequisists + +- Python 3.8+ +- MongoDB (either an ATLAS instance or locally installed) + +# How to run the project + +1) Create a new `env.py` file with the content from the `env.py.sample` file. Update the `MONGO_URI` and `MONGO_DBNAME` if necessary. +1) Install the requirements (optionally create a new virtual environment ) +1) Start the app running `pyhton3 run.py` from the terminal + # Challenge - The primary challenge is to query an existing company name dataset, find their website, extract the relevant data which can be queried by search. @@ -38,4 +49,4 @@ Contribution will be rewarded with special participation badges and prizes. # Credit - Code to create keywords from a text is from Xu Liang. - - [Understand TextRank for Keyword Extraction by Python](https://towardsdatascience.com/textrank-for-keyword-extraction-by-python-c0bae21bcec0) \ No newline at end of file + - [Understand TextRank for Keyword Extraction by Python](https://towardsdatascience.com/textrank-for-keyword-extraction-by-python-c0bae21bcec0) diff --git a/app/__init__.py b/app/__init__.py index f5306ef..b069494 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -12,6 +12,7 @@ def create_app(default_config=Config): Allows to use Blueprint for separation of concern. """ + app = Flask(__name__) # Use the Config class to set the app. app.config.from_object(default_config) @@ -22,13 +23,14 @@ def create_app(default_config=Config): # Import Blueprints and register them so they can be used # For exemple I have created the index.py app and registered it as follow from app.index import home - app.register_blueprint(home) - from app.api_users import api_users from app.cluster_model import cluster_model - from app.app import main + from app.main import main + from app.organisations import organisations + app.register_blueprint(home) app.register_blueprint(api_users) app.register_blueprint(cluster_model) app.register_blueprint(main) + app.register_blueprint(organisations) return app \ No newline at end of file diff --git a/app/api_users.py b/app/api_users.py index 482ba4a..40c2372 100644 --- a/app/api_users.py +++ b/app/api_users.py @@ -9,7 +9,7 @@ from app.functions.create_cat_from_nace import * # Blueprint -api_users = Blueprint("api_users", __name__) +api_users = Blueprint("api_users", __name__, template_folder='templates') # collection data_set_coll = mongo.db.SampleData diff --git a/app/cluster_model.py b/app/cluster_model.py index 76db584..ebce432 100644 --- a/app/cluster_model.py +++ b/app/cluster_model.py @@ -8,10 +8,11 @@ from app import mongo from app.functions.text_rank import TextRank4Keyword -from company_web_scraper import getHTMLdocument +from app.functions.company_web_scraper import getHTMLdocument # Blueprint -cluster_model = Blueprint("cluster_model", __name__) +cluster_model = Blueprint("cluster_model", __name__, + template_folder='templates') @cluster_model.route("/clustering", methods=["GET"]) diff --git a/app/config.py b/app/config.py index 128a06e..30eb0b3 100644 --- a/app/config.py +++ b/app/config.py @@ -1,7 +1,4 @@ -import os -if os.path.exists("env.py"): - import env - +import os class Config: """ @@ -9,4 +6,4 @@ class Config: """ MONGO_DBNAME = os.environ.get("MONGO_DBNAME") MONGO_URI = os.environ.get("MONGO_URI") - SECRET_KEY = os.environ.get("SECRET_KEY") \ No newline at end of file + SECRET_KEY = os.environ.get("SECRET_KEY") diff --git a/app/functions/company_web_scraper.py b/app/functions/company_web_scraper.py new file mode 100644 index 0000000..737f103 --- /dev/null +++ b/app/functions/company_web_scraper.py @@ -0,0 +1,31 @@ +import requests +from bs4 import BeautifulSoup +import re + + +# function to extract html document from given url +def getHTMLdocument(url): + + # request for HTML document of given url + response = requests.get(url) + + # response will be provided in JSON format + return response.text + +url_to_scrape = "https://www.recruiters.ie/" + +# create document +html_document = getHTMLdocument(url_to_scrape) + +# create soap object +soup = BeautifulSoup(html_document, 'html.parser') + +# find all the anchor tags with "href" +# attribute starting with "https:// and the about keyword" +# remove | about if you want to return all links on landing page +links = [] +for link in soup.find_all('a', + attrs={'href': re.compile(r'^http://|about')}): + links.append(link.get('href')) +# display the actual urls +print(links[0]) \ No newline at end of file diff --git a/app/index.py b/app/index.py index 8484bfe..761eb65 100644 --- a/app/index.py +++ b/app/index.py @@ -10,7 +10,6 @@ home = Blueprint("home", __name__) @home.route("/") -@home.route("/index") def index(): # Display home page return render_template("index.html") \ No newline at end of file diff --git a/app/main.py b/app/main.py new file mode 100644 index 0000000..2210871 --- /dev/null +++ b/app/main.py @@ -0,0 +1,7 @@ +from flask import ( + Flask, flash, render_template, redirect, + request, session, url_for, Blueprint, current_app) + + +# Blueprint +main = Blueprint("main", __name__) diff --git a/app/organisations.py b/app/organisations.py new file mode 100644 index 0000000..2152b32 --- /dev/null +++ b/app/organisations.py @@ -0,0 +1,104 @@ +from flask import ( + Flask, flash, render_template, + redirect, request, session, url_for, + Blueprint) +from bson.objectid import ObjectId + +from app import mongo + +organisations = Blueprint("organisations", __name__, template_folder='templates') + + +@organisations.route('/organisations', methods=['GET', 'POST']) +def get_organisations(): + ''' + Display a list of all organisations in table format for admin user + ''' + organisations = mongo.db.organisations.find() + return render_template('organisations/organisations_list.html', + organisations=organisations) + + +# TODO: define user role permission for admin and user. When user submits +# the form, will admin have to check the submission and approve before +# it is added to the database? +@organisations.route("/organisations/add", methods=["GET", "POST"]) +def create_organisation(): + ''' + Add an organisation for normal user and admin user + ''' + if request.method == "POST": + organisation_name = request.form.get("organisation_name") + latitude = request.form.get("latitude") + longitude = request.form.get("longitude") + nace_1 = request.form.get("nace_1") + nace_1_label = request.form.get("nace_1_label") + nace_2 = request.form.get("nace_2") + nace_2_label = request.form.get("nace_2_label") + nace_3 = request.form.get("nace_3") + nace_3_label = request.form.get("nace_3_label") + web_address = request.form.get("web_address") + business = { + "organisation_name": organisation_name, + "latitude": latitude, + "longitude": longitude, + "nace_1": nace_1, + "nace_1_label": nace_1_label, + "nace_2": nace_2, + "nace_2_label": nace_2_label, + "nace_3": nace_3, + "nace_3_label": nace_3_label, + "web_address": web_address, + } + mongo.db.organisations.insert_one(business) + # flash(" - Business Successfully Added - ") + return redirect(url_for("organisations.get_organisations")) + + return render_template("organisations/create_organisation.html") + + +@organisations.route('/organisations//edit', methods=['GET', 'POST']) +def edit_organisation(organisation_id): + ''' + Edit an organisation for admin user + ''' + if request.method == 'POST': + organisation_name = request.form.get("organisation_name") + latitude = request.form.get("latitude") + longitude = request.form.get("longitude") + nace_1 = request.form.get("nace_1") + nace_1_label = request.form.get("nace_1_label") + nace_2 = request.form.get("nace_2") + nace_2_label = request.form.get("nace_2_label") + nace_3 = request.form.get("nace_3") + nace_3_label = request.form.get("nace_3_label") + web_address = request.form.get("web_address") + edit_org = { + "organisation_name": organisation_name, + "latitude": latitude, + "longitude": longitude, + "nace_1": nace_1, + "nace_1_label": nace_1_label, + "nace_2": nace_2, + "nace_2_label": nace_2_label, + "nace_3": nace_3, + "nace_3_label": nace_3_label, + "web_address": web_address, + } + mongo.db.organisations.update_one({'_id': ObjectId(organisation_id)}, + {'$set': edit_org}) + return redirect(url_for('organisations.get_organisations')) + + organisation = mongo.db.organisations.find_one( + {'_id': ObjectId(organisation_id)}) + return render_template('organisations/edit_organisation.html', + organisation=organisation) + + +@organisations.route('/organisations//delete', methods=['GET', 'POST']) +def delete_organisation(organisation_id): + ''' + Delete an organisation for admin user + ''' + mongo.db.organisations.delete_one({'_id': ObjectId(organisation_id)}) + return redirect(url_for('organisations.get_organisations')) diff --git a/static/js/scripts.js b/app/static/js/scripts.js similarity index 100% rename from static/js/scripts.js rename to app/static/js/scripts.js diff --git a/app/templates/base.html b/app/templates/base.html index a5b16e5..31c6a56 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -7,23 +7,25 @@ - - - + + + {% block emailjs %} {% endblock %} - Business Analysis + {% block title %} + Business Analysis Project + {% endblock %}
+ {% include 'navbar.html' %}
-
+
{% with messages = get_flashed_messages() %} {% if messages %} @@ -41,14 +43,15 @@ {% endblock %}
- - - - +
+ + + + + + + + {% block scripts %} {% endblock %} diff --git a/app/templates/navbar.html b/app/templates/navbar.html new file mode 100644 index 0000000..a9a2ed0 --- /dev/null +++ b/app/templates/navbar.html @@ -0,0 +1,26 @@ + diff --git a/app/templates/organisations/create_organisation.html b/app/templates/organisations/create_organisation.html new file mode 100644 index 0000000..9b31973 --- /dev/null +++ b/app/templates/organisations/create_organisation.html @@ -0,0 +1,68 @@ +{% extends "base.html" %} + +{% block extra_title %} Add Organisation {% endblock %} +{% block extra_keywords %}, organisation, organisations, add, create{% endblock %} + +{% block metas %} + + + + + + + + + +{% endblock %} + +{% block content %} +
+

Create Organization

+
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + Cancel +
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/organisations/edit_organisation.html b/app/templates/organisations/edit_organisation.html new file mode 100644 index 0000000..ebb4915 --- /dev/null +++ b/app/templates/organisations/edit_organisation.html @@ -0,0 +1,72 @@ +{% extends "base.html" %} + +{% block extra_title %} Edit Organisation{% endblock %} +{% block extra_keywords %}, organisation, organisations, edit, update{% endblock %} + +{% block metas %} + + + + + + + + + +{% endblock %} + +{% block content %} +
+

Edit Organization

+
+
+ + +
+
+
+ + +
+
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + Cancel +
+
+{% endblock %} \ No newline at end of file diff --git a/app/templates/organisations/organisations_list.html b/app/templates/organisations/organisations_list.html new file mode 100644 index 0000000..0ae32a7 --- /dev/null +++ b/app/templates/organisations/organisations_list.html @@ -0,0 +1,59 @@ +{% extends "base.html" %} + +{% block extra_title %} Organisations List{% endblock %} +{% block extra_keywords %}, organisation, organisations, create{% endblock %} + +{% block metas %} + + + + + + + + + +{% endblock %} + +{% block content %} +

Organisations list

+ +{% if organisations %} + + + + + + + + + + + + + {% for organisation in organisations %} + + + + + + + + + {% endfor %} + +
#NameNACE codeNACE labelWeb addressActions
{{ loop.index }}{{ organisation.organisation_name }}{{ organisation.nace_3 }}{{ organisation.nace_3_label }}{{ organisation.web_address }} + + + Edit organisation + + + + Delete organisation + +
+{% else %} +

No organisations found.

+{% endif %} +Create new organisation +{% endblock %} \ No newline at end of file diff --git a/demo_data.json b/data/demo_data.json similarity index 100% rename from demo_data.json rename to data/demo_data.json diff --git a/env.py.sample b/env.py.sample new file mode 100644 index 0000000..21edec2 --- /dev/null +++ b/env.py.sample @@ -0,0 +1,9 @@ +import os + +os.environ.setdefault("DEBUG", "True") +os.environ.setdefault("SECRET_KEY", "asdasd") +os.environ.setdefault("IP", "localhost") +os.environ.setdefault("PORT", "8000") + +os.environ.setdefault("MONGO_DBNAME", "db") +os.environ.setdefault("MONGO_URI", "mongodb://localhost:27017/db") diff --git a/run.py b/run.py index 711e841..cb6cab5 100644 --- a/run.py +++ b/run.py @@ -1,9 +1,12 @@ import os +if os.path.exists("env.py"): + import env + from app import create_app -app = create_app() if __name__ == "__main__": - app.run(host=os.environ.get("IP"), - port=int(os.environ.get("PORT")), - debug=True) \ No newline at end of file + app = create_app() + app.run(host=os.environ.get("IP", "0.0.0.0"), + port=int(os.environ.get("PORT", "8000")), + debug=os.environ.get('DEBUG')) diff --git a/templates/create_organisation.html b/templates/create_organisation.html deleted file mode 100644 index bc4cd44..0000000 --- a/templates/create_organisation.html +++ /dev/null @@ -1,68 +0,0 @@ -{% extends "base.html" %} - -{% block extra_title %} Add Organisation{% endblock %} -{% block extra_keywords %}, organisation, organisations, add, create{% endblock %} - -{% block metas %} - - - - - - - - - -{% endblock %} - -{% block content %} -
-

Create Organization

-
-
- - -
-
-
- - -
-
- - -
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - Cancel -
-
-{% endblock %} \ No newline at end of file diff --git a/templates/edit_organisation.html b/templates/edit_organisation.html deleted file mode 100644 index de8dcd0..0000000 --- a/templates/edit_organisation.html +++ /dev/null @@ -1,72 +0,0 @@ -{% extends "base.html" %} - -{% block extra_title %} Edit Organisation{% endblock %} -{% block extra_keywords %}, organisation, organisations, edit, update{% endblock %} - -{% block metas %} - - - - - - - - - -{% endblock %} - -{% block content %} -
-

Edit Organization

-
-
- - -
-
-
- - -
-
- - -
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
- - Cancel -
-
-{% endblock %} \ No newline at end of file diff --git a/templates/organisations_list.html b/templates/organisations_list.html deleted file mode 100644 index c5bb1ac..0000000 --- a/templates/organisations_list.html +++ /dev/null @@ -1,59 +0,0 @@ -{% extends "base.html" %} - -{% block extra_title %} Organisations List{% endblock %} -{% block extra_keywords %}, organisation, organisations, create{% endblock %} - -{% block metas %} - - - - - - - - - -{% endblock %} - -{% block content %} -

Organisations list

- - {% if organisations %} - - - - - - - - - - - - - {% for organisation in organisations %} - - - - - - - - - {% endfor %} - -
#NameNACE codeNACE labelWeb addressActions
{{ loop.index }}{{ organisation.organisation_name }}{{ organisation.nace_3 }}{{ organisation.nace_3_label }}{{ organisation.web_address }} - - - Edit organisation - - - - Delete organisation - -
- {% else %} -

No organisations found.

- {% endif %} - Create new organisation -{% endblock %} \ No newline at end of file From a5ebc9debf9338bf332a9a7619d2018afaba9e01 Mon Sep 17 00:00:00 2001 From: Stefan Dworschak Date: Mon, 21 Mar 2022 20:59:58 +0000 Subject: [PATCH 2/8] Adding new meta tags back in --- app/templates/base.html | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/app/templates/base.html b/app/templates/base.html index 31c6a56..0197818 100644 --- a/app/templates/base.html +++ b/app/templates/base.html @@ -2,21 +2,26 @@ - - - - - - + + + + + + + + + + + + + + + - - {% block emailjs %} - {% endblock %} - - {% block title %} - Business Analysis Project - {% endblock %} + Business Analysis{% block title %}{% endblock %} + {% block metas %} + {% endblock %} From ad3308171de2b87307ccf57502d664657822ce0a Mon Sep 17 00:00:00 2001 From: Stefan Dworschak Date: Mon, 21 Mar 2022 21:09:23 +0000 Subject: [PATCH 3/8] Removing uneeded files --- app/__init__.py | 4 +--- app/app.py | 7 ------- app/main.py | 7 ------- 3 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 app/app.py delete mode 100644 app/main.py diff --git a/app/__init__.py b/app/__init__.py index b069494..bbb1197 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -25,12 +25,10 @@ def create_app(default_config=Config): from app.index import home from app.api_users import api_users from app.cluster_model import cluster_model - from app.main import main from app.organisations import organisations app.register_blueprint(home) app.register_blueprint(api_users) app.register_blueprint(cluster_model) - app.register_blueprint(main) app.register_blueprint(organisations) - return app \ No newline at end of file + return app diff --git a/app/app.py b/app/app.py deleted file mode 100644 index 2210871..0000000 --- a/app/app.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask import ( - Flask, flash, render_template, redirect, - request, session, url_for, Blueprint, current_app) - - -# Blueprint -main = Blueprint("main", __name__) diff --git a/app/main.py b/app/main.py deleted file mode 100644 index 2210871..0000000 --- a/app/main.py +++ /dev/null @@ -1,7 +0,0 @@ -from flask import ( - Flask, flash, render_template, redirect, - request, session, url_for, Blueprint, current_app) - - -# Blueprint -main = Blueprint("main", __name__) From 32791559ae642a9610ae39d5943e4ef08e6e1fe4 Mon Sep 17 00:00:00 2001 From: Stefan Dworschak Date: Mon, 21 Mar 2022 21:45:46 +0000 Subject: [PATCH 4/8] Renaming Blueprints for updated structure --- README.md | 53 +++++++++++++++++++ app/__init__.py | 12 ++--- app/{api_users.py => api.py} | 26 +++++---- app/{cluster_model.py => categories.py} | 12 ++--- app/home.py | 13 +++++ app/index.py | 15 ------ app/organisations.py | 10 ++-- .../list_organisations.html} | 22 ++++---- .../{ => categories}/clustering.html | 0 app/templates/{index.html => home/home.html} | 0 app/templates/navbar.html | 8 +-- .../organisations/edit_organisation.html | 2 +- ...ions_list.html => list_organisations.html} | 0 company_web_scraper.py | 31 ----------- 14 files changed, 109 insertions(+), 95 deletions(-) rename app/{api_users.py => api.py} (58%) rename app/{cluster_model.py => categories.py} (62%) create mode 100644 app/home.py delete mode 100644 app/index.py rename app/templates/{all_companies.html => api/list_organisations.html} (79%) rename app/templates/{ => categories}/clustering.html (100%) rename app/templates/{index.html => home/home.html} (100%) rename app/templates/organisations/{organisations_list.html => list_organisations.html} (100%) delete mode 100644 company_web_scraper.py diff --git a/README.md b/README.md index 9bf6c48..6aca7f7 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,59 @@ A Collaborative Open-Source Project where we are looking for a way to put region 1) Install the requirements (optionally create a new virtual environment ) 1) Start the app running `pyhton3 run.py` from the terminal +# Flask Blueprint + +New Blueprints only need to added for completely new functionality. +Currently we only have four blueprints, please add to these before creating a new one. + +1) Organisations - Everything to do with listing, updateing and deleting organisations +1) Categories - Everything to do with analysing, clustering and categorising organisations +1) API - Everthing to do with avaiable RESTful APIs +1) Home - A basic home app and any static views + +In case a new Blueprint needs to be created, follow the below steps: + +1) Add new file in the `app` directory giving it a meaningful and relevant name (e.g. categories) +2) Import `Blueprint` from flask and define your Blueprint + +``` +from flask import Blueprint + +categories = Blueprint("categories", __name__, template_folder='templates') +``` + +3) Register your Blueprint in the app directory's `__init__.py` file. + +``` +from app.categories import categories +app.register_blueprint(categories) +``` + +4) Create a new sub-folder in the app diretory's `templates` folder for your new Blueprint + +5) If your Blueprint needs to use mongodb, import mongo from the `app` directory's `__init__.py` file to reuse the PyMongo instance. + +``` +from app import mongo +``` + +6) Here is a full example: + +categories.py +``` +from flask import Blueprint, render_template + +from app import mongo + +categories = Blueprint("categories", __name__, template_folder='templates') + +@categories.route('/') +def view_categories(): + categories = mongo.db.categories.find() + return render_template('categories/list_categories.html', + categories=categories) +``` + # Challenge - The primary challenge is to query an existing company name dataset, find their website, extract the relevant data which can be queried by search. diff --git a/app/__init__.py b/app/__init__.py index bbb1197..6f7de1d 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -22,13 +22,13 @@ def create_app(default_config=Config): # Import Blueprints and register them so they can be used # For exemple I have created the index.py app and registered it as follow - from app.index import home - from app.api_users import api_users - from app.cluster_model import cluster_model + from app.home import home + from app.api import api + from app.categories import categories from app.organisations import organisations app.register_blueprint(home) - app.register_blueprint(api_users) - app.register_blueprint(cluster_model) - app.register_blueprint(organisations) + app.register_blueprint(api, url_prefix='/api') + app.register_blueprint(categories) + app.register_blueprint(organisations, url_prefix='/organisations') return app diff --git a/app/api_users.py b/app/api.py similarity index 58% rename from app/api_users.py rename to app/api.py index 40c2372..b757bb1 100644 --- a/app/api_users.py +++ b/app/api.py @@ -1,23 +1,21 @@ """ Views related to api_user. """ -from flask import ( - Flask, flash, render_template, redirect, - request, session, url_for, Blueprint, current_app) +from flask import Blueprint, render_template, request from app import mongo from app.functions.create_cat_from_nace import * # Blueprint -api_users = Blueprint("api_users", __name__, template_folder='templates') +api = Blueprint("api", __name__, template_folder='templates') -# collection -data_set_coll = mongo.db.SampleData -@api_users.route("/all_companies", methods=["GET"]) -def all_companies(): +@api.route("/organisations", methods=["GET"]) +def list_organisations(): # Get the data_set from db + # TODO: Rename this to something meaningful and use an actual collection + data_set_coll = mongo.db.SampleData data_set = list(data_set_coll.find()) # Get all labels @@ -36,15 +34,15 @@ def all_companies(): category_selected = request.args.get('category') if category_selected: selected_data = [] - # check if a company as label = category selected, - # and add the company data to the data_set returned to the template. + # check if a organisation as label = category selected, + # and add the organisation data to the data_set returned to the template. for data in data_set: - company_cat = [data["nace_1_label"].lower() + " " \ + organisation_cat = [data["nace_1_label"].lower() + " " \ + data["nace_2_label"].lower() + " " \ + data["nace_3_label"].lower()] - company_cat = company_cat[0].split() - if category_selected in company_cat: + organisation_cat = organisation_cat[0].split() + if category_selected in organisation_cat: selected_data.append(data) data_set = selected_data - return render_template("all_companies.html", + return render_template("api/list_organisations.html", data_set=data_set, categories=categories) \ No newline at end of file diff --git a/app/cluster_model.py b/app/categories.py similarity index 62% rename from app/cluster_model.py rename to app/categories.py index ebce432..bdda5d3 100644 --- a/app/cluster_model.py +++ b/app/categories.py @@ -2,20 +2,16 @@ View to extract keywork from data usin TextRank ''' -from flask import ( - Flask, render_template, redirect, - request, Blueprint, current_app) +from flask import Blueprint, render_template -from app import mongo from app.functions.text_rank import TextRank4Keyword from app.functions.company_web_scraper import getHTMLdocument # Blueprint -cluster_model = Blueprint("cluster_model", __name__, - template_folder='templates') +categories = Blueprint("categories", __name__, template_folder='templates') -@cluster_model.route("/clustering", methods=["GET"]) +@categories.route("/clustering", methods=["GET"]) def clustering(): '''Implementation of TextRank classe from Xu Liang''' # create document test from website url @@ -27,6 +23,6 @@ def clustering(): tr4w.analyze(text, candidate_pos = ['NOUN', 'PROPN'], window_size=4, lower=False) keywords_list = tr4w.get_keywords(10) - return render_template("clustering.html", keywords_list=keywords_list) + return render_template("categories/clustering.html", keywords_list=keywords_list) diff --git a/app/home.py b/app/home.py new file mode 100644 index 0000000..2e19481 --- /dev/null +++ b/app/home.py @@ -0,0 +1,13 @@ +""" +Views related to the presentation of the website, +home page +""" +from flask import Blueprint, render_template + + +home = Blueprint("home", __name__, template_folder='templates') + +@home.route("/") +def view_home(): + # Display home page + return render_template("home/home.html") \ No newline at end of file diff --git a/app/index.py b/app/index.py deleted file mode 100644 index 761eb65..0000000 --- a/app/index.py +++ /dev/null @@ -1,15 +0,0 @@ -""" -Views related to the presentation of the website, -home page -""" -from flask import ( - Flask, flash, render_template, redirect, - request, session, url_for, Blueprint, current_app) - - -home = Blueprint("home", __name__) - -@home.route("/") -def index(): - # Display home page - return render_template("index.html") \ No newline at end of file diff --git a/app/organisations.py b/app/organisations.py index 2152b32..84a1849 100644 --- a/app/organisations.py +++ b/app/organisations.py @@ -9,20 +9,20 @@ organisations = Blueprint("organisations", __name__, template_folder='templates') -@organisations.route('/organisations', methods=['GET', 'POST']) +@organisations.route('/', methods=['GET', 'POST']) def get_organisations(): ''' Display a list of all organisations in table format for admin user ''' organisations = mongo.db.organisations.find() - return render_template('organisations/organisations_list.html', + return render_template('organisations/list_organisations.html', organisations=organisations) # TODO: define user role permission for admin and user. When user submits # the form, will admin have to check the submission and approve before # it is added to the database? -@organisations.route("/organisations/add", methods=["GET", "POST"]) +@organisations.route("/add", methods=["GET", "POST"]) def create_organisation(): ''' Add an organisation for normal user and admin user @@ -57,7 +57,7 @@ def create_organisation(): return render_template("organisations/create_organisation.html") -@organisations.route('/organisations//edit', methods=['GET', 'POST']) +@organisations.route('//edit', methods=['GET', 'POST']) def edit_organisation(organisation_id): ''' Edit an organisation for admin user @@ -95,7 +95,7 @@ def edit_organisation(organisation_id): organisation=organisation) -@organisations.route('/organisations//delete', methods=['GET', 'POST']) +@organisations.route('//delete', methods=['GET', 'POST']) def delete_organisation(organisation_id): ''' Delete an organisation for admin user diff --git a/app/templates/all_companies.html b/app/templates/api/list_organisations.html similarity index 79% rename from app/templates/all_companies.html rename to app/templates/api/list_organisations.html index e6ca0d9..084d9fd 100644 --- a/app/templates/all_companies.html +++ b/app/templates/api/list_organisations.html @@ -5,7 +5,7 @@

- All Companies + All Organisations ({{ data_set|length }})

@@ -29,7 +29,7 @@