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 functionality so that approved daypass, leaves or both are visible on id search #297

Open
wants to merge 3 commits into
base: qosi
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
36 changes: 34 additions & 2 deletions swd/gate_security/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,40 @@
from django.shortcuts import render
from main.models import Leave, DayPass


# Create your views here.

def gate_security(request):

return render(request, "gate_security.html")
leaves = Leave.objects.filter(approved=True)
daypasss = DayPass.objects.filter(approved=True)
Comment on lines +8 to +9
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty expensive operation, storing all the leaves and day passes in the memory. It affects the performance of the system. Instead of this you can change it with:

leaves = Leave.objects.filter(approved=True, leave__student__bitsId = username)
daypasss = DayPass.objects.filter(approved=True, daypassses__student__bitsId = username)

This will fetch only the day passes for that particular system, and you could also remove the for loop from below llne.

context = {}
found_leave = False
if request.POST:
username = request.POST.get('username')
for leave in leaves:
if username in leave.student.bitsId:
student = leave.student
found_leave = True
if '1' in 'activate1':
leave.activated = True
leave.save()
context = {
'student': student,
'leave': leave,
'found_leave': found_leave
}
for daypass in daypasss:
if username in daypass.student.bitsId:
student = daypass.student
found_daypass = True
if '2' in 'activate2':
daypass.activated = True
daypass.save()
context = {
'student': student,
'daypass': daypass,
'found_daypass': found_daypass,
'found_leave': found_leave
}

return render(request, "gate_security.html", context)
2 changes: 2 additions & 0 deletions swd/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ class Leave(models.Model):
disapproved = models.BooleanField(default=0, blank=True)
inprocess = models.BooleanField(default=1, blank=True)
comment = models.TextField(default='', blank=True)
activated = models.BooleanField(default='False', blank=True)

def __str__(self):
return self.student.bitsId + ' '+ self.student.name + ' ' + str(self.id)
Expand All @@ -293,6 +294,7 @@ def document_path(instance, filename):
inprocess = models.BooleanField(default=1, blank=True)
comment = models.TextField()
document = models.FileField(upload_to=document_path, null=True, blank=True)
activated = models.BooleanField(default='False', blank=True)

def __str__(self):
return self.student.bitsId + ' (' + self.student.name + ')'
Expand Down
19 changes: 13 additions & 6 deletions swd/templates/gate_security.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</form>
<br>
</div>

{% if student %}
<div class="col s10">
<span class="card-title fresh-orange"><h4>Student Details</h4></span>
<br>
Expand All @@ -60,23 +60,30 @@
</div>
<div class="col sm-10" style="line-height:50px; position: relative;
transform: translate(20%, 20%);">
{{ student.name }} Dummy name<br>
{{ student.bitsId }} Dummy ID<br>
Dummy Phone Number
{{ student.name }}<br>
{{ student.bitsId }}<br>
{{ student.phone }}
</div>
<div class="col sm-10" style="line-height:50px; position: relative; transform: translate(20%, 20%); text-align:end">
<br>Dummy active leaves <button type="submit" class="waves-effect waves-light btn desert-yellow" id="loginbtn"><span class="deep-green">Activate</span></button>
{% if found_leave %}
<br>Click to activate Leave<button name="activate1" value='1' type="submit" class="waves-effect waves-light btn desert-yellow" id="loginbtn"><span class="deep-green">Activate</span></button>
{% endif %}
<br>
Dummy active daypasses <button type="submit" class="waves-effect waves-light btn desert-yellow" id="loginbtn"><span class="deep-green">Activate</span></button>
{% if found_daypass %}
Click to activate DayPass<button name="activate2" value='2' type="submit" class="waves-effect waves-light btn desert-yellow" id="loginbtn"><span class="deep-green">Activate</span></button>
{% endif %}
</div>
<div class="col s10" style="line-height:50px; position: relative; transform: translate(20%, 20%);">
<br><button type="submit" class="waves-effect waves-light btn desert-yellow" id="loginbtn"><span class="deep-green">In-Out</span></button>
<a href="{% url 'gate_security' %}">Look for other student</a>
</div>
{% endif %}
</div>
</div>

<br>
</div>
</form>
</div>
</div>

Expand Down