Exemple #1
0
 def get_form(self, form_class):
     form = super(CategoryCreateView, self).get_form(form_class)
     case_templates = get_contract(self.request).case_templates.all() if not self.request.user.is_superuser\
         else Template.objects.all()
     form_templates = [t.id for t in case_templates if not t.readonly]
     form.fields['template'].queryset = case_templates.filter(id__in=form_templates)
     form.fields['template'].empty_label = None
     form.fields['parent_category'].queryset = Category.objects.filter(template__id__in=form_templates,
                                                                       parent_category__isnull=True)
     return form
Exemple #2
0
 def get_queryset(self):
     try:
         contract = get_contract(self.request)
         template_pk = self.request.resolver_match.kwargs.get('template_pk', None)
         if template_pk:
             template = Template.objects.get(pk=template_pk, contract=contract)
             return Category.objects.filter(template=template)
         else:
             return Category.objects.filter(template__in=contract.case_templates.all())
     except:
         return Category.objects.all()
Exemple #3
0
 def get_queryset(self):
     try:
         contract = get_contract(self.request)
         return contract.template.categories.all()
     except:
         return Category.objects.all()