diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..2608112 Binary files /dev/null and b/.DS_Store differ diff --git a/backend/.env.sample b/.env.sample similarity index 100% rename from backend/.env.sample rename to .env.sample diff --git a/.gitignore b/.gitignore index f851903..b5e8132 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ -*.txt .env -__pycache__/ \ No newline at end of file +__pycache__/ +backend/staticfiles/ +.venv/ +venv/ +.DS_Store diff --git a/Procfile b/Procfile new file mode 100644 index 0000000..fcd857b --- /dev/null +++ b/Procfile @@ -0,0 +1,2 @@ +release: python manage.py migrate +web: gunicorn backend.wsgi --workers=3 --threads=6 diff --git a/backend/aboutus/__init__.py b/aboutus/__init__.py similarity index 100% rename from backend/aboutus/__init__.py rename to aboutus/__init__.py diff --git a/backend/aboutus/admin.py b/aboutus/admin.py similarity index 100% rename from backend/aboutus/admin.py rename to aboutus/admin.py diff --git a/backend/aboutus/apps.py b/aboutus/apps.py similarity index 100% rename from backend/aboutus/apps.py rename to aboutus/apps.py diff --git a/backend/aboutus/migrations/__init__.py b/aboutus/migrations/__init__.py similarity index 100% rename from backend/aboutus/migrations/__init__.py rename to aboutus/migrations/__init__.py diff --git a/backend/aboutus/models.py b/aboutus/models.py similarity index 100% rename from backend/aboutus/models.py rename to aboutus/models.py diff --git a/backend/aboutus/tests.py b/aboutus/tests.py similarity index 100% rename from backend/aboutus/tests.py rename to aboutus/tests.py diff --git a/backend/aboutus/urls.py b/aboutus/urls.py similarity index 70% rename from backend/aboutus/urls.py rename to aboutus/urls.py index 47a66bc..62d74bd 100644 --- a/backend/aboutus/urls.py +++ b/aboutus/urls.py @@ -1,10 +1,10 @@ -from django.urls import path +from django.urls import path, include from aboutus import views urlpatterns = [ path('aboutus/', views.aboutus), path('history/', views.history), path('governance/', views.governance), - path('ourteam/', views.ourteam), + path('ourteam/', include('ourteam.urls')), path('president/', views.president), ] diff --git a/backend/aboutus/views.py b/aboutus/views.py similarity index 88% rename from backend/aboutus/views.py rename to aboutus/views.py index 2ca3a76..c6c0928 100644 --- a/backend/aboutus/views.py +++ b/aboutus/views.py @@ -35,11 +35,11 @@ def governance(request): data = get_parsed_data(GOVERNANCE_URL) return Response(data, status=status.HTTP_200_OK) -@api_view(['Get']) -def ourteam(request): - OUR_TEAM_URL = 'd64ee576792d48a4a3bbca2153795348' - data = get_parsed_data(OUR_TEAM_URL) - return Response(data, status=status.HTTP_200_OK) +# @api_view(['Get']) +# def ourteam(request): +# OUR_TEAM_URL = 'd64ee576792d48a4a3bbca2153795348' +# data = get_parsed_data(OUR_TEAM_URL) +# return Response(data, status=status.HTTP_200_OK) @api_view(['Get']) def president(request): diff --git a/backend/.DS_Store b/backend/.DS_Store new file mode 100644 index 0000000..1d1cce9 Binary files /dev/null and b/backend/.DS_Store differ diff --git a/backend/backend/__init__.py b/backend/__init__.py similarity index 100% rename from backend/backend/__init__.py rename to backend/__init__.py diff --git a/backend/backend/asgi.py b/backend/asgi.py similarity index 100% rename from backend/backend/asgi.py rename to backend/asgi.py diff --git a/backend/backend/__pycache__/__init__.cpython-39.pyc b/backend/backend/__pycache__/__init__.cpython-39.pyc deleted file mode 100644 index 2bbbafc..0000000 Binary files a/backend/backend/__pycache__/__init__.cpython-39.pyc and /dev/null differ diff --git a/backend/backend/__pycache__/settings.cpython-39.pyc b/backend/backend/__pycache__/settings.cpython-39.pyc deleted file mode 100644 index e1cd1d6..0000000 Binary files a/backend/backend/__pycache__/settings.cpython-39.pyc and /dev/null differ diff --git a/backend/backend/__pycache__/urls.cpython-39.pyc b/backend/backend/__pycache__/urls.cpython-39.pyc deleted file mode 100644 index cc5b8fd..0000000 Binary files a/backend/backend/__pycache__/urls.cpython-39.pyc and /dev/null differ diff --git a/backend/backend/__pycache__/wsgi.cpython-39.pyc b/backend/backend/__pycache__/wsgi.cpython-39.pyc deleted file mode 100644 index fa76693..0000000 Binary files a/backend/backend/__pycache__/wsgi.cpython-39.pyc and /dev/null differ diff --git a/backend/backend/settings.py b/backend/settings.py similarity index 73% rename from backend/backend/settings.py rename to backend/settings.py index d0c0d03..b4ebfc3 100644 --- a/backend/backend/settings.py +++ b/backend/settings.py @@ -15,7 +15,7 @@ from dotenv import load_dotenv # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent - +PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ @@ -23,16 +23,30 @@ #Load Secret Key load_dotenv() +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles') +STATIC_URL = '/static/' + +# Extra places for collectstatic to find static files. +STATICFILES_DIRS = [ + os.path.join(PROJECT_ROOT, 'static'), +] + +# Simplified static file serving. +# https://warehouse.python.org/project/whitenoise/ +STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' # SECURITY WARNING: keep the secret key used in production secret! SECRET_KEY = os.getenv("DJANGOSECRETKEY") # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = True if os.getenv("DEBUG").lower() == 'true' else False ALLOWED_HOSTS = ['*'] -CORS_ALLOWED_ORIGINS = ["http://localhost:3000", "http://127.0.0.1:3000"] +CORS_ALLOWED_ORIGINS = ["http://localhost:3000", "http://127.0.0.1:3000", "https://kaleidoscopic-druid-8d4af7.netlify.app", "https://nussu.org.sg"] # Application definition @@ -42,9 +56,13 @@ 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', - 'django.contrib.staticfiles', 'rest_framework', 'corsheaders', + # Disable Django's own staticfiles handling in favour of WhiteNoise, for + # greater consistency between gunicorn and `./manage.py runserver`. See: + # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development + 'whitenoise.runserver_nostatic', + 'django.contrib.staticfiles', ] MIDDLEWARE = [ @@ -130,3 +148,17 @@ # https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' + + + + + + +# settings.py + +EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' +EMAIL_HOST = 'smtp.gmail.com' +EMAIL_PORT = 587 +EMAIL_USE_TLS = True +EMAIL_HOST_USER = os.getenv("EMAIL_HOST_USER") +EMAIL_HOST_PASSWORD = os.getenv("EMAIL_HOST_PASSWORD") # Note: Store credentials securely \ No newline at end of file diff --git a/backend/backend/urls.py b/backend/urls.py similarity index 100% rename from backend/backend/urls.py rename to backend/urls.py diff --git a/backend/backend/wsgi.py b/backend/wsgi.py similarity index 100% rename from backend/backend/wsgi.py rename to backend/wsgi.py diff --git a/backend/contact/__init__.py b/contact/__init__.py similarity index 100% rename from backend/contact/__init__.py rename to contact/__init__.py diff --git a/backend/contact/admin.py b/contact/admin.py similarity index 100% rename from backend/contact/admin.py rename to contact/admin.py diff --git a/backend/contact/apps.py b/contact/apps.py similarity index 100% rename from backend/contact/apps.py rename to contact/apps.py diff --git a/backend/contact/migrations/__init__.py b/contact/migrations/__init__.py similarity index 100% rename from backend/contact/migrations/__init__.py rename to contact/migrations/__init__.py diff --git a/backend/contact/models.py b/contact/models.py similarity index 100% rename from backend/contact/models.py rename to contact/models.py diff --git a/backend/contact/tests.py b/contact/tests.py similarity index 100% rename from backend/contact/tests.py rename to contact/tests.py diff --git a/backend/contact/urls.py b/contact/urls.py similarity index 57% rename from backend/contact/urls.py rename to contact/urls.py index ae7eb0c..76affe8 100644 --- a/backend/contact/urls.py +++ b/contact/urls.py @@ -3,4 +3,5 @@ urlpatterns = [ path('', views.contact), + path('submit_feedback/', views.submit_feedback, name='submit_feedback'), ] diff --git a/contact/views.py b/contact/views.py new file mode 100644 index 0000000..4c2ee49 --- /dev/null +++ b/contact/views.py @@ -0,0 +1,85 @@ +from rest_framework.decorators import api_view +from rest_framework.response import Response +from rest_framework import status +from django.core.mail import send_mail +from django.core.exceptions import ValidationError +from django.core.validators import EmailValidator +from dotenv import load_dotenv +from pathlib import Path +import os +import requests +from notionConnection.parser import parse + + +dotenv_path = Path('backend/.env') +load_dotenv(dotenv_path) +token = os.getenv('NOTION_API_KEY') +version = '2021-08-16' + +NOTION_PAGE_URL = 'https://api.notion.com/v1/blocks/{blockid}/children' +NOTION_HEADER = {'Notion-Version': version, 'Authorization': token} + + + +@api_view(['POST']) +def submit_feedback(request): + # Extract data from the request + sheet1 = request.data.get('sheet1', {}) + full_name = sheet1.get('fullName') + email = sheet1.get('email') + subject = sheet1.get('subject') + question = sheet1.get('question') + + # Validate the input + if not (full_name and email and subject and question): + return Response({"error": "Missing required fields"}, status=status.HTTP_400_BAD_REQUEST) + + + # Validate email format + email_validator = EmailValidator() + try: + email_validator(email) + except ValidationError: + return Response({"error": "Invalid email address"}, status=status.HTTP_400_BAD_REQUEST) + + # Email configuration + SENDER_EMAIL = os.getenv('EMAIL_HOST_USER') + RECEIVER_EMAIL = SENDER_EMAIL # Feedback goes to the company email + + # Send the feedback email + try: + send_mail( + subject=f"Feedback: {subject} from {full_name}", + message=f"Name: {full_name}\nEmail: {email}\nSubject: {subject}\nQuestion: {question}", + from_email=SENDER_EMAIL, + recipient_list=["emmaxu2005@gmail.com", "e1300538@u.nus.edu", "xusiyi2005@gmail.com"], + ) + except Exception as e: + return Response({"error": "Failed to send feedback email", "details": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + # Send auto-reply to the user + try: + send_mail( + subject='Auto Reply From NUS Student Union', + message='Thank you for your message. We will get back to you soon.', + from_email=SENDER_EMAIL, + recipient_list=[email], + ) + + except Exception as e: + return Response({"error": "Failed to send auto reply", "details": str(e)}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + + return Response({"success": "Feedback submitted successfully"}, status=status.HTTP_200_OK) + + +@api_view(['Get']) +def contact(request): + CONTACT_URL = '80fc40185db84c88bd30824a10add0de' + data = get_parsed_data(CONTACT_URL) + return Response(data, status=status.HTTP_200_OK) + +def get_parsed_data(id): + url = NOTION_PAGE_URL.format(blockid=id) + response = requests.get(url, headers=NOTION_HEADER) + data = response.json() + return parse(data) diff --git a/backend/db.sqlite3 b/db.sqlite3 similarity index 100% rename from backend/db.sqlite3 rename to db.sqlite3 diff --git a/backend/events/__init__.py b/events/__init__.py similarity index 100% rename from backend/events/__init__.py rename to events/__init__.py diff --git a/backend/events/admin.py b/events/admin.py similarity index 100% rename from backend/events/admin.py rename to events/admin.py diff --git a/backend/events/apps.py b/events/apps.py similarity index 100% rename from backend/events/apps.py rename to events/apps.py diff --git a/backend/events/migrations/__init__.py b/events/migrations/__init__.py similarity index 100% rename from backend/events/migrations/__init__.py rename to events/migrations/__init__.py diff --git a/backend/events/models.py b/events/models.py similarity index 100% rename from backend/events/models.py rename to events/models.py diff --git a/backend/events/tests.py b/events/tests.py similarity index 100% rename from backend/events/tests.py rename to events/tests.py diff --git a/backend/events/urls.py b/events/urls.py similarity index 100% rename from backend/events/urls.py rename to events/urls.py diff --git a/backend/events/views.py b/events/views.py similarity index 100% rename from backend/events/views.py rename to events/views.py diff --git a/backend/freshmen/__init__.py b/freshmen/__init__.py similarity index 100% rename from backend/freshmen/__init__.py rename to freshmen/__init__.py diff --git a/backend/freshmen/admin.py b/freshmen/admin.py similarity index 100% rename from backend/freshmen/admin.py rename to freshmen/admin.py diff --git a/backend/freshmen/apps.py b/freshmen/apps.py similarity index 100% rename from backend/freshmen/apps.py rename to freshmen/apps.py diff --git a/backend/freshmen/migrations/__init__.py b/freshmen/migrations/__init__.py similarity index 100% rename from backend/freshmen/migrations/__init__.py rename to freshmen/migrations/__init__.py diff --git a/backend/freshmen/models.py b/freshmen/models.py similarity index 100% rename from backend/freshmen/models.py rename to freshmen/models.py diff --git a/backend/freshmen/tests.py b/freshmen/tests.py similarity index 100% rename from backend/freshmen/tests.py rename to freshmen/tests.py diff --git a/backend/freshmen/urls.py b/freshmen/urls.py similarity index 100% rename from backend/freshmen/urls.py rename to freshmen/urls.py diff --git a/backend/freshmen/views.py b/freshmen/views.py similarity index 100% rename from backend/freshmen/views.py rename to freshmen/views.py diff --git a/backend/home/__init__.py b/home/__init__.py similarity index 100% rename from backend/home/__init__.py rename to home/__init__.py diff --git a/backend/home/admin.py b/home/admin.py similarity index 100% rename from backend/home/admin.py rename to home/admin.py diff --git a/backend/home/apps.py b/home/apps.py similarity index 100% rename from backend/home/apps.py rename to home/apps.py diff --git a/backend/home/migrations/__init__.py b/home/migrations/__init__.py similarity index 100% rename from backend/home/migrations/__init__.py rename to home/migrations/__init__.py diff --git a/backend/home/models.py b/home/models.py similarity index 100% rename from backend/home/models.py rename to home/models.py diff --git a/backend/home/tests.py b/home/tests.py similarity index 100% rename from backend/home/tests.py rename to home/tests.py diff --git a/backend/home/urls.py b/home/urls.py similarity index 71% rename from backend/home/urls.py rename to home/urls.py index 353b2c8..db5f169 100644 --- a/backend/home/urls.py +++ b/home/urls.py @@ -2,5 +2,5 @@ from home import views urlpatterns = [ - path('home/', views.home), + path('', views.home), ] diff --git a/backend/home/views.py b/home/views.py similarity index 100% rename from backend/home/views.py rename to home/views.py diff --git a/backend/joinus/__init__.py b/joinus/__init__.py similarity index 100% rename from backend/joinus/__init__.py rename to joinus/__init__.py diff --git a/backend/joinus/admin.py b/joinus/admin.py similarity index 100% rename from backend/joinus/admin.py rename to joinus/admin.py diff --git a/backend/joinus/apps.py b/joinus/apps.py similarity index 100% rename from backend/joinus/apps.py rename to joinus/apps.py diff --git a/backend/joinus/migrations/__init__.py b/joinus/migrations/__init__.py similarity index 100% rename from backend/joinus/migrations/__init__.py rename to joinus/migrations/__init__.py diff --git a/backend/joinus/models.py b/joinus/models.py similarity index 100% rename from backend/joinus/models.py rename to joinus/models.py diff --git a/backend/joinus/tests.py b/joinus/tests.py similarity index 100% rename from backend/joinus/tests.py rename to joinus/tests.py diff --git a/backend/joinus/urls.py b/joinus/urls.py similarity index 100% rename from backend/joinus/urls.py rename to joinus/urls.py diff --git a/backend/joinus/views.py b/joinus/views.py similarity index 100% rename from backend/joinus/views.py rename to joinus/views.py diff --git a/backend/manage.py b/manage.py similarity index 100% rename from backend/manage.py rename to manage.py diff --git a/backend/notionConnection/__init__.py b/notionConnection/__init__.py similarity index 100% rename from backend/notionConnection/__init__.py rename to notionConnection/__init__.py diff --git a/backend/notionConnection/admin.py b/notionConnection/admin.py similarity index 100% rename from backend/notionConnection/admin.py rename to notionConnection/admin.py diff --git a/backend/notionConnection/apps.py b/notionConnection/apps.py similarity index 100% rename from backend/notionConnection/apps.py rename to notionConnection/apps.py diff --git a/backend/notionConnection/migrations/__init__.py b/notionConnection/migrations/__init__.py similarity index 100% rename from backend/notionConnection/migrations/__init__.py rename to notionConnection/migrations/__init__.py diff --git a/backend/notionConnection/models.py b/notionConnection/models.py similarity index 100% rename from backend/notionConnection/models.py rename to notionConnection/models.py diff --git a/backend/notionConnection/parser.py b/notionConnection/parser.py similarity index 76% rename from backend/notionConnection/parser.py rename to notionConnection/parser.py index 44af257..4fe71f2 100644 --- a/backend/notionConnection/parser.py +++ b/notionConnection/parser.py @@ -5,12 +5,15 @@ dotenv_path = Path('backend/.env') load_dotenv(dotenv_path) -token = os.getenv('token') -version = os.getenv('version') +token = os.getenv('NOTION_API_KEY') +version = os.getenv('VERSION') def parse(data): - if (data["object"] == "list"): - return parse_list(data["results"]) + if isinstance(data, list): + return parse_list(data) + + if isinstance(data, dict) and data.get("object") == "list": + return parse_list(data.get("results", [])) def parse_list(data): list = [] @@ -40,9 +43,18 @@ def parse_numbered_list_item(data): list = [] result["type"] = "numbered_list_item" for i in data["numbered_list_item"]["text"]: - if (i["plain_text"] != ""): + if i["plain_text"]: list.append(parse_text(i)) - result["type"] = "numbered_list_item" + + # Handle children recursively (similar to bulleted list items) + if data.get("has_children"): + url = 'https://api.notion.com/v1/blocks/' + data["id"] + '/children' + headers = {'Notion-Version': version, 'Authorization': f'Bearer {token}'} + response = requests.get(url, headers=headers) + response_data = response.json() + + result["children"] = parse(response_data) + result["content"] = list return result @@ -50,17 +62,13 @@ def parse_heading(data): result = dict() result["type"] = "heading" - # quick and dirty fix for notion's buggy API being returned for events page textArray = data[data["type"]]["text"] for i in range(len(textArray)): if textArray[i]["plain_text"] != "": result["content"] = textArray[i]["plain_text"] break - - # result["content"] = data[data["type"]]["text"][0]["plain_text"] return result - def parse_paragraph(data): list = [] for i in data["paragraph"]["text"]: @@ -80,13 +88,13 @@ def parse_text(data): for attribute in data["annotations"]: if (attribute != "color" and data["annotations"][attribute] == True): special_attribute[attribute] = True - elif (attribute == "color" and data["annotations"][attribute] != "default"): special_attribute[attribute] = data["annotations"][attribute] - if (data["text"]["link"]): - special_attribute["link"] = data["text"]["link"]["url"] + if (data["text"].get("link")): + special_attribute["link"] = data["text"]["link"]["url"] + result["annotations"] = special_attribute return result def parse_quote(data): @@ -106,24 +114,29 @@ def parse_bullet_list(data): list = [] for i in data["bulleted_list_item"]["text"]: bullet_item = parse_text(i) + + # Handle children recursively if data["has_children"]: url = 'https://api.notion.com/v1/blocks/' + data["id"] + '/children' - headers = {'Notion-Version': version, 'Authorization': token} + headers = {'Notion-Version': version, 'Authorization': f'Bearer {token}'} response = requests.get(url, headers=headers) - responseData = response.json() - bullet_item["children"] = parse(responseData) - + response_data = response.json() + + # Recursively parse the children + bullet_item["children"] = parse(response_data) + list.append(bullet_item) + result["content"] = list return result def parse_table(data): result = dict() url = 'https://api.notion.com/v1/blocks/' + data["id"] + '/children' - headers = {'Notion-Version': version, 'Authorization': token} + headers = {'Notion-Version': version, 'Authorization': f'Bearer {token}'} response = requests.get(url, headers=headers) table = response.json() - #Assume that table does not have children inside the block + list = [] if "results" in table: for i in table["results"]: @@ -145,10 +158,8 @@ def parse_file(data): result = dict() result["type"] = "file" - # can be external of file type type = data["file"]["type"] - - if (type == "external"): + if type == "external": result["url"] = data["file"]["external"]["url"] else: result["url"] = data["file"]["file"]["url"] diff --git a/backend/notionConnection/tests.py b/notionConnection/tests.py similarity index 100% rename from backend/notionConnection/tests.py rename to notionConnection/tests.py diff --git a/backend/notionConnection/utils.py b/notionConnection/utils.py similarity index 100% rename from backend/notionConnection/utils.py rename to notionConnection/utils.py diff --git a/backend/notionConnection/views.py b/notionConnection/views.py similarity index 100% rename from backend/notionConnection/views.py rename to notionConnection/views.py diff --git a/backend/services/__init__.py b/ourteam/__init__.py similarity index 100% rename from backend/services/__init__.py rename to ourteam/__init__.py diff --git a/backend/services/admin.py b/ourteam/admin.py similarity index 100% rename from backend/services/admin.py rename to ourteam/admin.py diff --git a/ourteam/apps.py b/ourteam/apps.py new file mode 100644 index 0000000..3d954d8 --- /dev/null +++ b/ourteam/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class OurteamConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'ourteam' diff --git a/backend/services/migrations/__init__.py b/ourteam/migrations/__init__.py similarity index 100% rename from backend/services/migrations/__init__.py rename to ourteam/migrations/__init__.py diff --git a/backend/services/models.py b/ourteam/models.py similarity index 100% rename from backend/services/models.py rename to ourteam/models.py diff --git a/backend/services/tests.py b/ourteam/tests.py similarity index 100% rename from backend/services/tests.py rename to ourteam/tests.py diff --git a/ourteam/urls.py b/ourteam/urls.py new file mode 100644 index 0000000..8c67964 --- /dev/null +++ b/ourteam/urls.py @@ -0,0 +1,12 @@ +from django.urls import path +from ourteam import views + +urlpatterns = [ + path('presidential/', views.presidential), + path('relations/', views.relations), + path('secretariat/', views.secretariat), + path('finance/', views.finance), + path('communications/', views.communications), + path('studentlife/', views.studentlife), + path('studentwelfare/', views.studentwelfare), +] diff --git a/ourteam/views.py b/ourteam/views.py new file mode 100644 index 0000000..c9f4d5d --- /dev/null +++ b/ourteam/views.py @@ -0,0 +1,66 @@ +from rest_framework.decorators import api_view +from dotenv import load_dotenv +from rest_framework.response import Response +from rest_framework import status +from pathlib import Path + +import os +import requests +from notionConnection.parser import parse + + +dotenv_path = Path('backend/.env') +load_dotenv(dotenv_path) +token = os.getenv('NOTION_API_KEY') +version = '2021-08-16' + +NOTION_PAGE_URL = 'https://api.notion.com/v1/blocks/{blockid}/children' +NOTION_HEADER = {'Notion-Version': version, 'Authorization': token} + +@api_view(['Get']) +def presidential(request): + PRESIDENTIAL_URL = '775fe303392d498293f9102feb96ac35' + data = get_parsed_data(PRESIDENTIAL_URL) + return Response(data, status=status.HTTP_200_OK) + +@api_view(['Get']) +def relations(request): + RELATIONS_URL = 'dc34de1f9d7f405e982517689b429bce' + data = get_parsed_data(RELATIONS_URL) + return Response(data, status=status.HTTP_200_OK) + +@api_view(['Get']) +def secretariat(request): + SECRETARIAT_URL = '8871dfe66ad2448c8e7740059a4f83cc' + data = get_parsed_data(SECRETARIAT_URL) + return Response(data, status=status.HTTP_200_OK) + +@api_view(['Get']) +def finance(request): + FINANCE_URL = 'b840c269648e4d5c8d1934e7251d4595' + data = get_parsed_data(FINANCE_URL) + return Response(data, status=status.HTTP_200_OK) + +@api_view(['Get']) +def communications(request): + COMMUNICATIONS_URL = '70e6bf12c8154340bf06e0f888618866' + data = get_parsed_data(COMMUNICATIONS_URL) + return Response(data, status=status.HTTP_200_OK) + +@api_view(['Get']) +def studentlife(request): + STUDENT_LIFE_URL = 'f48aefac261446f8918d94816a0b7327' + data = get_parsed_data(STUDENT_LIFE_URL) + return Response(data, status=status.HTTP_200_OK) + +@api_view(['Get']) +def studentwelfare(request): + STUDENT_WELFARE_URL = '5e75012fc8da47cd9a5948108a27e735' + data = get_parsed_data(STUDENT_WELFARE_URL) + return Response(data, status=status.HTTP_200_OK) + +def get_parsed_data(id): + url = NOTION_PAGE_URL.format(blockid=id) + response = requests.get(url, headers=NOTION_HEADER) + data = response.json() + return parse(data) diff --git a/publicity/__init__.py b/publicity/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/publicity/admin.py b/publicity/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/publicity/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/publicity/apps.py b/publicity/apps.py new file mode 100644 index 0000000..572d129 --- /dev/null +++ b/publicity/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class OurteamConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'publicity' diff --git a/publicity/migrations/__init__.py b/publicity/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/publicity/models.py b/publicity/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/publicity/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/publicity/tests.py b/publicity/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/publicity/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/publicity/urls.py b/publicity/urls.py new file mode 100644 index 0000000..992a323 --- /dev/null +++ b/publicity/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from publicity import views + +urlpatterns = [ + path('page-1/', views.pageOne), + path('page-2/', views.pageTwo), +] diff --git a/backend/contact/views.py b/publicity/views.py similarity index 71% rename from backend/contact/views.py rename to publicity/views.py index 69addbb..dc5d14a 100644 --- a/backend/contact/views.py +++ b/publicity/views.py @@ -18,9 +18,15 @@ NOTION_HEADER = {'Notion-Version': version, 'Authorization': token} @api_view(['Get']) -def contact(request): - CONTACT_URL = '80fc40185db84c88bd30824a10add0de' - data = get_parsed_data(CONTACT_URL) +def pageOne(request): + PAGE_ONE_URL = 'a439ca165b8f466cbbe6235e4614a5a0' + data = get_parsed_data(PAGE_ONE_URL) + return Response(data, status=status.HTTP_200_OK) + +@api_view(['Get']) +def pageTwo(request): + PAGE_TWO_URL = '988df5f0e0c04496966c0d318e3a2a87' + data = get_parsed_data(PAGE_TWO_URL) return Response(data, status=status.HTTP_200_OK) def get_parsed_data(id): diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..a03e8d6 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,43 @@ +asgiref==3.7.2 +beautifulsoup4==4.12.2 +bs4==0.0.1 +certifi==2023.7.22 +charset-normalizer==3.3.1 +contourpy==1.2.0 +countryinfo==0.1.2 +cycler==0.12.1 +distlib==0.3.7 +Django==4.2.6 +django-cors-headers==4.2.0 +djangorestframework==3.14.0 +dnspython==2.4.2 +filelock==3.12.4 +fonttools==4.44.0 +gevent==23.9.1 +greenlet==3.0.1 +idna==3.4 +kiwisolver==1.4.5 +matplotlib==3.8.1 +numpy==1.26.1 +packaging==23.2 +pandas==2.1.2 +Pillow==10.1.0 +platformdirs==3.11.0 +pymongo==4.5.0 +pyparsing==3.1.1 +python-dateutil==2.8.2 +python-dotenv==1.0.0 +pytz==2023.3 +requests==2.31.0 +six==1.16.0 +soupsieve==2.5 +sqlparse==0.4.4 +tzdata==2023.3 +urllib3==2.0.7 +virtualenv==20.24.5 +websocket==0.2.1 +websocket-client==1.7.0 +zope.event==5.0 +zope.interface==6.1 +whitenoise==6.6.0 +gunicorn==21.2.0 diff --git a/runtime.txt b/runtime.txt new file mode 100644 index 0000000..19c64f2 --- /dev/null +++ b/runtime.txt @@ -0,0 +1 @@ +python-3.10.9 diff --git a/services/__init__.py b/services/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/services/admin.py b/services/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/services/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/backend/services/apps.py b/services/apps.py similarity index 100% rename from backend/services/apps.py rename to services/apps.py diff --git a/services/migrations/__init__.py b/services/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/services/models.py b/services/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/services/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/services/tests.py b/services/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/services/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/services/urls.py b/services/urls.py similarity index 74% rename from backend/services/urls.py rename to services/urls.py index 872b832..c4c4b53 100644 --- a/backend/services/urls.py +++ b/services/urls.py @@ -1,4 +1,4 @@ -from django.urls import path +from django.urls import path, include from services import views urlpatterns = [ @@ -7,5 +7,5 @@ path('resiliencefund/', views.resilienceFund), path('logisticsrental/', views.logisticsRental), path('zoomLicense/', views.zoomLicense), - path('publicitymanagement/', views.publicityManagement), + path('publicitymanagement/', include('publicity.urls')), ] \ No newline at end of file diff --git a/backend/services/views.py b/services/views.py similarity index 88% rename from backend/services/views.py rename to services/views.py index 09b2114..7c6f43c 100644 --- a/backend/services/views.py +++ b/services/views.py @@ -47,11 +47,11 @@ def zoomLicense(request): data = get_parsed_data(ZOOM_LICENSE_URL) return Response(data, status=status.HTTP_200_OK) -@api_view(['Get']) -def publicityManagement(request): - PUBLICITY_MANAGEMENT_URL = '270cba9c9f9b4fb79660e525039acaa8' - data = get_parsed_data(PUBLICITY_MANAGEMENT_URL) - return Response(data, status=status.HTTP_200_OK) +# @api_view(['Get']) +# def publicityManagement(request): +# PUBLICITY_MANAGEMENT_URL = '270cba9c9f9b4fb79660e525039acaa8' +# data = get_parsed_data(PUBLICITY_MANAGEMENT_URL) +# return Response(data, status=status.HTTP_200_OK) def get_parsed_data(id): url = NOTION_PAGE_URL.format(blockid=id)