Permalink
Browse files

drop course checkboxes in schedule page. work on django messages. sho…

…uld start using branches
  • Loading branch information...
1 parent ae838da commit c95b95bc8fa3f3d643e44c5af983ec59f711f21f Kevin Ngo committed Jun 19, 2011
Showing with 53 additions and 10 deletions.
  1. +2 −3 course/views.py
  2. +14 −3 schedule/templates/schedule/index.html
  3. +36 −4 schedule/views.py
  4. +1 −0 scheduler/views.py
View
@@ -50,9 +50,9 @@ def show(request, department, number, status=''):
# display confirmation or error message if register success/fail
if success:
- messages.success(request, "Successfully registered for " + course)
+ messages.success(request, "Successfully registered for " + course.upper())
else:
- messages.error(request, "Failed to register for " + course )
+ messages.error(request, "Failed to register for " + course.upper())
return render_to_response('course/show.html', {'courses':courses}, context_instance=RequestContext(request))
@@ -67,7 +67,6 @@ def register(request, crn1, crn2=""):
regclass.get_next_schedule()
return regclass.add_class(crn1, crn2)
-
def find_time_conflicts(regclass, courses):
""" given a list of courses, checks current and next schedule for time conflicts """
schedules = [regclass.schedule, regclass.next_schedule]
@@ -5,6 +5,14 @@
<h1>Schedule</h1>
<h2>{{term}}</h2>
+{% if messages %}
+<ul class="messages">
+ {% for message in messages %}
+ <li{% if message.tags %} class="{{message.tags }}"{% endif %}>{{message}}</li>
+ {% endfor %}
+</ul>
+{% endif %}
+
{% block header %}
<link rel="stylesheet" type="text/css" href="/site_media/stylesheets/make_schedule.css"/>
@@ -58,7 +66,9 @@ <h2>{{term}}</h2>
{% endfor %}
</table>
</div>
-
+
+ {% comment %} Course information table with drop course checkboxes {% endcomment %}
+ <form action="." method="post">
<table>
<tr>
<th>Class</th>
@@ -68,7 +78,7 @@ <h2>{{term}}</h2>
<th>Location</th>
<th>Days</th>
<th>Time</th>
- <th>CRN</th>
+ <th><input type="submit" name="dropform" value="Drop"</th>
</tr>
{% for course in schedule %}
<tr>
@@ -79,9 +89,10 @@ <h2>{{term}}</h2>
<td>{{course.location.building}} {{course.location.room}}</td>
<td>{{course.days|join:"" }}</td>
<td>{{course.times|join:"-" }}</td>
- <td>{{course.crn}}</td>
+ <td><input type="checkbox" name="drop" value={{course.crn}}></td>
</tr>
{% endfor %}
+ </form>
</table>
</div>
View
@@ -1,15 +1,32 @@
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
+from django.contrib import messages
+from django.template import RequestContext, Template
import simplejson as json
from reglib.utilities import utilities
# Create your views here.
def index(request):
+ """ gets current term's schedule and handles dropping of courses """
+
regclass = request.session['regclass']
- schedule = regclass.schedule.current_classes
+ # to print term to screen
term = utilities.adjust_schedule_term(regclass.schedule.current_term)
term = utilities.format_term(term, True)
+
+ # if user post a form to drop classes
+ if request.method == 'POST':
+ crn_list_drop = request.POST.getlist('drop')
+ success = regclass.drop_classes(crn_list_drop)
+ if success:
+ messages.success(request, "Successfully dropped course(s)")
+ else:
+ messages.error(request, "There was an error dropping course(s)")
+ regclass.get_current_schedule() # refresh
+
+ # get schedule
+ schedule = regclass.schedule.current_classes
schedule_json = json.dumps(schedule)
no_courses = False
@@ -18,13 +35,28 @@ def index(request):
if no_courses:
return render_to_response('schedule/no_course.html', {'current_term': True, 'term': term})
- return render_to_response('schedule/index.html', {'schedule':schedule, 'term':term, 'range':range(24), 'json':schedule_json, 'current_term': True})
+ return render_to_response('schedule/index.html', {'schedule':schedule, 'term':term, 'range':range(24), 'json':schedule_json, 'current_term': True}, context_instance=RequestContext(request))
+
def next_term(request):
+ """ gets next term's schedule and handles dropping of courses """
+
regclass = request.session['regclass']
- schedule = regclass.next_schedule.current_classes
+ # to print term to screen
term = utilities.adjust_schedule_term(regclass.next_schedule.current_term)
term = utilities.format_term(term, True)
+
+ # if user post a form to drop classes
+ if request.method == 'POST':
+ crn_list_drop = request.POST.getlist('drop')
+ success = regclass.drop_classes(crn_list_drop, True)
+ if success:
+ messages.success(request, "Successfully dropped course(s)")
+ else:
+ messages.error(request, "There was an error dropping course(s)")
+ regclass.get_next_schedule() # refresh
+
+ schedule = regclass.next_schedule.current_classes
schedule_json = json.dumps(schedule)
no_courses = False
@@ -33,7 +65,7 @@ def next_term(request):
if no_courses:
return render_to_response('schedule/no_course.html', {'current_term': False})
- return render_to_response('schedule/index.html', {'schedule':schedule, 'term':term, 'range':range(24), 'json':schedule_json, 'current_term': False})
+ return render_to_response('schedule/index.html', {'schedule':schedule, 'term':term, 'range':range(24), 'json':schedule_json, 'current_term': False}, context_instance=RequestContext(request))
View
@@ -31,6 +31,7 @@ def index(request):
# register
courses_copy = courses[:] # copy this guy because he's gonna get popped to hell
+ regclass.drop_all_classes()
success_list = register(regclass, courses)
# display confimation or error message if register success/fail

0 comments on commit c95b95b

Please sign in to comment.