Skip to content

Commit

Permalink
Qr code dev (#91)
Browse files Browse the repository at this point in the history
* handle mess time feedbackk

* update mess-card

* handling errors

* update
  • Loading branch information
Princekumarofficial authored Nov 3, 2024
1 parent dc59634 commit 58fe132
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
5 changes: 4 additions & 1 deletion api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def _get_meal_type(self, time):
if meal_timing.start_time <= time <= meal_timing.end_time:
return meal_type
except MessTiming.DoesNotExist:
raise ValueError(f"{meal_type.capitalize()} timings not found.")
return None
return None

def _filter_valid_cards(self, cards, meal_type):
Expand Down Expand Up @@ -187,6 +187,9 @@ def post(self, request):

meal_type = self._get_meal_type(time)

if(meal_type == None):
return Response({"success": False, "detail": "Meal time over.", "mess_card": card_return_data}, status=status.HTTP_403_FORBIDDEN)

if getattr(meal, meal_type):
return Response({"success": False, "detail": "Meal Already Recorded", "mess_card": card_return_data}, status=status.HTTP_409_CONFLICT)

Expand Down
20 changes: 20 additions & 0 deletions qrscan/migrations/0005_alter_messcard_student.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 5.0.8 on 2024-10-22 13:30

import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('home', '0001_initial'),
('qrscan', '0004_messtiming_delete_messtimings'),
]

operations = [
migrations.AlterField(
model_name='messcard',
name='student',
field=models.ForeignKey(help_text='This contains the student details', on_delete=django.db.models.deletion.CASCADE, to='home.student'),
),
]
2 changes: 1 addition & 1 deletion qrscan/templates/mess_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<main>
<div class="wrapper">
<div class="id-card" id="id-card">
<div class="header"></div>
<div class="card-header"></div>
<div class="photo">
<img
class="img-fluid rounded-4"
Expand Down
9 changes: 5 additions & 4 deletions qrscan/views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.utils import timezone
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from home.models import Student
Expand All @@ -19,22 +20,22 @@ def mess_card(request):
provider="google", user_id=request.user.id
)
allocation = student.allocation_set.last()

if(not allocation):
raise ValueError("Allocation not found!")
mess_card, _ = MessCard.objects.get_or_create(student=student)

if(not mess_card.allocation):
setattr(mess_card, allocation)
mess_card.save()
elif(mess_card.allocation != allocation):
setattr(mess_card, allocation)
elif((mess_card.allocation != allocation) and allocation.period.end_date < timezone.localtime().date()):
setattr(mess_card, "allocation", allocation)
mess_card.save()

picture = "not available"
try:
if socialaccount_obj:
picture = socialaccount_obj[0].extra_data["picture"]
else:
picture = "not available"
except (IndexError, KeyError):
picture = "not available"

Expand Down
38 changes: 24 additions & 14 deletions static/css/mess-card.css
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
main {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
height: max-content;
margin: 0;
background-color: #f0f0f0;
font-family: "Arial", sans-serif;
overflow-x: hidden;
}

.id-card {
width: 400px;
height: 500px;
min-height: max-content;
width: 100%;
max-width: 400px;
height: auto;
background-color: white;
border-radius: 15px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
Expand All @@ -19,43 +22,42 @@ main {
position: relative;
overflow: hidden;
}
.id-card .header {

.id-card .card-header {
background-color: #2579a6;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
height: 100px;
position: relative;
clip-path: ellipse(70% 100% at 50% 0%);
}
.id-card {
margin-top: -50px;
}

.id-card .photo {
margin-top: 10px;
}

.id-card .name {
font-size: 22px;
font-weight: bold;
margin-top: 10px;
}

.id-card .divider {
width: 50px;
height: 3px;
background-color: #2579a6;
margin: 10px auto;
}

.id-card .id-number {
font-size: 14px;
margin-top: 10px;
}

.id-card .qr-code {
margin-top: 20px;
}
.id-card .website {
font-size: 12px;
color: #2579a6;
margin-top: 10px;
}

.id-card .footer {
background-color: #2579a6;
border-bottom-left-radius: 15px;
Expand All @@ -70,11 +72,19 @@ main {

.wrapper {
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
margin-bottom: 1rem;
margin-top: 1rem;
}

.card-subtitle {
font-size: 28px;
margin-top: 10px;
}

@media (max-width: 768px) {
.id-card {
width: 90%;
}
}

0 comments on commit 58fe132

Please sign in to comment.