def add_client(request): context_vars = dict() context_vars['header'] = capfirst(_('add new client')) form = ClientForm() helper = FormHelper() helper.form_class = 'uniform' submit = Submit('save',_('save')) helper.add_input(submit) if request.method == "POST": form = ClientForm(request.POST, request.FILES) if form.is_valid(): client = Client() client.name = form.cleaned_data['name'] client.address = form.cleaned_data['address'] client.postal_address = form.cleaned_data['postal_address'] client.phone = form.cleaned_data['phone'] client.fax = form.cleaned_data['fax'] client.website = form.cleaned_data['website'] client.referral_source = form.cleaned_data['referral_source'] client = client.save() return HttpResponseRedirect(reverse('workflowmax-client', args=[client.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: wm_client = WorkflowmaxClient() if self.wm_id: wm_client.id = int(self.wm_id) wm_client.name = self.name wm_client.address = str(self.address) wm_client.postal_address = str(self.postal_address) wm_client.phone = self.phone wm_client.fax = self.fax wm_client.website = self.website wm_client.referral_source = self.referral_source wm_client = wm_client.save() if not self.wm_id: self.wm_id = wm_client.id self.save() if self.contacts.all(): for contact in self.contacts.all(): contact.wm_sync()