def post(self,request,pk,*args,**kwargs): resource = Resource.objects.get(pk=pk) part = request.POST['part'] discount,created = DiscountPart.objects.get_or_create(resource=resource,part=part) template = get_template('numbas_lti/management/discount/discounted.html') html = template.render({'resource':resource,'discount':discount,'form':forms.DiscountPartBehaviourForm(instance=discount),'path':part}) return JsonResponse({'pk':discount.pk,'created':created, 'behaviour': discount.behaviour, 'html':html})
def row(q, p=None, g=None): qnum = int(q) + 1 path = 'q{}'.format(q) if p is not None: pletter = string.ascii_lowercase[int(p)] path += 'p{}'.format(p) if g is not None: path += 'g{}'.format(g) else: pletter = None out = { 'q': qnum, 'p': pletter, 'g': g, 'path': path, } if p is not None: discount = DiscountPart.objects.filter(resource=resource, part=path).first() out.update({ 'discount': discount, 'form': forms.DiscountPartBehaviourForm(instance=discount) }) return out
def row(q,p,g,qnum,path,pletter,**kwargs): out = { 'q': qnum, 'p': pletter, 'g': g, 'path': path, } if p is not None: discount = DiscountPart.objects.filter(resource=resource,part=path).first() out.update({ 'discount': discount, 'form': forms.DiscountPartBehaviourForm(instance=discount) }) return out