Skip to content
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
8 changes: 8 additions & 0 deletions cdcontent/templates/cdcontent/cdcontent_home.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,15 @@
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 col-lg-offset-3 col-md-offset-3 col-sm-offset-3">
<span class='ajax-refresh ajax-refresh-add-foss'><i class="fa fa-2 fa-refresh fa-spin"></i></span>
<input type="button" class="add_foss_lang btn btn-primary" value="Add selected FOSS" tabindex="4" />
{% if is_valid_vle %}
<input type="submit" class="btn btn-primary create_zip" value="Create ZIP file" tabindex="5" />
{% else %}
<div class="alert alert-danger" role="alert">
{{renewal_info}}
<p>Please renew subscription to download cdcontent.</p>
</div>
{% endif %}

</div>
</div>
</fieldset>
Expand Down
13 changes: 10 additions & 3 deletions csc/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from csc.models import Student, Student_certificate_course,CertifiateCategories, VLE, CSC, Transaction,CategoryCourses,Student_Foss
from csc.api.utility import send_pwd_mail,map_foss_to_student

from csc.utils import getFirstName,getLastName
from csc.utils import getFirstName,getLastName,calculate_tenure_end

from django.contrib.auth.hashers import make_password
import random
Expand Down Expand Up @@ -195,7 +195,11 @@ def create(self, validated_data):
vle = VLE.objects.create(**validated_data)
vle_group = Group.objects.get(name='VLE')
vle_group.user_set.add(u)
t = Transaction.objects.create(vle=vle,csc=obj,transcdate=transaction_data[0]['transcdate'])

trans_start_date = transaction_data[0]['transcdate']
tenure_end_date = calculate_tenure_end(vle,trans_start_date)
t = Transaction.objects.create(vle=vle,csc=obj,transcdate=trans_start_date,tenure_end_date=tenure_end_date)

send_pwd_mail(u)
return vle

Expand Down Expand Up @@ -224,7 +228,10 @@ def update(self,instance,validated_data):
c.is_valid(raise_exception=True)
c.save()
if has_transaction :
t = Transaction.objects.create(vle=instance,csc=instance.csc,transcdate=transaction_data['transcdate'])
trans_start_date = transaction_data['transcdate']
tenure_end_date = calculate_tenure_end(vle,trans_start_date)
t = Transaction.objects.create(vle=instance,csc=instance.csc,transcdate=trans_start_date,tenure_end_date=tenure_end_date)

if has_user:
user_obj = instance.user
if "email" in user_data:
Expand Down
25 changes: 25 additions & 0 deletions csc/context_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from csc.models import VLE, Transaction
from datetime import date
from django.conf import settings
def is_vle_valid(request):
is_valid_vle = False
valid_days = 0
alert_tag = 'danger'
user = request.user
vle = None
expire_date = None
if user.is_authenticated:
vle = VLE.objects.filter(user=user).first()
if vle:
expire_date = Transaction.objects.filter(vle=vle).order_by('-tenure_end_date').values('tenure_end_date')[0]['tenure_end_date']
current_date = date.today()
if current_date <= expire_date:
is_valid_vle = True
date_diff = expire_date - current_date
valid_days = date_diff.days
ALERT_DAYS = int(getattr(settings, 'ALERT_DAYS'))
if valid_days > ALERT_DAYS:
alert_tag = 'info'
renewal_info = 'Your account is restricted due to non-renewal of subscription.'
return {'is_valid_vle':is_valid_vle,'alert_tag':alert_tag,'valid_days':valid_days,'tenure_end_date':expire_date,'renewal_info':renewal_info}

22 changes: 22 additions & 0 deletions csc/migrations/0023_auto_20230421_1119.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Generated by Django 3.0.3 on 2023-04-21 05:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('csc', '0022_auto_20230116_1539'),
]

operations = [
migrations.RemoveField(
model_name='vle',
name='status',
),
migrations.AlterField(
model_name='student',
name='date_of_registration',
field=models.DateField(blank=True, null=True),
),
]
8 changes: 4 additions & 4 deletions csc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@
from django.db import models
from django.contrib.auth.models import User
from django.forms import ChoiceField
from django.core.exceptions import ValidationError
from spokenlogin.models import *
from model_utils import Choices
from cms.models import State, District, City
from django.forms import widgets
from datetime import date
from django.template.defaultfilters import slugify
from django.conf import settings
# from csc.utils import TEST_OPEN


VLE_TENURE_DAYS = int(getattr(settings, 'VLE_TENURE_DAYS'))
TEST_OPEN = 0
REJECTED = 0
APPROVED = 1
Expand Down Expand Up @@ -98,13 +100,11 @@ class CSC(models.Model):
def __str__(self):

return f"{self.city},{self.district}"


class VLE(models.Model):
csc = models.ForeignKey(CSC,on_delete=models.CASCADE) # edge case : 1 vle moves to another city, enrolls for csc with same email??
user = models.ForeignKey(User,on_delete=models.CASCADE)
phone = models.CharField(max_length=100)
status = models.BooleanField(default=True) # If the vle is inactivated for some reason

