Skip to content
Merged
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
39 changes: 37 additions & 2 deletions home/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
from .models import Caterer, GlobalConstants
from django.core.cache import cache

from .models import Caterer, Contact, GlobalConstants

"""
File-name: context_processors.py
Functions: base
Used to send All Caterers Information as context in the base template
"""

FOOTER_CONTACT_CACHE_KEY = "footer_contact"
FOOTER_CONTACT_EMAIL = "gs.dining@iiti.ac.in"
FOOTER_CONTACT_CACHE_TIMEOUT = 60 * 60 * 24 # 1 day
_MISSING = object()


def get_footer_contact():
cached = cache.get(FOOTER_CONTACT_CACHE_KEY, _MISSING)
if cached is not _MISSING:
return cached

contact = (
Contact.objects.filter(email__iexact=FOOTER_CONTACT_EMAIL)
.only("name", "occupation", "email", "contact")
.first()
)
data = (
{
"name": contact.name,
"occupation": contact.occupation,
"email": contact.email,
"phone": contact.contact,
}
if contact
else {}
)
cache.set(FOOTER_CONTACT_CACHE_KEY, data, FOOTER_CONTACT_CACHE_TIMEOUT)
return data


def base(request):
caterer = Caterer.objects.filter(visible=True).all()
constants = GlobalConstants.objects.first()
if not constants:
# Provide defaults if no constants exist yet
constants = GlobalConstants.objects.create()
return {"all_caterer": caterer, "constants": constants}
return {
"all_caterer": caterer,
"constants": constants,
"footer_contact": get_footer_contact(),
}
10 changes: 9 additions & 1 deletion home/signals.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import logging
from datetime import datetime

from django.db.models.signals import post_save, pre_save
from django.core.cache import cache
from django.db.models.signals import post_delete, post_save, pre_save
from django.dispatch import receiver

from .context_processors import FOOTER_CONTACT_CACHE_KEY
from .models import (
Allocation,
Caterer,
CatererBills,
Contact,
LongRebate,
Period,
Rebate,
Expand All @@ -26,6 +29,11 @@
logger = logging.getLogger(__name__)


@receiver([post_save, post_delete], sender=Contact)
def invalidate_footer_contact_cache(sender, **kwargs):
cache.delete(FOOTER_CONTACT_CACHE_KEY)


@receiver(post_save, sender=Student)
def create_bill(sender, instance, created, **kwargs):
if created:
Expand Down
7 changes: 7 additions & 0 deletions messWebsite/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,13 @@
WSGI_APPLICATION = "messWebsite.wsgi.application"
DJANGO_ADMIN_LOGS_DELETABLE = True

CACHES = {
"default": {
"BACKEND": "django.core.cache.backends.locmem.LocMemCache",
"LOCATION": "mess-website",
}
}

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

Expand Down
14 changes: 11 additions & 3 deletions templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,21 @@ <h5 class="text-uppercase mb-2 fw-bold text-white">Location :</h5>
</div>
<div class="col-md-4 mt-md-0 mt-4 border-footer">
<h5 class="text-uppercase mb-mt-4 mb-2 fw-bold text-white">Contact Us</h5>
<p>Shubham Kumar (General secrotary mess cafiteria and allied services)</p>
{% if footer_contact %}
{% if footer_contact.name %}
<p>{{ footer_contact.name }} ({{ footer_contact.occupation }})</p>
{% endif %}
{% if footer_contact.email %}
<p>
<a href="mailto:dining.committee.sg@iiti.ac.in" class="text-white text-decoration-none"><i class="fas fa-envelope mr-3"></i> Mail us at:</a> gs.dining@iiti.ac.in
<a href="mailto:{{ footer_contact.email }}" class="text-white text-decoration-none"><i class="fas fa-envelope mr-3"></i> Mail us at:</a> {{ footer_contact.email }}
</p>
{% endif %}
{% if footer_contact.phone %}
<p>
<i class="fas fa-phone mr-3"></i> +91 8076229689
<i class="fas fa-phone mr-3"></i> {{ footer_contact.phone }}
</p>
{% endif %}
{% endif %}
</div>
</div>
<hr class="">
Expand Down
Loading