Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added page for dynamically changing sponsors at /indrel_admin #568

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added hknweb/static/img/sponsors/Amazon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added hknweb/static/img/sponsors/Microsoft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions hknweb/static/img/sponsors/metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Citadel https://citadel.com Citadel.png
Google https://google.com Google.png
Amazon https://amazon.com Amazon.png
2 changes: 2 additions & 0 deletions hknweb/static/img/sponsors/metadata2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Citadel https://citadel.com Citadel.png
Google https://google.com Google.png
12 changes: 7 additions & 5 deletions hknweb/templates/indrel.html
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ <h3>Sounds good, who should I contact?</h3>

<div id="sponsors" class="tabcontent">
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!

<div class="company-sponsors-logos">
<a href="https://www.citadel.com/">
<img src="{% static 'img/indrel_sponsors_citadel_logo.png' %}" class="company-sponsors-logo" alt="Citadel logo">
{% for index, company_name, company_url, company_file in company_data %}
<div class = "company-sponsors-logos">
<a href = {{company_url}}>
<img src = "{% static company_file %}" class = "company-sponsors-logo" alt = {{company_name}}>
</a>
</div>
</div>
{% endfor %}

</div>
</div>
</div>
Expand Down
101 changes: 101 additions & 0 deletions hknweb/templates/indrel_admin.html
Original file line number Diff line number Diff line change
@@ -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' %}

<style>
.content {
padding-top: 25px;
padding-bottom: 25px;
}

.inner {
max-width: 1000px;
margin: auto;
text-align: left;
}

.scrollable {
height: 750px;
overflow-y: auto;
}

.company-sponsors-logos {
text-align: center;
}

.company-sponsors-logo {
width: 500px;
max-width: 100%;
}
</style>
<!--
<div class="inner">
<div class="tab">
<button id="default_option" class="tablinks" onclick="open_tab(event, 'what_is_hkn')">What is HKN?</button>
<button class="tablinks" onclick="open_tab(event, 'resume_book')">Resume Book</button>
<button class="tablinks" onclick="open_tab(event, 'career_fair')">EECS Career Fair</button>
<button class="tablinks" onclick="open_tab(event, 'infosessions')">Infosessions</button>
<button class="tablinks" onclick="open_tab(event, 'sponsors')">Current sponsors</button>
</div>


</div> -->

<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
$(document).ready(function () {
let maxFields = 200;
let addButton = $('.add-button');
let inputWrapper = $('.input-wrapper');

$(addButton).click(function () {
if (inputWrapper.children().length < maxFields) {
let index = inputWrapper.children().length;
let inputName = `name_${index}`;
let inputUrl = `url_${index}`;
let inputFile = `file_${index}`;
inputWrapper.append(`<div class = "input-elem"><input type="text" name="${inputName}" placeholder="">
<input type="text" name="${inputUrl}" placeholder="">
<input type="file" name="${inputFile}"></div>`);
}
});

$(document).on('click', '.remove-button', function () {
$(this).prev('input').remove();
});
});
</script>

<h3>Current sponsors:</h3>
<form method="POST" action= "{% url 'indrel_admin' %}" enctype = "multipart/form-data">
{% csrf_token %}
<div class = "input-wrapper">
{% for index, company_name, company_url, company_file in company_data %}
<div class = "input-elem">
<input type = "text" size = "32" value = {{company_name}} name = "name_{{index}}">
<input type = "text" size = "32" value = {{company_url}} name = "url_{{index}}">
<input type = "file" size = "32" value = "Upload Image" name = "file_{{index}}">
<!-- <a href = {{company_url}}>
<img src = "{% static company_file %}" class = "company-sponsors-logo" alt = {{company_name}}>
</a> -->
</div>
{% endfor %}
</div>
<button type="button" class="add-button">Add Sponsor</button>
<button type="submit" name="submit_button" class="btn btn-primary">Submit Changes</button>
<button type = "button" class = "remove-button">Remove Sponsor (Doesn't Work)</button>
</form>
<script>
document.getElementById("default_option").click();
</script>

{% endblock %}
3 changes: 2 additions & 1 deletion hknweb/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand All @@ -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"),
]

Expand Down
25 changes: 23 additions & 2 deletions hknweb/views/indrel.py
Original file line number Diff line number Diff line change
@@ -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)
70 changes: 70 additions & 0 deletions hknweb/views/indrel_admin.py
Original file line number Diff line number Diff line change
@@ -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!"