Skip to content

Commit

Permalink
feat: add md5 hashes to static files; remove manual JS_VERSION variable
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Jan 29, 2025
1 parent 8f3588d commit 619a14e
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 72 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,3 @@ You can leave the default values for development.
You can create the tag via GitHub releases tab.
4. Ask maintainer (@ArtemSBulgakov) to allow the deployment via GitHub Actions.
5. Verify that changes work on the production server.

### Changing JS or CSS

When changing JS scripts or CSS styles,
you also should update 'JS_VERSION' setting in `adminpage/adminpage/settings.py`.
This is needed to update the cache in browsers.

15 changes: 11 additions & 4 deletions adminpage/adminpage/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ def compose_base_url(schema, hostname, port) -> str:
# People with passed checkup are able to upload self-sport
SELFSPORT_MINIMUM_MEDICAL_GROUP_ID = -1

JS_VERSION = "F24.22.22"

SPORT_DEPARTMENT_EMAIL = "sport@innopolis.university"
STUDENT_AUTH_GROUP_VERBOSE_NAME = "Students"
STUDENT_AUTH_GROUP_NAME = "S-1-5-21-721043115-644155662-3522934251-2285"
Expand Down Expand Up @@ -166,7 +164,6 @@ def compose_base_url(schema, hostname, port) -> str:
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'sport.context_processors.js_version',
],
},
},
Expand Down Expand Up @@ -292,7 +289,7 @@ def compose_base_url(schema, hostname, port) -> str:
USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.2/howto/static-files/
# https://docs.djangoproject.com/en/5.1/howto/static-files/

STATIC_ROOT = '/static/'

Expand All @@ -301,6 +298,16 @@ def compose_base_url(schema, hostname, port) -> str:
else:
STATIC_URL = '/static/'

STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
# Add md5 hash to filenames in production
"BACKEND": "adminpage.storage.CustomManifestStaticFilesStorage",
},
}

MEDIA_URL = '/media/'
MEDIA_ROOT = '/uploaded_media'

Expand Down
8 changes: 8 additions & 0 deletions adminpage/adminpage/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib.staticfiles.storage import ManifestStaticFilesStorage


class CustomManifestStaticFilesStorage(ManifestStaticFilesStorage):
def url(self, name, force=False):
if name == "plupload":
return None # Fix error with smartfields
return super().url(name, force)
5 changes: 0 additions & 5 deletions adminpage/sport/context_processors.py

This file was deleted.

4 changes: 2 additions & 2 deletions adminpage/sport/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{% block title %} {% endblock %}</title>
<link rel="stylesheet" href="{% static "sport/css/header.css" %}?v={{JS_VERSION}}">
<script src="{% static "sport/js/header.js" %}?v={{JS_VERSION}}"></script>
<link rel="stylesheet" href="{% static "sport/css/header.css" %}">
<script src="{% static "sport/js/header.js" %}"></script>
{% block extrahead %} {% endblock %}
</head>
<body>
Expand Down
14 changes: 7 additions & 7 deletions adminpage/sport/templates/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.css">
<link rel="stylesheet" href="{% static "sport/css/calendar.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/calendar.css" %}">
<script>
const sport_name = "{{ sport.name }}";
</script>
Expand All @@ -19,11 +19,11 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.js"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/calendar.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/calendar.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}"></script>
<script src="{% static "sport/js/modules/calendar.mjs" %}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}"></script>
<script src="{% static "sport/js/calendar.js" %}"></script>
{% endblock %}

{% block content %}
Expand Down Expand Up @@ -85,4 +85,4 @@ <h5 class="alert-heading">Remember!</h5>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
14 changes: 7 additions & 7 deletions adminpage/sport/templates/calendar_without_sport.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.css">
<link rel="stylesheet" href="{% static "sport/css/calendar.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/calendar.css" %}">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/core/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/daygrid/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/js/bootstrap.bundle.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.js"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/calendar.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/calendar.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}"></script>
<script src="{% static "sport/js/modules/calendar.mjs" %}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}"></script>
<script src="{% static "sport/js/calendar.js" %}"></script>
{% endblock %}

{% block content %}
Expand All @@ -38,4 +38,4 @@ <h1>Extra Sport Activities</h1>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
20 changes: 10 additions & 10 deletions adminpage/sport/templates/category.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/css/bootstrap-reboot.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.css">
<link rel="stylesheet" href="{% static "sport/css/bootstrap-tourist.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/category.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/bootstrap-tourist.css" %}">
<link rel="stylesheet" href="{% static "sport/css/category.css" %}">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.4.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.js"></script>
<script src="{% static "sport/js/bootstrap-tourist.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/tour.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/category.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/bootstrap-tourist.js" %}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}"></script>
<script src="{% static "sport/js/modules/tour.mjs" %}"></script>
<script src="{% static "sport/js/category.js" %}"></script>
{% endblock %}

