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)
Beispiel #3
0
def root(request, client_name=None, client_id=None, add_job=False):
  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:
    staff = Staff.objects.get(user_ptr=request.user)
    context_vars['staff'] = staff
  except ObjectDoesNotExist:
    staff = None

  client = None
  if client_id:
    try:
      client = Client.objects.get(id=client_id)
    except ObjectDoesNotExist:
      return HttpResponseRedirect(reverse('schedule-root'))
    
  if client_name:
    clients = Client.objects.search(client_name)
    if clients:
      if len(clients) == 1:
        client = clients[0]
      else:
        context_vars['clients'] = clients
    else:
      context_vars['client_form'] = RootPageClientForm(prefix='client', instance=Client(name=client_name))
      context_vars['client_form'].action = reverse('schedule-client-add')
      context_vars['address_form'] = RootPageAddressForm(prefix='address')

  if client:
    context_vars['client'] = client
    try:
      job = client.jobs.latest()
    except ObjectDoesNotExist:
      add_job = True
    if add_job:
      job_form = RootPageAddJobForm()
      helper = FormHelper()
      helper.set_form_action('%s?return_to=%s' % (reverse('job-add'), reverse('schedule-client-byid', args=[client.id,])))
      submit = Submit('save',_('save'))
      helper.add_input(submit)
      layout = Layout( 
        HTML('<h3>%s</h3>' % capfirst(_('job details'))),
        'description', 'type',
        HTML('<h3>%s</h3>' % capfirst(_('time and staff'))),
        'start_date', 'due_date', 'staff'
        )
      helper.add_layout(layout)

      context_vars['job_form'] = job_form
      client_input = Hidden('client', client.id)
      helper.add_input(client_input)
      context_vars['helper'] = helper
    else:                
      context_vars['job_edit_form'] = RootPageEditJobForm(instance=job)
      editjob_helper = FormHelper()
      editjob_helper.set_form_action('%s?return_to=%s' % (reverse('job-edit', args=[job.id]), reverse('schedule-client-byid', args=[client.id,])))
      submit = Submit('save',_('save'))
      editjob_helper.add_input(submit)
      recomended_staff_html = ''
      for s in ['%s, ' % staff for staff in job.get_valid_staff()]: recomended_staff_html +=s
      layout = Layout( 
        'state', 
        Row(HTML('<span style="color:red">Recommended: %s</span>' % recomended_staff_html), HTML('<a href="%s">%s</a>' % (reverse('staff-add'), _('add new'))), 'staff'),
        )
      editjob_helper.add_layout(layout)
      context_vars['edit_job_helper'] = editjob_helper
        
  context_vars['staff_list'] = Staff.objects.all()
  return direct_to_template(request, template='schedule/root.html', extra_context=context_vars)