def add_job(request): context_vars = dict() context_vars['header'] = capfirst(_('add new job')) form = AddJobForm() helper = FormHelper() helper.form_class = 'uniform' submit = Submit('save',_('save')) helper.add_input(submit) if request.method == "POST": form = AddJobForm(request.POST, request.FILES) if form.is_valid(): job = Job() job.name = form.cleaned_data['name'] job.description = form.cleaned_data['description'] job.start_date = strptime(form.cleaned_data['start_date'], '%Y%m%d') job.due_date = strptime(form.cleaned_data['due_date'], '%Y%m%d') client_id = form.cleaned_data['client'] client = Client.objects.get(id=client_id) job.clients = [client,] job = job.save() return HttpResponseRedirect(reverse('workflowmax-job', args=[job.id])) context_vars['form'] = form context_vars['helper'] = helper return direct_to_template(request, template='workflowmax/form.html', extra_context=context_vars)
def wm_sync(self): if self.name and self.description and self.start_date and self.due_date and self.client and self.client.wm_id: wm_job = WorkflowmaxJob() if self.wm_id: wm_job = WorkflowmaxJob.objects.get(id=self.wm_id) # wm_job.state = self.state.name wm_job.name = self.name wm_job.description = self.description wm_job.start_date = self.start_date wm_job.due_date = self.due_date wm_client = WorkflowmaxClient.objects.get(id=self.client.wm_id) wm_job.clients = [wm_client,] wm_job = wm_job.save() if not self.wm_id: self.wm_id = wm_job.id self.save() if self.staff.all(): wm_job.assigned = [] for staff in self.staff.all(): try: wm_job.assigned.append(WorkflowmaxStaff.objects.get(id=staff.wm_id)) except ResponseStatusError: pass wm_job.save()