def proceed(self): category = get_category_by_slug(self.slug) results = [] if not self._errors: try: table = self._wb[self._wb.sheetnames[0]] data = list(table) if self._not_valid_header(data[0]): self._errors.append(_('File has wrong content')) return for row in data[1:]: data = {} for index, item in enumerate(list(row)): if not index and not item.value: self._errors.append(self.required_field_error) if item.value: data[self.header_fields_choices[index] [1]] = item.value data['category'] = category.pk results.append(data) if not results: self._errors.append(self.no_data_error) if not self._errors: for result in results: form = TaskForm(result) if form.is_valid(): form.save() else: self._errors.append(form.errors.items()) except IndexError: self._errors.append(self.content_error) except (ValidationError, IntegrityError) as error: self._errors.append(str(error))
def post(self, *args, **kwargs): form = TaskForm(self.request.POST) if form.is_valid(): task = form.save(commit=False) task.user = self.request.user if is_task_not_overlapped(task): task.save() return redirect(task) return redirect('tasks:add_task')
def create_tasks(request): if request.method == 'POST': form = TaskForm(request.POST) if form.is_valid(): task = form.save(commit=False) task.created_by = request.user task.save() return HttpResponseRedirect(reverse('read-project', args=(task.project.title_slug,))) else: form = TaskForm() params = {'form':form, 'user': request.user } params.update(csrf(request)) return render_to_response('tasks/task_form.html', params)
def post(self, *args, **kwargs): task_id = kwargs.get('task_id') task = get_object_or_404(Task, pk=task_id) old_start, old_end = task.start, task.end condition = (task.user is not self.request.user) and (not self.request.user.is_superuser) if (task.user.id is not self.request.user.id) and (not self.request.user.is_superuser): raise PermissionDenied form = TaskForm(self.request.POST, instance=task) if form.is_valid(): task = form.save(commit=False) if is_task_not_overlapped(task, id=task.id): task.save() return redirect(task) return redirect('tasks:task_edit', {'task_id': task_id})
def post(self, request, pk, **kwargs): form = TaskForm(request.POST) if form.is_valid(): object = Task( name=form.cleaned_data.get('name'), description=form.cleaned_data.get('description'), ) object.save() object.subject.add(Subject.objects.get(pk=pk)) return HttpResponse( json.dumps({ 'success': 1 }), content_type="application/json" ) else: return HttpResponse( json.dumps({ 'success': 0, 'errors': dict(form.errors.items()), }), content_type="application/json" )