Beispiel #1
0
class CategoryActions(BaseActions):
    """Category actions used by view function `category`"""

    form = None

    def _get_form(self):
        self.form = CaseCategoryForm(self.request.POST)
        self.form.populate(product_id=self.product_id)
        return self.form

    # todo: the caller checks the wrong permissions
    def update(self):
        is_valid, form = self._check_form_validation()
        if not is_valid:
            return form

        category_pk = self.request.POST.get('o_category')
        # FIXME: no exception hanlder when pk does not exist.
        category = Category.objects.get(pk=category_pk)

        testcases = self.get_testcases()
        for testcase in testcases:
            testcase.category = category
            testcase.save()
        return JsonResponse(self.ajax_response)

    def render_form(self):
        form = CaseCategoryForm(
            initial={
                'product': self.product_id,
                'category': self.request.POST.get('o_category'),
            })
        form.populate(product_id=self.product_id)

        return HttpResponse(form.as_p())
Beispiel #2
0
    def render_form(self):
        form = CaseCategoryForm(initial={
            'product': self.product_id,
            'category': self.request.REQUEST.get('o_category'),
        })
        form.populate(product_id=self.product_id)

        return HttpResponse(form.as_p())
Beispiel #3
0
    def render_form(self):
        form = CaseCategoryForm(initial={
            'product': self.product_id,
            'category': self.request.POST.get('o_category'),
        })
        form.populate(product_id=self.product_id)

        return HttpResponse(form.as_p())
Beispiel #4
0
class CategoryActions(BaseActions):
    '''Category actions used by view function `category`'''

    def __get_form(self):
        self.form = CaseCategoryForm(self.request.REQUEST)
        self.form.populate(product_id=self.product_id)
        return self.form

    def __check_form_validation(self):
        form = self.__get_form()
        if not form.is_valid():
            return 0, self.render_ajax(forms.errors_to_list(form))

        return 1, form

    def __check_perms(self, perm):
        return 1, True

    def update(self):
        is_valid, perm = self.__check_perms('change')
        if not is_valid:
            return perm

        is_valid, form = self.__check_form_validation()
        if not is_valid:
            return form

        category_pk = self.request.REQUEST.get('o_category')
        # FIXME: no exception hanlder when pk does not exist.
        category = TestCaseCategory.objects.get(pk=category_pk)
        # FIXME: lower performance. It's not necessary to update each TestCase
        # in this way.
        tcs = self.get_testcases()
        for tc in tcs:
            tc.category = category
            tc.save()
        return self.render_ajax(self.ajax_response)

    def render_ajax(self, response):
        return HttpResponse(simplejson.dumps(self.ajax_response))

    def render_form(self):
        form = CaseCategoryForm(initial={
            'product': self.product_id,
            'category': self.request.REQUEST.get('o_category'),
        })
        form.populate(product_id=self.product_id)

        return HttpResponse(form.as_p())
Beispiel #5
0
class CategoryActions(BaseActions):
    '''Category actions used by view function `category`'''
    def __get_form(self):
        self.form = CaseCategoryForm(self.request.REQUEST)
        self.form.populate(product_id=self.product_id)
        return self.form

    def __check_form_validation(self):
        form = self.__get_form()
        if not form.is_valid():
            return 0, self.render_ajax(forms.errors_to_list(form))

        return 1, form

    def __check_perms(self, perm):
        return 1, True

    def update(self):
        is_valid, perm = self.__check_perms('change')
        if not is_valid:
            return perm

        is_valid, form = self.__check_form_validation()
        if not is_valid:
            return form

        category_pk = self.request.REQUEST.get('o_category')
        # FIXME: no exception hanlder when pk does not exist.
        category = TestCaseCategory.objects.get(pk=category_pk)
        # FIXME: lower performance. It's not necessary to update each TestCase
        # in this way.
        tcs = self.get_testcases()
        for tc in tcs:
            tc.category = category
            tc.save()
        return self.render_ajax(self.ajax_response)

    def render_ajax(self, response):
        return HttpResponse(simplejson.dumps(self.ajax_response))

    def render_form(self):
        form = CaseCategoryForm(
            initial={
                'product': self.product_id,
                'category': self.request.REQUEST.get('o_category'),
            })
        form.populate(product_id=self.product_id)

        return HttpResponse(form.as_p())
Beispiel #6
0
 def __get_form(self):
     self.form = CaseCategoryForm(self.request.REQUEST)
     self.form.populate(product_id=self.product_id)
     return self.form
Beispiel #7
0
 def _get_form(self):
     self.form = CaseCategoryForm(self.request.POST)
     self.form.populate(product_id=self.product_id)
     return self.form