Beispiel #1
0
def client_add(request):
  client_query = request.GET.get('q', '')
  if client_query:
    return HttpResponseRedirect(reverse('schedule-client', args=[client_query,]))

  context_vars = dict()
  context_vars['header'] = capfirst(_('schedule'))
  
  context_vars['client_form'] = RootPageClientForm(prefix='client')
  context_vars['address_form'] = RootPageAddressForm(prefix='address')

  if request.method == "POST":
    client_form = RootPageClientForm(request.POST, prefix='client')
    address_form = RootPageAddressForm(request.POST, prefix='address')
    if client_form.is_valid() and address_form.is_valid():
      client = client_form.save()
      address_form = RootPageAddressForm(request.POST, prefix='address', instance=client.address)
      address_form.save()
      client.postal_address.postcode = client.address.postcode
      client.postal_address.address = client.address.address
      client.postal_address.city = client.address.city
      client.postal_address.county = client.address.county
      client.postal_address.country = client.address.country
      client.postal_address.latitude = client.address.latitude
      client.postal_address.longitude = client.address.longitude
      client.postal_address.save()
      if settings.WORKFLOWMAX_APIKEY and settings.WORKFLOWMAX_ACCOUNTKEY:
        client.wm_sync()
      messages.success(request, capfirst(_('client was created successfully')), fail_silently=True)
      return HttpResponseRedirect(reverse('schedule-client-byid', args=[client.id]))

  context_vars['staff_list'] = Staff.objects.all()
  return direct_to_template(request, template='schedule/root.html', extra_context=context_vars)
Beispiel #2
0
def client_edit(request, client_id):
  client_query = request.GET.get('q', '')
  if client_query:
    return HttpResponseRedirect(reverse('schedule-client', args=[client_query,]))

  context_vars = dict()
  context_vars['header'] = capfirst(_('schedule'))
  
  try:
    client = Client.objects.get(id=client_id)
    context_vars['client_form'] = RootPageClientForm(prefix='client', instance=client)
    context_vars['address_form'] = RootPageAddressForm(prefix='address', instance=client.address)

    if request.method == "POST":
      client_form = RootPageClientForm(request.POST, prefix='client', instance=client)
      address_form = RootPageAddressForm(request.POST, prefix='address', instance=client.address)
      if client_form.is_valid() and address_form.is_valid():
        client = client_form.save()
        address_form.save()
        if settings.WORKFLOWMAX_APIKEY and settings.WORKFLOWMAX_ACCOUNTKEY:
          client.wm_sync()
        messages.success(request, capfirst(_('client was modified successfully')), fail_silently=True)
        return HttpResponseRedirect(reverse('schedule-client-byid', args=[client.id]))
  except ObjectDoesNotExist:
    return HttpResponseRedirect(reverse('schedule-client', args=[client_name,]))      

  context_vars['staff_list'] = Staff.objects.all()
  return direct_to_template(request, template='schedule/root.html', extra_context=context_vars)