Skip to content

Commit

Permalink
Merge pull request #2 from Pancham1603/production
Browse files Browse the repository at this point in the history
Production merge with hostel status view and improvements
  • Loading branch information
Pancham1603 authored Dec 25, 2023
2 parents b3c6c44 + 1d3613b commit 6d92243
Show file tree
Hide file tree
Showing 34 changed files with 881 additions and 352 deletions.
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
FROM python:3.8.16

# Install cron
RUN apt-get update && apt-get install -y cron
# RUN apt-get update && apt-get install -y cron

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
Expand All @@ -17,14 +17,14 @@ RUN python -m pip install -r requirements.txt
WORKDIR /app
COPY . /app

# Copy cron job file
COPY cronjob /etc/cron.d/cronjob
# # Copy cron job file
# COPY cronjob /etc/cron.d/cronjob

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/cronjob
# # Give execution rights on the cron job
# RUN chmod 0644 /etc/cron.d/cronjob

# Create the log file to be able to run tail
RUN touch /var/log/cron.log
# # Create the log file to be able to run tail
# RUN touch /var/log/cron.log

# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-python-configure-containers
Expand Down
Empty file.
5 changes: 5 additions & 0 deletions apps/global_settings/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin
from .models import Settings

# Register your models here.
admin.site.register(Settings)
6 changes: 6 additions & 0 deletions apps/global_settings/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class GlobalSettingsConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.global_settings'
25 changes: 25 additions & 0 deletions apps/global_settings/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.7 on 2023-12-11 22:17

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Settings',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('enable_hostel_timers', models.BooleanField(default=False)),
('frontend_checkin_timer', models.IntegerField(blank=True, default=0, null=True)),
('backend_checkin_timer', models.IntegerField(blank=True, default=0, null=True)),
('last_entry_without_hostel_checkout', models.TimeField(blank=True, null=True)),
('valid_entry_without_hostel_checkout', models.TimeField(blank=True, null=True)),
],
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.7 on 2023-12-11 22:38

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('global_settings', '0001_initial'),
]

operations = [
migrations.AddField(
model_name='settings',
name='enable_gender_ratio',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='settings',
name='female_ratio',
field=models.FloatField(blank=True, default=0.5, null=True),
),
migrations.AddField(
model_name='settings',
name='male_ratio',
field=models.FloatField(blank=True, default=0.5, null=True),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 4.2.7 on 2023-12-13 01:37

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('global_settings', '0002_settings_enable_gender_ratio_settings_female_ratio_and_more'),
]

operations = [
migrations.AlterModelOptions(
name='settings',
options={'verbose_name_plural': 'Settings'},
),
migrations.AddField(
model_name='settings',
name='max_violation_count',
field=models.IntegerField(blank=True, default=3, null=True),
),
]
Empty file.
19 changes: 19 additions & 0 deletions apps/global_settings/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.db import models

class Settings(models.Model):

enable_hostel_timers = models.BooleanField(default=False)
frontend_checkin_timer = models.IntegerField(blank=True, null=True, default=0)
backend_checkin_timer = models.IntegerField(blank=True, null=True, default=0)

last_entry_without_hostel_checkout = models.TimeField(blank=True, null=True)
valid_entry_without_hostel_checkout = models.TimeField(blank=True, null=True)

enable_gender_ratio = models.BooleanField(default=False)
male_ratio = models.FloatField(blank=True, null=True, default=0.5)
female_ratio = models.FloatField(blank=True, null=True, default=0.5)

max_violation_count = models.IntegerField(blank=True, null=True, default=3)

class Meta:
verbose_name_plural = 'Settings'
3 changes: 3 additions & 0 deletions apps/global_settings/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
3 changes: 3 additions & 0 deletions apps/global_settings/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.shortcuts import render

# Create your views here.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 4.2.7 on 2023-12-11 22:17

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('nightpass', '0002_alter_campusresource_slots_booked'),
]

operations = [
migrations.AddField(
model_name='hostel',
name='backend_checkin_timer',
field=models.IntegerField(blank=True, default=0, null=True),
),
migrations.AddField(
model_name='hostel',
name='frontend_checkin_timer',
field=models.IntegerField(blank=True, default=0, null=True),
),
]
3 changes: 3 additions & 0 deletions apps/nightpass/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class Hostel(models.Model):
contact_number = models.CharField(max_length=15)
email = models.EmailField(max_length=100)

