From c2df01e4838256ccd6cf5cb0dc433811a9306a5e Mon Sep 17 00:00:00 2001 From: CruiseDevice Date: Tue, 11 Dec 2018 14:25:04 +0530 Subject: [PATCH] Fix consecutive slot booking issue, and UI issues - Fix consecutive slot booking issue. - Add Forum and Contact us in SBHSInfocenter dropdown. - Disable Refresh button in show_video for 3 seconds. --- sbhs/context_processors.py | 10 ++-- sbhs/models.py | 5 ++ sbhs/templates/base.html | 3 +- sbhs/templates/dashboard/profile.html | 1 - sbhs/templates/dashboard/show_all_boards.html | 2 +- sbhs/templates/pages/feedback.html | 13 +++--- sbhs/templates/pages/info.html | 2 +- .../registration/password_reset_email.html | 6 +-- sbhs/templates/slot/create_slot.html | 4 +- sbhs/templates/webcam/show_video.html | 8 ++-- sbhs/urls.py | 2 +- sbhs/views.py | 46 +++++++++++++++---- 12 files changed, 66 insertions(+), 36 deletions(-) diff --git a/sbhs/context_processors.py b/sbhs/context_processors.py index 104a55b..ff51f99 100644 --- a/sbhs/context_processors.py +++ b/sbhs/context_processors.py @@ -5,8 +5,8 @@ def production_details(request): Context processor to access settings.py CONSTANTS in django template. """ - return { - 'sitename':'vlabs.iitb.ac.in/sbhs', - 'domain':settings.PRODUCTION_URL, - 'vlabs_team':settings.SENDER_NAME, - } \ No newline at end of file + context={} + context['sitename'] = request.META['HTTP_HOST'] + context['domain'] = settings.PRODUCTION_URL + context['vlabs_team'] = settings.SENDER_NAME + return context \ No newline at end of file diff --git a/sbhs/models.py b/sbhs/models.py index 506ba14..b0154fb 100644 --- a/sbhs/models.py +++ b/sbhs/models.py @@ -11,6 +11,10 @@ MOD_GROUP_NAME = 'moderator' +SLOT_TYPES = ( + ('cs','CS'), + ('as','AS'), + ) def create_group(group_name, app_label): try: @@ -146,6 +150,7 @@ class Slot(models.Model): end_time = models.DateTimeField("End time of a slot", default=timezone.now()+timedelta( minutes=settings.SLOT_DURATION)) + type_ = models.CharField(max_length=10, choices=SLOT_TYPES) objects = SlotManager() diff --git a/sbhs/templates/base.html b/sbhs/templates/base.html index 5543e0c..6827e21 100644 --- a/sbhs/templates/base.html +++ b/sbhs/templates/base.html @@ -52,6 +52,8 @@
  • Info
  • Theory
  • Procedure
  • +
  • Contact Us
  • +
  • Forums
  • @@ -78,7 +80,6 @@
    - {% if messages %}
      {% for message in messages %} diff --git a/sbhs/templates/dashboard/profile.html b/sbhs/templates/dashboard/profile.html index fe999f6..694e44e 100644 --- a/sbhs/templates/dashboard/profile.html +++ b/sbhs/templates/dashboard/profile.html @@ -5,7 +5,6 @@ {% endblock %} {% block headerfiles %} - diff --git a/sbhs/templates/dashboard/show_all_boards.html b/sbhs/templates/dashboard/show_all_boards.html index 766ebc9..fa0f48d 100644 --- a/sbhs/templates/dashboard/show_all_boards.html +++ b/sbhs/templates/dashboard/show_all_boards.html @@ -29,7 +29,7 @@

      All Active Boards

      {% if board.online %}On{% else %}Off{% endif %} View Image View Profile - Download + Download {% endfor %} diff --git a/sbhs/templates/pages/feedback.html b/sbhs/templates/pages/feedback.html index b58c727..632913a 100644 --- a/sbhs/templates/pages/feedback.html +++ b/sbhs/templates/pages/feedback.html @@ -4,14 +4,13 @@ {% block content %}
      -
      +

      Feedback / Contact Us

      -
      -
      -

      -

      Write a mail to sbhs[at]os-hardware[dot]in to provide a feedback on SBHS virtual lab experience. If you have any questions, please use the forum. -
      -

      +
      +

      +

      Write a mail to sbhs[at]os-hardware[dot]in to provide a feedback on SBHS virtual lab experience. +
      +


      diff --git a/sbhs/templates/pages/info.html b/sbhs/templates/pages/info.html index 756feb5..4782cd0 100644 --- a/sbhs/templates/pages/info.html +++ b/sbhs/templates/pages/info.html @@ -55,7 +55,7 @@


      - For more information please read the pdf +

      For more information about the procedure, please read the pdf.

      diff --git a/sbhs/templates/registration/password_reset_email.html b/sbhs/templates/registration/password_reset_email.html index bce3d3c..c32e653 100644 --- a/sbhs/templates/registration/password_reset_email.html +++ b/sbhs/templates/registration/password_reset_email.html @@ -1,14 +1,14 @@ {% load i18n %}{% autoescape off %} -{% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{ sitename }}.{% endblocktrans %} +{% blocktrans %}You're receiving this email because you requested a password reset for your user account at {{sitename}}.{% endblocktrans %} {% trans "Please go to the following page and choose a new password:" %} {% block reset_link %} -{{ protocol }}://{{ domain }}{% url 'password_reset_confirm' uidb64=uid token=token %} +{{ protocol }}://{{domain}}{% url 'password_reset_confirm' uidb64=uid token=token %} {% endblock %} {% trans "Your username, in case you've forgotten:" %} {{ user.get_username }} {% trans "Thanks for using our site!" %} -{% blocktrans %}The {{ vlabs_team }} team{% endblocktrans %} +{% blocktrans %}The SBHS Vlabs team{% endblocktrans %} {% endautoescape %} \ No newline at end of file diff --git a/sbhs/templates/slot/create_slot.html b/sbhs/templates/slot/create_slot.html index baf4f73..c0f451d 100644 --- a/sbhs/templates/slot/create_slot.html +++ b/sbhs/templates/slot/create_slot.html @@ -17,7 +17,7 @@
      diff --git a/sbhs/templates/webcam/show_video.html b/sbhs/templates/webcam/show_video.html index f8c739d..21f0909 100644 --- a/sbhs/templates/webcam/show_video.html +++ b/sbhs/templates/webcam/show_video.html @@ -27,11 +27,11 @@

      SBHS live feed: Machine ID {{mid}}

      - {% endblock %} \ No newline at end of file diff --git a/sbhs/urls.py b/sbhs/urls.py index ac046af..13bd3f5 100644 --- a/sbhs/urls.py +++ b/sbhs/urls.py @@ -38,7 +38,7 @@ # restore password urls url(r'^account/password-reset/$', password_reset, - {'template_name': 'registration/password_reset_form.html'}, + {'template_name': 'registration/password_reset_form.html',}, name='password_reset'), url(r'^account/password-reset/done/$', password_reset_done, {'template_name': 'registration/password_reset_done.html'}, diff --git a/sbhs/views.py b/sbhs/views.py index 90d83ab..140c625 100644 --- a/sbhs/views.py +++ b/sbhs/views.py @@ -318,15 +318,31 @@ def slot_new(request): form = SlotCreationForm(request.POST) if form.is_valid(): new_slot = form.save(commit=False) - new_slot_date = new_slot.start_time.date() new_slot_time = new_slot.start_time.time() + prev_hour = dt.combine( + new_slot_date,time( + new_slot_time.hour,00)) - timedelta(hours=1) + prev_slot = slot_history.filter(start_time__date=new_slot_date, + start_time__time=prev_hour) + next_hour = dt.combine( + new_slot_date,time( + new_slot_time.hour,00)) + timedelta(hours=1) + next_slot = slot_history.filter(start_time__date=new_slot_date, + start_time__time=next_hour) + if prev_slot.exists() or next_slot.exists(): + messages.error(request, + 'Cannot book two consecutive slots.') + return redirect('slot_new') + new_slot_date_slots = slot_history.filter( - start_time__date=new_slot_date + start_time__date=new_slot_date, + slot_type='as' ) if len(new_slot_date_slots) >= settings.LIMIT: messages.error(request,'Cannot Book more than {0} \ slots in advance in a day'.format(settings.LIMIT)) + return redirect('slot_new') else: if new_slot.start_time.time(): if Slot.objects.check_booked_slots( @@ -344,24 +360,30 @@ def slot_new(request): ) ) new_slot.user = user + new_slot.slot_type='as' new_slot.save() messages.success(request, 'Slot booked successfully.' ) + return redirect('slot_new') else: messages.error(request, - 'Start time selected' - + ' is before today.' - + 'Please choose again.' + 'Either you have not selected' + + ' Time or the selected Time' + + ' is before current time.' + + ' Please choose again.' ) + return redirect('slot_new') else: messages.error(request, 'Slot is already booked.' + ' Try the next slot.' ) + return redirect('slot_new') else: messages.error(request,'Please also select Time with \ Date.') + return redirect('slot_new') if request.POST.get("book_now") == "book_now": if not current_slot: @@ -373,14 +395,17 @@ def slot_new(request): time(now.hour,00)), end_time=dt.combine(now.date(), time(now.hour, settings.SLOT_DURATION) - ) + ), + slot_type='cs' ) messages.success(request,'Slot booked successfully.') + return redirect('slot_new') else: messages.error(request, 'Slot is booked by someone else.' + ' Try the next slot.' ) + return redirect('slot_new') else: messages.error(request,'Slot is already booked for \ current time. Please select a future slot.' @@ -660,7 +685,8 @@ def profile(request, mid): f = open(filename, "r") f.close() except: - raise Http404("Log does not exist for this profile.") + messages.error(request,'Log does not exist for this profile.') + return redirect('moderator_dashboard') delta_T = 1000 data = subprocess.check_output("tail -n {0} {1}".format( @@ -714,7 +740,8 @@ def download_log(request, mid): f.close() return HttpResponse(data, content_type='text/text') except: - return HttpResponse("Requested log file does not exist") + messages.error(request,"Requested log file does not exist.") + return redirect('moderator_dashboard') def zipdir(path,ziph): @@ -935,7 +962,8 @@ def download_file(request, experiment_id): ).read()) return response except: - raise Http404("Requested files does not exist.") + messages.error(request,'Requested file does not exist.') + return redirect('fetch_logs') ################## Webcam Views #############################