def ajax_delete_demonstration_form(request, course_id, demonstration_id): demonstration = get_object_or_404(Demonstration, pk=demonstration_id) item = demonstration.item if not request.user.has_perm( 'grades.delete_grade') and not item.marking_period.active: # you aren't a registrar, so you can't modify an inactive marking period return HttpResponse(status=403) ghost_item = Item() ghost_item.course = item.course ghost_item.category = item.category ghost_item.marking_period = item.marking_period message = '%s deleted' % (demonstration, ) demonstration.delete() # TODO: degrossify if not Demonstration.objects.filter(item=item): if Mark.objects.filter(item=item): raise Exception( 'Stray marks found after attempting to delete last demonstration.' ) else: # the last demonstration is dead. kill the item. item.delete() gradebook_recalculate_on_item_change(ghost_item) messages.success(request, message) return HttpResponse('SUCCESS')
def ajax_delete_item_form(request, course_id, item_id): item = get_object_or_404(Item, pk=item_id) ghost_item = Item() ghost_item.course = item.course ghost_item.category = item.category ghost_item.marking_period = item.marking_period message = '%s deleted' % (item, ) item.delete() gradebook_recalculate_on_item_change(ghost_item) messages.success(request, message) return HttpResponse('SUCCESS')
def ajax_delete_item_form(request, course_id, item_id): item = get_object_or_404(Item, pk=item_id) ghost_item = Item() ghost_item.course = item.course ghost_item.category = item.category ghost_item.marking_period = item.marking_period message = '%s deleted' % (item,) item.delete() gradebook_recalculate_on_item_change(ghost_item) messages.success(request, message) return HttpResponse('SUCCESS')
def ajax_delete_item_form(request, course_id, item_id): item = get_object_or_404(Item, pk=item_id) if not request.user.has_perm('grades.delete_grade') and not item.marking_period.active: # you aren't a registrar, so you can't modify an inactive marking period return HttpResponse(status=403) ghost_item = Item() ghost_item.course = item.course ghost_item.category = item.category ghost_item.marking_period = item.marking_period message = '%s deleted' % (item,) item.delete() gradebook_recalculate_on_item_change(ghost_item) messages.success(request, message) return HttpResponse('SUCCESS')
def ajax_delete_item_form(request, course_id, item_id): item = get_object_or_404(Item, pk=item_id) if not request.user.has_perm( 'grades.delete_grade') and not item.marking_period.active: # you aren't a registrar, so you can't modify an inactive marking period return HttpResponse(status=403) ghost_item = Item() ghost_item.course = item.course ghost_item.category = item.category ghost_item.marking_period = item.marking_period message = '%s deleted' % (item, ) item.delete() gradebook_recalculate_on_item_change(ghost_item) messages.success(request, message) return HttpResponse('SUCCESS')
def ajax_delete_demonstration_form(request, course_id, demonstration_id): demonstration = get_object_or_404(Demonstration, pk=demonstration_id) item = demonstration.item ghost_item = Item() ghost_item.course = item.course ghost_item.category = item.category ghost_item.marking_period = item.marking_period message = '%s deleted' % (demonstration,) demonstration.delete() if not Demonstration.objects.filter(item=item): if Mark.objects.filter(item=item): raise Exception('Stray marks found after attempting to delete last demonstration.') else: # the last demonstration is dead. kill the item. item.delete() gradebook_recalculate_on_item_change(ghost_item) messages.success(request, message) return HttpResponse('SUCCESS')
def ajax_delete_demonstration_form(request, course_id, demonstration_id): demonstration = get_object_or_404(Demonstration, pk=demonstration_id) item = demonstration.item ghost_item = Item() ghost_item.course = item.course ghost_item.category = item.category ghost_item.marking_period = item.marking_period message = '%s deleted' % (demonstration, ) demonstration.delete() if not Demonstration.objects.filter(item=item): if Mark.objects.filter(item=item): raise Exception( 'Stray marks found after attempting to delete last demonstration.' ) else: # the last demonstration is dead. kill the item. item.delete() gradebook_recalculate_on_item_change(ghost_item) messages.success(request, message) return HttpResponse('SUCCESS')
def ajax_delete_demonstration_form(request, course_id, demonstration_id): demonstration = get_object_or_404(Demonstration, pk=demonstration_id) item = demonstration.item if not request.user.has_perm('grades.delete_grade') and not item.marking_period.active: # you aren't a registrar, so you can't modify an inactive marking period return HttpResponse(status=403) ghost_item = Item() ghost_item.course = item.course ghost_item.category = item.category ghost_item.marking_period = item.marking_period message = '%s deleted' % (demonstration,) demonstration.delete() if not Demonstration.objects.filter(item=item): if Mark.objects.filter(item=item): raise Exception('Stray marks found after attempting to delete last demonstration.') else: # the last demonstration is dead. kill the item. item.delete() gradebook_recalculate_on_item_change(ghost_item) messages.success(request, message) return HttpResponse('SUCCESS')
def ajax_get_demonstration_form(request, course_id, demonstration_id=None): ''' the transaction decorator helps, but people can still hammer the submit button and create tons of assignments. for some reason, only one shows up right away, and the rest don't appear until reload ''' course = get_object_or_404(Course, pk=course_id) lists = None if request.POST: if demonstration_id: # modifying an existing demonstration demonstration = get_object_or_404(Demonstration, pk=demonstration_id) old_demonstration = get_object_or_404(Demonstration, pk=demonstration_id) form = DemonstrationForm(request.POST, instance=demonstration, prefix="demonstration") if not request.user.has_perm('grades.change_grade') and not demonstration.item.marking_period.active: # you aren't a registrar, so you can't modify a demonstration from an inactive marking period form.fields['item'].validators.append( make_validationerror_raiser('This demonstration belongs to the inactive marking period {}.'.format(demonstration.item.marking_period)) ) else: # creating a new demonstration form = DemonstrationForm(request.POST, prefix="demonstration") if not request.user.has_perm('grades.add_grade'): # you aren't a registrar, so make sure you can only select items in active marking periods form.fields['item'].validators.append(require_item_in_active_marking_period) if form.is_valid(): demonstration = form.save() if demonstration_id is None: # a new demonstration; must create blank marks for each student for student in Student.objects.filter(course=course): mark, created = Mark.objects.get_or_create(item=demonstration.item, demonstration=demonstration, student=student) else: # do we belong to a different Item? if old_demonstration.item_id != demonstration.item_id: # update all our Marks to reference the new Item for mark in Mark.objects.filter(demonstration=demonstration): mark.item = demonstration.item mark.save() # recalculate both Items gradebook_recalculate_on_item_change(demonstration.item, old_item=old_demonstration.item) # is the old Item totally abandoned now? if not old_demonstration.item.demonstration_set.count(): if old_demonstration.item.mark_set.count(): raise Exception('Stray Marks found after attempting to reassign last Demonstration.') else: # no Demonstrations are left. kill the Item. old_demonstration.item.delete() # Should I use the django message framework to inform the user? # This would not work in ajax unless we make some sort of ajax # message handler. messages.success(request, '%s saved' % (demonstration,)) return HttpResponse('SUCCESS') else: if demonstration_id: demonstration = get_object_or_404(Demonstration, pk=demonstration_id) form = DemonstrationForm(instance=demonstration, prefix="demonstration") # TODO: remove TC hard-coding if demonstration.item.category.name == 'Standards': students_missing = Student.objects.filter(mark__demonstration=demonstration, mark__mark__lt=3) if not students_missing: students_missing = ('None',) lists = ({'heading':'Students Missing This Demonstration', 'items':students_missing},) else: form = DemonstrationForm(initial={'course': course}, prefix="demonstration") form.fields['item'].queryset = Item.objects.filter(course=course, category__display_in_gradebook=True, category__allow_multiple_demonstrations=True) return render_to_response('benchmark_grade/demonstration_form_fragment.html', { 'form': form, 'demonstration_id': demonstration_id, 'lists': lists, }, RequestContext(request, {}),)
def ajax_get_item_form(request, course_id, item_id=None): ''' the transaction decorator helps, but people can still hammer the submit button and create tons of assignments. for some reason, only one shows up right away, and the rest don't appear until reload ''' course = get_object_or_404(Course, pk=course_id) item = None lists = None if request.POST: if item_id: # modifying an existing item item = get_object_or_404(Item, pk=item_id) original_course_id = item.course_id form = ItemForm(request.POST, instance=item, prefix="item") if not request.user.has_perm('grades.change_grade') and not item.marking_period.active: # you aren't a registrar, so you can't modify an item from an inactive marking period form.fields['marking_period'].validators.append( make_validationerror_raiser('This item belongs to the inactive marking period {}.'.format(item.marking_period)) ) if original_course_id != long(form.data['item-course']): # don't support moving items between courses form.fields['course'].validators.append( make_validationerror_raiser('Please click "Make a Copy" if you would like to add this item to another course.') ) else: # creating a new item form = ItemForm(request.POST, prefix="item") if not request.user.has_perm('grades.add_grade'): # registrars should have this, as opposed to change_own_grade # restrict regular teachers to the active marking period try: form.fields['marking_period'].validators.append(require_active_marking_period) except KeyError: pass # field was disabled by user configuration if form.is_valid(): with reversion.create_revision(): if item_id is None: # a new item! item = form.save() dem = None if item.category.allow_multiple_demonstrations: # must have at least one demonstration; create a new one dem = Demonstration() dem.name = 'Dem. 1' dem.item = item dem.save() # must create blank marks for each student for student in Student.objects.filter(course=course): mark, created = Mark.objects.get_or_create(item=item, student=student, demonstration=dem) else: # modifying an existing item old_item = Item.objects.get(pk=item.pk) item = form.save() gradebook_recalculate_on_item_change(item, old_item=old_item) reversion.set_user(request.user) reversion.set_comment("gradebook") # Should I use the django message framework to inform the user? # This would not work in ajax unless we make some sort of ajax # message handler. messages.success(request, '%s saved' % (item,)) return HttpResponse('SUCCESS') else: if item_id: item = get_object_or_404(Item, pk=item_id) form = ItemForm(instance=item, prefix="item") # TODO: remove TC hard-coding try: Category.objects.get(name='Standards') # are we in TC land? if item.category.name == 'Standards': students_missing = Student.objects.filter(mark__item=item).annotate(best_mark=Max('mark__mark')).filter(best_mark__lt=3) if not students_missing: students_missing = ('None',) lists = ({'heading':'Students Missing This Item', 'items':students_missing},) except Category.DoesNotExist: pass_letters = Configuration.get_or_default("Letter Passing Grade").value.split(',') pass_number = float(Configuration.get_or_default("Passing Grade").value) / 100 # yay, assumptions students_missing = Student.objects.filter(mark__item=item).annotate(best_mark=Max('mark__normalized_mark')).filter(best_mark__lt=pass_number) text_missing = [] for student in students_missing: if item.mark_set.get(student=student).letter_grade in pass_letters: continue text_missing.append(u'{} / {} ({:.0f}%) {}'.format( student.best_mark * float(item.points_possible), item.points_possible, student.best_mark * 100, unicode(student))) lists = ({'heading':'Students Missing This Item', 'items':text_missing},) else: active_mps = course.marking_period.filter(active=True) if active_mps: form = ItemForm(initial={'course': course, 'marking_period':active_mps[0]}, prefix="item") else: form = ItemForm(initial={'course': course}, prefix="item") # some fields may have been disabled by user configuration try: form.fields['marking_period'].queryset = course.marking_period.all() except KeyError: pass try: form.fields['category'].queryset = Category.objects.filter(display_in_gradebook=True) except KeyError: pass try: form.fields['benchmark'].queryset = Benchmark.objects.filter() except KeyError: pass available_courses = get_teacher_courses(request.user.username) if (not available_courses or not len(available_courses)) and request.user.has_perm('grades.change_grade'): available_courses = Course.objects.all() try: form.fields['course'].queryset = available_courses except KeyError: pass try: form.fields['category'].widget.attrs = { 'onchange': "Dajaxice.ecwsp.benchmark_grade.check_fixed_points_possible(Dajax.process, {'category':this.value})"} if item and item.category.fixed_points_possible: form.fields['points_possible'].widget.attrs = {'disabled': 'true'} except KeyError: pass return render_to_response('sis/gumby_modal_form.html', { 'my_form': form, 'item_id': item_id, 'lists': lists, }, RequestContext(request, {}),)
def ajax_get_item_form(request, course_id, item_id=None): ''' the transaction decorator helps, but people can still hammer the submit button and create tons of assignments. for some reason, only one shows up right away, and the rest don't appear until reload ''' course = get_object_or_404(Course, pk=course_id) item = None lists = None if request.POST: if item_id: # modifying an existing item item = get_object_or_404(Item, pk=item_id) form = ItemForm(request.POST, instance=item, prefix="item") if not request.user.has_perm('grades.change_grade') and not item.marking_period.active: # you aren't a registrar, so you can't modify an item from an inactive marking period form.fields['marking_period'].validators.append( make_validationerror_raiser('This item belongs to the inactive marking period {}.'.format(item.marking_period)) ) else: # creating a new item form = ItemForm(request.POST, prefix="item") if not request.user.has_perm('grades.add_grade'): # registrars should have this, as opposed to change_own_grade # restrict regular teachers to the active marking period form.fields['marking_period'].validators.append(require_active_marking_period) if form.is_valid(): with reversion.create_revision(): if item_id is None: # a new item! item = form.save() dem = None if item.category.allow_multiple_demonstrations: # must have at least one demonstration; create a new one dem = Demonstration() dem.name = 'Dem. 1' dem.item = item dem.save() # must create blank marks for each student for student in Student.objects.filter(course=course): mark, created = Mark.objects.get_or_create(item=item, student=student, demonstration=dem) else: # modifying an existing item old_item = Item.objects.get(pk=item.pk) item = form.save() gradebook_recalculate_on_item_change(item, old_item=old_item) reversion.set_user(request.user) reversion.set_comment("gradebook") # Should I use the django message framework to inform the user? # This would not work in ajax unless we make some sort of ajax # message handler. messages.success(request, '%s saved' % (item,)) return HttpResponse('SUCCESS') else: if item_id: item = get_object_or_404(Item, pk=item_id) form = ItemForm(instance=item, prefix="item") # TODO: remove TC hard-coding if item.category.name == 'Standards': students_missing = Student.objects.filter(mark__item=item).annotate(best_mark=Max('mark__mark')).filter(best_mark__lt=3) if not students_missing: students_missing = ('None',) lists = ({'heading':'Students Missing This Item', 'items':students_missing},) else: active_mps = course.marking_period.filter(active=True) if active_mps: form = ItemForm(initial={'course': course, 'marking_period':active_mps[0]}, prefix="item") else: form = ItemForm(initial={'course': course}, prefix="item") form.fields['marking_period'].queryset = course.marking_period.all() form.fields['category'].queryset = Category.objects.filter(display_in_gradebook=True) form.fields['benchmark'].queryset = Benchmark.objects.filter() form.fields['category'].widget.attrs = { 'onchange': "Dajaxice.ecwsp.benchmark_grade.check_fixed_points_possible(Dajax.process, {'category':this.value})"} if item and item.category.fixed_points_possible: form.fields['points_possible'].widget.attrs = {'disabled': 'true'} return render_to_response('sis/gumby_modal_form.html', { 'my_form': form, 'item_id': item_id, 'lists': lists, }, RequestContext(request, {}),)
def ajax_get_item_form(request, course_id, item_id=None): ''' the transaction decorator helps, but people can still hammer the submit button and create tons of assignments. for some reason, only one shows up right away, and the rest don't appear until reload ''' course = get_object_or_404(Course, pk=course_id) item = None lists = None if request.POST: if item_id: item = get_object_or_404(Item, pk=item_id) form = ItemForm(request.POST, instance=item, prefix="item") else: form = ItemForm(request.POST, prefix="item") if form.is_valid(): with reversion.create_revision(): if item_id is None: # a new item! item = form.save() dem = None if item.category.allow_multiple_demonstrations: # must have at least one demonstration; create a new one dem = Demonstration() dem.name = 'Dem. 1' dem.item = item dem.save() # must create blank marks for each student for student in Student.objects.filter(course=course): mark, created = Mark.objects.get_or_create( item=item, student=student, demonstration=dem) else: # modifying an existing item old_item = Item.objects.get(pk=item.pk) item = form.save() gradebook_recalculate_on_item_change(item, old_item=old_item) reversion.set_user(request.user) reversion.set_comment("gradebook") # Should I use the django message framework to inform the user? # This would not work in ajax unless we make some sort of ajax # message handler. messages.success(request, '%s saved' % (item, )) return HttpResponse('SUCCESS') else: if item_id: item = get_object_or_404(Item, pk=item_id) form = ItemForm(instance=item, prefix="item") # TODO: remove TC hard-coding if item.category.name == 'Standards': students_missing = Student.objects.filter( mark__item=item).annotate( best_mark=Max('mark__mark')).filter(best_mark__lt=3) if not students_missing: students_missing = ('None', ) lists = ({ 'heading': 'Students Missing This Item', 'items': students_missing }, ) else: active_mps = course.marking_period.filter(active=True) if active_mps: form = ItemForm(initial={ 'course': course, 'marking_period': active_mps[0] }, prefix="item") else: form = ItemForm(initial={'course': course}, prefix="item") form.fields['marking_period'].queryset = course.marking_period.all() form.fields['category'].queryset = Category.objects.filter( display_in_gradebook=True) form.fields['benchmark'].queryset = Benchmark.objects.filter() form.fields['category'].widget.attrs = { 'onchange': "Dajaxice.ecwsp.benchmark_grade.check_fixed_points_possible(Dajax.process, {'category':this.value})" } if item and item.category.fixed_points_possible: form.fields['points_possible'].widget.attrs = {'disabled': 'true'} return render_to_response( 'sis/generic_form_fragment.html', { 'form': form, 'item_id': item_id, 'lists': lists, }, RequestContext(request, {}), )
def ajax_get_demonstration_form(request, course_id, demonstration_id=None): ''' the transaction decorator helps, but people can still hammer the submit button and create tons of assignments. for some reason, only one shows up right away, and the rest don't appear until reload ''' course = get_object_or_404(Course, pk=course_id) lists = None if request.POST: if demonstration_id: # modifying an existing demonstration demonstration = get_object_or_404(Demonstration, pk=demonstration_id) old_demonstration = get_object_or_404(Demonstration, pk=demonstration_id) form = DemonstrationForm(request.POST, instance=demonstration, prefix="demonstration") if not request.user.has_perm( 'grades.change_grade' ) and not demonstration.item.marking_period.active: # you aren't a registrar, so you can't modify a demonstration from an inactive marking period form.fields['item'].validators.append( make_validationerror_raiser( 'This demonstration belongs to the inactive marking period {}.' .format(demonstration.item.marking_period))) else: # creating a new demonstration form = DemonstrationForm(request.POST, prefix="demonstration") if not request.user.has_perm('grades.add_grade'): # you aren't a registrar, so make sure you can only select items in active marking periods form.fields['item'].validators.append( require_item_in_active_marking_period) if form.is_valid(): demonstration = form.save() if demonstration_id is None: # a new demonstration; must create blank marks for each student for student in Student.objects.filter(course=course): mark, created = Mark.objects.get_or_create( item=demonstration.item, demonstration=demonstration, student=student) else: # do we belong to a different Item? if old_demonstration.item_id != demonstration.item_id: # update all our Marks to reference the new Item for mark in Mark.objects.filter( demonstration=demonstration): mark.item = demonstration.item mark.save() # recalculate both Items gradebook_recalculate_on_item_change( demonstration.item, old_item=old_demonstration.item) # is the old Item totally abandoned now? if not old_demonstration.item.demonstration_set.count(): if old_demonstration.item.mark_set.count(): raise Exception( 'Stray Marks found after attempting to reassign last Demonstration.' ) else: # no Demonstrations are left. kill the Item. old_demonstration.item.delete() # Should I use the django message framework to inform the user? # This would not work in ajax unless we make some sort of ajax # message handler. messages.success(request, '%s saved' % (demonstration, )) return HttpResponse('SUCCESS') else: if demonstration_id: demonstration = get_object_or_404(Demonstration, pk=demonstration_id) form = DemonstrationForm(instance=demonstration, prefix="demonstration") # TODO: remove TC hard-coding if demonstration.item.category.name == 'Standards': students_missing = Student.objects.filter( mark__demonstration=demonstration, mark__mark__lt=3) if not students_missing: students_missing = ('None', ) lists = ({ 'heading': 'Students Missing This Demonstration', 'items': students_missing }, ) else: form = DemonstrationForm(initial={'course': course}, prefix="demonstration") form.fields['item'].queryset = Item.objects.filter( course=course, category__display_in_gradebook=True, category__allow_multiple_demonstrations=True) return render_to_response( 'benchmark_grade/demonstration_form_fragment.html', { 'form': form, 'demonstration_id': demonstration_id, 'lists': lists, }, RequestContext(request, {}), )