frontend_checkin_timer = models.IntegerField(blank=True, null=True, default=0)
backend_checkin_timer = models.IntegerField(blank=True, null=True, default=0)

def __str__(self):
return self.name

Expand Down
26 changes: 26 additions & 0 deletions apps/nightpass/static/serviceworker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
var staticCacheName = 'thapar-nightpass';

self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(staticCacheName).then(function(cache) {
return cache.addAll([
'',
]);
})
);
});

self.addEventListener('fetch', function(event) {
var requestUrl = new URL(event.request.url);
if (requestUrl.origin === location.origin) {
if ((requestUrl.pathname === '/')) {
event.respondWith(caches.match(''));
return;
}
}
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
56 changes: 55 additions & 1 deletion apps/nightpass/static/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,61 @@ select {
color: #fff;
}

footer {
background-color: #696b6d;
color: #fff;
text-align: center;
padding: 10px;
position: fixed;
bottom: 0;
width: 100%;
}

.custom-table {
width: 100%;
border-collapse: collapse;
}

.custom-table th,
.custom-table td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}

.custom-table th {
background-color: #eb1b23;
color: #fff;
font-weight: bold;
}

.red {
background-color: #d92550;
}

.green {
background-color: #3ac47d;
}

.yellow {
background-color: #f7b924;
}

.badge {
color: white;
padding: 5px 10px;
border-radius: 5px;
}

.table-container {
max-width: 800px; /* Adjust the maximum width as needed */
margin: 10px auto; /* Center the container horizontally */
padding: 20px; /* Add some padding for spacing */
overflow-x: auto; /* Add horizontal scrolling for small screens */
background-color: #fff;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);

}

@media (max-width: 768px) {
.profile-card, .resource-card {
Expand All @@ -246,7 +300,7 @@ select {
flex-wrap: wrap;
justify-content: center;
align-items: center;
}
}

.activity-table {
font-size: 14px;
Expand Down
Binary file added apps/nightpass/static/thapar_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions apps/nightpass/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Thapar NightPass</title>
<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.6/dist/barcodes/JsBarcode.code128.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.4/jquery.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastr.js/latest/toastr.min.js"></script>
<link rel="stylesheet" href="../static/styles.css">
</head>
<body>

<div class="header">
<img class="header-logo" src="https://i.imgur.com/gnAYCgT.png" alt="College Logo">
<h1>Thapar NightPass</h1>
<button class="logout-button" onclick="window.location.href = '/logout';">Logout</button>
</div>
{% block content %}
{% endblock %}

<footer>
Made with ♥ by <a href="https://www.linkedin.com/in/pancham1603/" target="_blank" style="text-decoration: underline; color: white;">Pancham Agarwal</a>
</footer>


<script>
toastr.options = {
"closeButton": false,
"newestOnTop": true,
"progressBar": false,
"positionClass": "toast-top-right",
"preventDuplicates": true,
"onclick": null,
"showDuration": "300",
"hideDuration": "1000",
"timeOut": "3000",
"extendedTimeOut": "1000",
"showEasing": "swing",
"hideEasing": "linear",
"showMethod": "fadeIn",
"hideMethod": "fadeOut"
}
</script>

{% if messages %}
{% for message in messages %}
<script>
toastr.info("{{ message }}")
</script>
{% endfor %}
{% endif %}
</body>
</html>
41 changes: 41 additions & 0 deletions apps/nightpass/templates/caretaker.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{% extends 'base.html' %}

{% block content %}
<div class="table-container">
<div class="table-responsive">
<table class="custom-table">
<thead>
<tr>
<th>Name</th>
<th>Room No</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
{% for pass in hostel_passes %}
<tr>
<td>{{ pass.user.student.name }}</td>
<td>{{ pass.user.student.room_number }}</td>
{% if pass.user.student.is_checked_in %}
<td><span class="badge green">Checked In</span></td>
{% else %}
{% if pass %}
{% if pass.check_in and not pass.check_out %}
<td><span class="badge yellow">{{ pass.campus_resource }}</span></td>
{% else %}
<td><span class="badge red">Outside</span></td>
{% endif %}
{% else %}
<td><span class="badge red">Outside</span></td>
{% endif %}
{% endif %}
<td><a href="tel:{{ pass.user.student.contact_number }}"><button>Call</button></td>
</tr>
{% endfor %}
</tbody>
</table>

</div>
</div>
{% endblock %}
Loading

0 comments on commit 6d92243

Please sign in to comment.