diff options
-rw-r--r-- | myadmin/views.py | 6 | ||||
-rw-r--r-- | pages/views.py | 5 | ||||
-rw-r--r-- | password/views.py | 35 | ||||
-rw-r--r-- | sbhs_server/helpers/mailer.py | 2 | ||||
-rw-r--r-- | sbhs_server/helpers/simple_encrypt.py | 4 | ||||
-rw-r--r-- | sbhs_server/sbhs.py | 22 | ||||
-rw-r--r-- | sbhs_server/scan_machine1.py | 10 | ||||
-rw-r--r-- | sbhs_server/settings.py | 4 | ||||
-rw-r--r-- | sbhs_server/tables/models.py | 43 |
9 files changed, 107 insertions, 24 deletions
diff --git a/myadmin/views.py b/myadmin/views.py index bbbb2f9..fbbae34 100644 --- a/myadmin/views.py +++ b/myadmin/views.py @@ -10,6 +10,12 @@ import subprocess,json,serial,os, datetime, re # Create your views here. def checkadmin(req): + """ Checks for valid admin + Raises Http error if: + Requested user is not admin. + Input: s: request object. + Output: HttpResponse + """ if not req.user.is_admin: raise Http404 diff --git a/pages/views.py b/pages/views.py index 4b88086..db8e58f 100644 --- a/pages/views.py +++ b/pages/views.py @@ -3,6 +3,11 @@ from django.template.loader import render_to_string from django.http import HttpResponseNotFound, HttpResponseServerError # Create your views here. +""" + Renders the required html page + Input: s: request object + output: Redirect object returned by render() and Httpresponse() functions. +""" def index(req): return render(req, "pages/index.html") diff --git a/password/views.py b/password/views.py index c0323a3..67406ed 100644 --- a/password/views.py +++ b/password/views.py @@ -8,12 +8,25 @@ import datetime # Create your views here. def new(req): + """ Returns html page to set new password + Input: request object + Output: renders new.html page through render function. + """ return render(req, 'password/new.html') def password_token(username): + """ Returns encrypted token + Input: username + Output: encrypted token returned by encrypt() function. + """ return simple_encrypt.encrypt(username + ",,," + str(datetime.datetime.now())) def email(req): + """ Sends the reset password link to the email + Checks if the user has an account + Input: request object + Output: INDEX_PAGE returned by redirect() function. + """ email = req.POST.get("email") account = Account.objects.filter(email=email) @@ -24,6 +37,12 @@ def email(req): return redirect(INDEX_PAGE) def validate_token(req, token): + """ Checks if the token is valid + Decrypts token and checks for validity + Input: request object, token. + Output: INDEX_PAGE returned by redirect() function if Invalid link + data if Valid link. + """ try: data = simple_encrypt.decrypt(token) except: @@ -38,6 +57,13 @@ def validate_token(req, token): return data, True def edit(req, token): + """ Makes user able to edit the password + calculates the time and checks if reset link is expired + Input: request object, token + Output: renders edit.html page if link is not expired + shows error message if link is expired and returns the Index_page through redirect() + function. + """ data, flag = validate_token(req, token) if not flag: return data @@ -51,6 +77,15 @@ def edit(req, token): return redirect(INDEX_PAGE) def update(req, token): + """ Makes user able to update the password + -Checks if token is valid + -Checks if the link is expired + -Checks if email entered by user is valid + -Checks if passwords of password and confirm field matches + Input: request object , token. + Output: Message "Password changed successfully" if success + Message "Invalid link" or "Reset link is expired" if respective validations fails. + """ data, flag = validate_token(req, token) if not flag: return data diff --git a/sbhs_server/helpers/mailer.py b/sbhs_server/helpers/mailer.py index e24d3e5..4c61035 100644 --- a/sbhs_server/helpers/mailer.py +++ b/sbhs_server/helpers/mailer.py @@ -2,6 +2,8 @@ from sbhs_server import settings import smtplib def email(to, subject, message): + """ Utility function to send the e-mail using SMTP. + """ smtpserver = smtplib.SMTP() smtpserver.connect(settings.EMAIL_HOST, settings.EMAIL_PORT) smtpserver.ehlo() diff --git a/sbhs_server/helpers/simple_encrypt.py b/sbhs_server/helpers/simple_encrypt.py index 976fe4d..09f8aba 100644 --- a/sbhs_server/helpers/simple_encrypt.py +++ b/sbhs_server/helpers/simple_encrypt.py @@ -1,6 +1,8 @@ import base64 def encrypt(cleartext): + """ Function to encrypt the text which is send over the e-mail to verify the user. + """ string = cleartext string = string[::-1] @@ -17,6 +19,8 @@ def encrypt(cleartext): def decrypt(ciphertext): + """ Function to decrypt the ciphertext + """ data = ciphertext.split(".") padding = int(data[0]) cipher = data[1] diff --git a/sbhs_server/sbhs.py b/sbhs_server/sbhs.py index f7873cb..6820ce5 100644 --- a/sbhs_server/sbhs.py +++ b/sbhs_server/sbhs.py @@ -19,9 +19,10 @@ class Sbhs: """ This is the Single Board Heater System class """ def __init__(self): - # status of the board - # 0 = not connected - # 1 = connected + """ status of the board + 0 = not connected + 1 = connected + """ self.machine_id = 26 self.device_num = 26 self.boardcon = False @@ -106,7 +107,10 @@ class Sbhs: return False def setHeat(self, val): - """ Set the heat """ + """ Sets the heat, checks if value is valid i.e. within range. + Input: self object, val + Output: Error message if heat cannot be set. + """ if val > MAX_HEAT or val < 0: print 'Error: heat value cannot be more than %d' % MAX_HEAT return False @@ -122,7 +126,10 @@ class Sbhs: return False def setFan(self, val): - """ Set the fan """ + """ Sets the fan speed, checks if value is valid i.e. within range. + Input: self object, val + Output: Error message if fan cannot be set. + """ if val > MAX_FAN or val < 0: print 'Error: fan value cannot be more than %d' % MAX_FAN return False @@ -137,7 +144,8 @@ class Sbhs: return False def getTemp(self): - """ Get the temperature """ + """ Gets the temperature from the machine. + """ try: self.boardcon.flushInput() self._write(chr(OUTGOING_TEMP)) @@ -149,7 +157,7 @@ class Sbhs: return 0.0 def getMachineId(self): - """ Get machine id from the device """ + """ Gets machine id from the device """ try: self.boardcon.flushInput() self._write(chr(OUTGOING_MACHINE_ID)) diff --git a/sbhs_server/scan_machine1.py b/sbhs_server/scan_machine1.py index f6922de..d33f32d 100644 --- a/sbhs_server/scan_machine1.py +++ b/sbhs_server/scan_machine1.py @@ -3,25 +3,25 @@ import sbhs import os import sys -# erase the old map_machine_ids.txt file +"""erase the old map_machine_ids.txt file""" try: file('map_machine_ids.txt', 'w').close() except: print 'Failed to create machine map file file' sys.exit(1) -# open the map_machine_ids file for writing +"""open the map_machine_ids file for writing""" try: map_machine_file = file('map_machine_ids.txt', 'w') except: print 'Failed to create machine map file file' sys.exit(1) -# get list of device file names that start with ttyUSB* in the /dev folder -#device_files = [] +""" get list of device file names that start with ttyUSB* in the /dev folder + device_files = []""" device_files = [each for each in os.listdir('/dev') if each.startswith('ttyUSB')] -# if no device filename found then exit +"""if no device filename found then exit""" if not device_files: print 'No USB device found in /dev folder' sys.exit(1) diff --git a/sbhs_server/settings.py b/sbhs_server/settings.py index ba6a19e..271ca16 100644 --- a/sbhs_server/settings.py +++ b/sbhs_server/settings.py @@ -52,7 +52,9 @@ if not DEBUG: ] # Application definition - +""" + Installed apps +""" INSTALLED_APPS = ( #'django.contrib.admin', 'django.contrib.auth', diff --git a/sbhs_server/tables/models.py b/sbhs_server/tables/models.py index 0010d2d..7ab7966 100644 --- a/sbhs_server/tables/models.py +++ b/sbhs_server/tables/models.py @@ -10,6 +10,13 @@ from django.core.exceptions import ObjectDoesNotExist # Create your models here. class Board(TrashableMixin): + """ Declaring varibales + mid = Integer and unique + online = Boolean, Default - True + temp_offline = Boolean, default - False + created_at = DateTime + updated_at = DateTime + """ mid = models.IntegerField(unique=True) online = models.BooleanField(default=True) @@ -24,6 +31,8 @@ class Board(TrashableMixin): @staticmethod def toggle_random_allotment(): + """ Enables to toggle allotment of machines between Workshop mode and Random mode + """ if Board.can_do_random_allotment(): f = open(os.path.join(settings.BASE_DIR, "WORKSHOP_MODE"), "w") f.close() @@ -32,6 +41,8 @@ class Board(TrashableMixin): @staticmethod def allot_board(): + """ + """ if Board.can_do_random_allotment(): online_boards_count = len(settings.online_mids) board_num = random.randrange(online_boards_count) @@ -55,11 +66,12 @@ class Board(TrashableMixin): return -1 def image_link(self): + """ Function to show the image obtained from webcam + """ return settings.WEBCAM_STATIC_DIR + "image" + str(self.mid) + ".jpeg" -class Account(TrashableMixin, AbstractBaseUser): - +class Account(TrashableMixin, AbstractBaseUser): name = models.CharField(max_length=255) username = models.CharField(max_length=127, unique=True) email = models.EmailField(max_length=255, unique=True) @@ -83,12 +95,17 @@ class Account(TrashableMixin, AbstractBaseUser): return self.name def send_confirmation(self): + """ Function to show message to the user to confirm their account by visiting the link sent + to their e-mail. + """ message = """Hi,\n\nPlease visit the link """ + settings.BASE_URL + """sbhs/account/confirm/""" message = message + self.confirmation_token() message = message + """ to confirm your account.\n\n\nRegards,\nVlabs Team""" mailer.email(self.email, "Please confirm your account", message) def send_password_link(self, token): + """ Function to show message to user to visit the link in order to change the password. + """ message = """Hi,\n\nPlease visit the link """ + settings.BASE_URL + """password/edit/""" message = message + token message = message + """ to change your password.\n\n\nRegards,\nVlabs Team""" @@ -122,15 +139,15 @@ class Slot(TrashableMixin): @staticmethod def indices(self, other): - # These lines are irrelevant due to booking date scheme - # - # now = datetime.datetime.now() - # cur_hour = now.hour - - # s = abs(cur_hour - self.start_hour) - # s = s + 100 if self.start_hour < cur_hour else s - # o = abs(cur_hour - other.start_hour) - # o = o + 100 if other.start_hour < cur_hour else o + These lines are irrelevant due to booking date scheme + """ now = datetime.datetime.now() + cur_hour = now.hour + + s = abs(cur_hour - self.start_hour) + s = s + 100 if self.start_hour < cur_hour else s + o = abs(cur_hour - other.start_hour) + o = o + 100 if other.start_hour < cur_hour else o + """ return self.start_hour, other.start_hour def __lt__(self, other): @@ -159,6 +176,10 @@ class Slot(TrashableMixin): @staticmethod def current_slots(mid): + """ Function to display the current slots to the user. + Input: mid + Output: slots + """ now = datetime.datetime.now() slots = list(Slot.objects.filter(start_hour=now.hour, end_minute__gt=now.minute)) bookings = Booking.objects.filter(booking_date__year=now.year, |