示例#1
0
 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})
示例#2
0
        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
示例#3
0
        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