From 736b9760d1360d0be460c125a008db0eb0d170ea Mon Sep 17 00:00:00 2001 From: Hoponga Date: Fri, 1 Dec 2023 16:27:48 -0800 Subject: [PATCH] added page for dynamically changing sponsors at /indrel_admin --- hknweb/static/img/sponsors/Amazon.png | Bin 0 -> 4216 bytes .../Citadel.png} | Bin hknweb/static/img/sponsors/Microsoft.png | Bin 0 -> 763 bytes hknweb/static/img/sponsors/metadata | 3 + hknweb/static/img/sponsors/metadata2 | 2 + hknweb/templates/indrel.html | 12 ++- hknweb/templates/indrel_admin.html | 101 ++++++++++++++++++ hknweb/urls.py | 3 +- hknweb/views/indrel.py | 25 ++++- hknweb/views/indrel_admin.py | 70 ++++++++++++ 10 files changed, 208 insertions(+), 8 deletions(-) create mode 100644 hknweb/static/img/sponsors/Amazon.png rename hknweb/static/img/{indrel_sponsors_citadel_logo.png => sponsors/Citadel.png} (100%) create mode 100644 hknweb/static/img/sponsors/Microsoft.png create mode 100644 hknweb/static/img/sponsors/metadata create mode 100644 hknweb/static/img/sponsors/metadata2 create mode 100644 hknweb/templates/indrel_admin.html create mode 100644 hknweb/views/indrel_admin.py diff --git a/hknweb/static/img/sponsors/Amazon.png b/hknweb/static/img/sponsors/Amazon.png new file mode 100644 index 0000000000000000000000000000000000000000..ee7d4eaf6254eaba722f1a5ce5612f4bf9007246 GIT binary patch literal 4216 zcmbuDXEYn&+y7IuR%z`hL91r$y<^mj5vr(Nqh^tyB&k(JsZlDZv_?wpQIuL$DoSev zC0eR##EMOf^7#G#&&%hP~yX48g_@Z~)*M;y-a|)*JNb zLUi@DwMWByCB%w7I$wjiJWd2|F;2a9o{CK>o|+j*7P!TgyLtK=orA?<4L>=rVr$?0qnNMD zE1bMK->oGgj`Ec$7L1Iy1+~syA>DIg^DtT9vlfojr^3>-B}GYQ-4Fh6(rsV(**>Pq z_Pw5=pG%p*9f?55ox!udAJIu^rF^WLV?_!=pVt(fJCU!nqmMo}C(C`!hy~hJTja@m z&-*92v`0dHYFtXC@)T^UpXH2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%G{;9l&AK_?HMS2wJ~SSiHn{o=wUtGK^?|1vUa{uu0;=FM2Y3DVNLat@eE5SBzELkfz zh~F*%ctcA7Jx#}X&-Y$3luVmlzj5!C%$4+p^2~#!7-P(_|7+gFaiGnsEghmuu6jLW z<0M3ztQ!K!G}*{AsounrS(WDl-Wk0XuoE*2GE$A50nEQ7gbUK|*r_=e*_yZ)jHXPGvPYeJ6002ovPDHLkV1m!mhgSdq literal 0 HcmV?d00001 diff --git a/hknweb/static/img/sponsors/metadata b/hknweb/static/img/sponsors/metadata new file mode 100644 index 00000000..a037be0f --- /dev/null +++ b/hknweb/static/img/sponsors/metadata @@ -0,0 +1,3 @@ +Citadel https://citadel.com Citadel.png +Google https://google.com Google.png +Amazon https://amazon.com Amazon.png diff --git a/hknweb/static/img/sponsors/metadata2 b/hknweb/static/img/sponsors/metadata2 new file mode 100644 index 00000000..427a0601 --- /dev/null +++ b/hknweb/static/img/sponsors/metadata2 @@ -0,0 +1,2 @@ +Citadel https://citadel.com Citadel.png +Google https://google.com Google.png diff --git a/hknweb/templates/indrel.html b/hknweb/templates/indrel.html index 1ce392db..a934d2dd 100644 --- a/hknweb/templates/indrel.html +++ b/hknweb/templates/indrel.html @@ -144,12 +144,14 @@

Sounds good, who should I contact?

We thank all of our sponsors for their support of HKN and the broader EECS community. Click on the logos display below to visit that sponsors' website! - - + {% endfor %} +
diff --git a/hknweb/templates/indrel_admin.html b/hknweb/templates/indrel_admin.html new file mode 100644 index 00000000..ccacb082 --- /dev/null +++ b/hknweb/templates/indrel_admin.html @@ -0,0 +1,101 @@ +{% extends "base.html" %} +{% load static %} + +{% block title %}Industrial Relations Admin Page{% endblock %} + +{% block heading %} +Industrial Relations Admin Page +{% endblock %} + +{% block content %} + +{% include 'components/tabs.html' %} + + + + + + + +

Current sponsors:

+
+ {% csrf_token %} +
+ {% for index, company_name, company_url, company_file in company_data %} +
+ + + + +
+ {% endfor %} +
+ + + +
+ + +{% endblock %} diff --git a/hknweb/urls.py b/hknweb/urls.py index 0e068d64..dacd2da7 100644 --- a/hknweb/urls.py +++ b/hknweb/urls.py @@ -5,7 +5,7 @@ from django.urls import include, path from hknweb.utils import method_login_and_permission -from hknweb.views import indrel, landing, outreach, people, users +from hknweb.views import indrel, landing, outreach, people, users, indrel_admin __all__ = ["urlpatterns", "safe_urlpatterns"] @@ -29,6 +29,7 @@ path("", landing.home, name="home"), path("about/people/", people.people, name="people"), path("indrel", indrel.indrel, name="indrel"), + path("indrel_admin/", indrel_admin.indrel_admin, name = 'indrel_admin'), path("outreach", outreach.outreach, name="outreach"), ] diff --git a/hknweb/views/indrel.py b/hknweb/views/indrel.py index a427a983..03d975ed 100644 --- a/hknweb/views/indrel.py +++ b/hknweb/views/indrel.py @@ -1,8 +1,29 @@ from django.shortcuts import render from hknweb.utils import allow_public_access - +import os @allow_public_access def indrel(request): - return render(request, "indrel.html") + # company_names = ['Google', 'Microsoft', 'Berkeley', 'Amazon'] + # company_urls = ['https://google.com', 'https://microsoft.com', 'https://berkeley.edu', 'https://amazon.com'] + # company_files = ['', '', '', ''] + + data_path = "/hknweb/static/img/sponsors/" + metadata_file = data_path + "metadata" + + image_filepath = "/img/sponsors/" + + current_companies = [] + with open(os.getcwd() + metadata_file, "r") as f: + for index, line in enumerate(f.readlines()): + current_name, current_url, current_filename = line.split() + current_companies.append((index, current_name, current_url, image_filepath + current_filename)) + + + a = 0 + context = { + "company_data": current_companies + } + + return render(request, "indrel.html", context) diff --git a/hknweb/views/indrel_admin.py b/hknweb/views/indrel_admin.py new file mode 100644 index 00000000..5f7d0397 --- /dev/null +++ b/hknweb/views/indrel_admin.py @@ -0,0 +1,70 @@ +from django.shortcuts import render + +from hknweb.utils import allow_public_access +import os + +@allow_public_access +def indrel_admin(request): + post_data = {} + data_path = "/hknweb/static/img/sponsors/" + metadata_file = data_path + if request.method == 'POST': + print(request.POST) + for key in request.POST.keys(): + post_data[key] = request.POST.get(key, "") + metadata_file += "metadata" + write_metadata(post_data, os.getcwd() + metadata_file, data_path, request) + + + + + metadata_file = data_path + "metadata" + + + + current_companies = [] + + print(os.getcwd()) + + with open(os.getcwd() + metadata_file, "r") as f: + for index, line in enumerate(f.readlines()): + current_name, current_url, current_filename = line.split() + current_companies.append((index, current_name, current_url, current_filename)) + + + + + context = { + "company_data": current_companies + } + + + return render(request, "indrel_admin.html", context) + + + +def write_metadata(data, filepath, file_save_path, request): + count = 0 + for key in data: + if key.startswith("name"): + count += 1 + with open(filepath, 'w') as f: + for i in range(count): + name = data[f"name_{i}"] + url = data[f"url_{i}"] + if name == "" or url == "": + continue + uploaded_image = request.FILES.get(f"file_{i}", None) + filename = name + ".png" + if uploaded_image: + with open(os.getcwd() + file_save_path + filename, 'wb') as destination: + for chunk in uploaded_image.chunks(): + destination.write(chunk) + + + + f.write(name + " " + url + " " + filename + "\n") + + return "Successfully wrote to metadata file!" + +