class Meta:
unique_together = ('csc','user')
Expand Down Expand Up @@ -160,7 +160,7 @@ class Student(models.Model):
district = models.ForeignKey(District,on_delete=models.CASCADE,blank=True,null=True)
pincode = models.CharField(max_length=6,blank=True,null=True)
address = models.CharField(max_length=255,blank=True,null=True)
date_of_registration = models.DateField(default=date.today())
date_of_registration = models.DateField(null=True,blank=True)
occupation = models.CharField(max_length=255,blank=True,null=True)
category = models.CharField(max_length=255,blank=True,null=True)
mdl_mail_sent = models.BooleanField(default=False)
Expand Down
12 changes: 11 additions & 1 deletion csc/templates/csc/mark_attendance.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,17 @@
<div class="card-text d-flex my-3">
<p class="me-5"><button class="btn btn-sm " id="btn_select_all" style="background-color: #90B77D">Select all </button></p>
<p class="me-5"><button class="btn btn-sm " id="btn_deselect_all" style="background-color: #F29393">Deselect all </button></p>
<p class="me-5"><button class="btn btn-sm btn-success" id="btn_mark_attendance1" type="submit" form="mark_atten">Mark attendance</button></p>
<p class="me-5">
{% if is_valid_vle %}
<button class="btn btn-sm btn-success" id="btn_mark_attendance1" type="submit" form="mark_atten">Mark attendance</button>
{% else %}
<div class="alert alert-danger" role="alert">
{{renewal_info}}
<p>Please renew subscription to mark attendance.</p>
</div>
{% endif %}

</p>

<!-- <p>Total Students selected : <span id="students_selected"></span></p> -->
</div>
Expand Down
10 changes: 9 additions & 1 deletion csc/templates/csc/test.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,15 @@
<form method="POST">
{% csrf_token %}
{{form | crispy}}
<button type="submit" class="btn c-btn">Create Test</button>
{% if is_valid_vle %}
<button type="submit" class="btn c-btn">Create Test</button>
{% else %}
<div class="alert alert-danger" role="alert">
{{renewal_info}}
<p>Please renew subscription to create new test.</p>
</div>
{% endif %}

</form>
<hr>
<p><small>** Tests can be raised only for the FOSS which is assigned to your students! </small></p>
Expand Down
10 changes: 9 additions & 1 deletion csc/templates/csc/test_assign.html
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,15 @@
</tbody>
</table>
</div>
<button type="submit" name="action_type" value="add_students" class="btn c-btn">Add students to the test</button>
{% if is_valid_vle %}
<button type="submit" name="action_type" value="add_students" class="btn c-btn">Add students to the test</button>
{% else %}
<div class="alert alert-danger" role="alert">
{{renewal_info}}
<p>Please renew subscription to assign new students to the test.</p>
</div>
{% endif %}

</form>
<hr>
<p><small>** Tests can be assigned to the students after 10 days of assigning FOSS ! </small></p>
Expand Down
11 changes: 11 additions & 0 deletions csc/templates/csc/vle.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,17 @@


<div>
{% if is_valid_vle %}
<div class="alert alert-{{alert_tag}}" role="alert">
<p>Your subscription will expire on {{tenure_end_date}} (Days remaining : {{valid_days}})</p>
</div>
{% else %}
<div class="alert alert-{{alert_tag}}" role="alert">
<p>Your subscription expired on {{tenure_end_date}}.You have restricted access to the interface.</p>
</div>
{% endif %}


<div class="card mb-3">
<div class="card-header">
<div><i class="fas fa-user-circle mr-2"> </i> <span>{{ user.first_name | title }} {{ user.last_name | title }}</span></div>
Expand Down
11 changes: 11 additions & 0 deletions csc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,14 @@ def get_test_valid_fosses(vle):
def get_invig(vle):
invigilators = Invigilator.objects.filter(vle=vle).order_by('user__first_name')
return invigilators

def calculate_tenure_end(vle,start_date):
prev_transactions = Transaction.objects.filter(vle=vle).order_by('-transcdate')
if prev_transactions:
prev_transaction = prev_transactions[0]
prev_end_date = prev_transaction.tenure_end_date
if start_date < prev_end_date:
tenure_end_date = prev_end_date + datetime.timedelta(days=VLE_TENURE_DAYS)
return tenure_end_date
tenure_end_date = start_date + datetime.timedelta(days=VLE_TENURE_DAYS)
return tenure_end_date
5 changes: 4 additions & 1 deletion spoken_main_website/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
'django.template.context_processors.media',
'django.template.context_processors.static',
'spoken_main_website.context_processor.settings_val',
'csc.context_processor.is_vle_valid',
],
},
},
Expand Down Expand Up @@ -295,4 +296,6 @@
MDL_URL = os.getenv("MDL_URL")

TIME_OUT = 15
GOOGLE_TAG=os.getenv("GOOGLE_TAG")
GOOGLE_TAG=os.getenv("GOOGLE_TAG")
VLE_TENURE_DAYS=os.getenv("VLE_TENURE_DAYS",100)
ALERT_DAYS=os.getenv("ALERT_DAYS",15)