예제 #1
0
    def post(self, request):

        form = CampaignForm(request.POST, initial={"manager": request.user})
        form.instance.manager = request.user

        if not form.is_valid():
            return {"error": True, "errors": get_all_form_errors(form)}

        try:
            form.save(commit=True)
        except IntegrityError:
            return {"error": True, "errors": [u"Такая кампания есть в базе данных"]}

        return {"error": False}
예제 #2
0
    def post(self, request):

        """ Обновить информацию о компании """

        try:
            campaign = Campaign.objects.get(pk=request.POST.get('campaign_id'), manager=request.user)
        except Campaign.DoesNotExist:
            return {'error': True, 'errors': [u'Неизвестная кампания']}


        form = CampaignForm(request.POST, instance=campaign)
        if not form.is_valid():
            return {'error': True, 'errors': get_all_form_errors(form)}

        form.save(commit=True)

        return {'error': False}