{% block content %}
Expand All @@ -33,7 +33,7 @@ <h1 class="mb-3">Sports & Clubs</h1>
{% if student_sport_group|length == 0 %}
<div class="mb-3">
<div class="alert alert-success" role="alert">
To choose a <span class="badge badge-dark">SPORT TYPE</span> and
To choose a <span class="badge badge-dark">SPORT TYPE</span> and
enroll to a <span class="badge badge-info">SPORT GROUP</span>, <strong>see the schedule</strong>.
</div>
</div>
Expand Down Expand Up @@ -118,4 +118,4 @@ <h4><span class="badge badge-warning">No sport types are available</span></h4>
</div>
</div>
</div>
{% endblock %}
{% endblock %}
18 changes: 9 additions & 9 deletions adminpage/sport/templates/fitness_test.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.css">
<link rel="stylesheet" href="{% static "sport/css/bootstrap-tourist.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/profile.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/bootstrap-tourist.css" %}">
<link rel="stylesheet" href="{% static "sport/css/profile.css" %}">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
Expand All @@ -24,13 +24,13 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.js"></script>
<script src="{% static "sport/js/bootstrap-tourist.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/tour.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/category.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/fitness_test.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/bootstrap-tourist.js" %}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}"></script>
<script src="{% static "sport/js/modules/tour.mjs" %}"></script>
<script src="{% static "sport/js/category.js" %}"></script>
<script src="{% static "sport/js/fitness_test.js" %}"></script>
{% endblock %}

{% block content %}
Expand Down
18 changes: 9 additions & 9 deletions adminpage/sport/templates/fitness_test_session.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.css">
<link rel="stylesheet" href="{% static "sport/css/bootstrap-tourist.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/profile.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/bootstrap-tourist.css" %}">
<link rel="stylesheet" href="{% static "sport/css/profile.css" %}">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
Expand All @@ -24,14 +24,14 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.js"></script>
<script src="{% static "sport/js/bootstrap-tourist.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/tour.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/category.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/bootstrap-tourist.js" %}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}"></script>
<script src="{% static "sport/js/modules/tour.mjs" %}"></script>
<script src="{% static "sport/js/category.js" %}"></script>
<script src="https://cdn.jsdelivr.net/gh/digitalBush/jquery.maskedinput/dist/jquery.maskedinput.min.js" type="text/javascript"></script>
<script src="{% static "sport/js/fitness_test_session.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/fitness_test_session.js" %}"></script>
{% endblock %}

{% block content %}
Expand Down
24 changes: 12 additions & 12 deletions adminpage/sport/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.css">
<link rel="stylesheet" href="{% static "sport/css/bootstrap-tourist.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/profile.css" %}?v={{JS_VERSION}}">
<link rel="stylesheet" href="{% static "sport/css/bootstrap-tourist.css" %}">
<link rel="stylesheet" href="{% static "sport/css/profile.css" %}">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
Expand All @@ -24,16 +24,16 @@
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/timegrid/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/4.2.0/list/main.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/2.1.4/toastr.min.js"></script>
<script src="{% static "sport/js/csv.min.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/bootstrap-tourist.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/calendar.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/modules/tour.mjs" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/self_sport_reference.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/swipeCalendar.min.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/profile.js" %}?v={{JS_VERSION}}"></script>
<script src="{% static "sport/js/csv.min.js" %}"></script>
<script src="{% static "sport/js/bootstrap-tourist.js" %}"></script>
<script src="{% static "sport/js/modules/networking.mjs" %}"></script>
<script src="{% static "sport/js/modules/enrollment.mjs" %}"></script>
<script src="{% static "sport/js/modules/calendar.mjs" %}"></script>
<script src="{% static "sport/js/modules/modals.mjs" %}"></script>
<script src="{% static "sport/js/modules/tour.mjs" %}"></script>
<script src="{% static "sport/js/self_sport_reference.js" %}"></script>
<script src="{% static "sport/js/swipeCalendar.min.js" %}"></script>
<script src="{% static "sport/js/profile.js" %}"></script>
{% endblock %}

{% block content %}
Expand Down

0 comments on commit 619a14e

Please sign in to comment.