예제 #1
0
파일: views.py 프로젝트: KateKate/aceplace
def customer_letter(request, pk):
  location = get_object_or_404(models.Locations, id=pk)
  if request.method == 'POST':
    form = forms.LetterToCutomerForm(request.POST)
    form_image = forms.ImageToSelect(location, request.POST)
    if form.is_valid() and form_image.is_valid():
      form = form.cleaned_data
      s_getvalue, zip_filename = pack_to_zip(location, form_image.cleaned_data['image_select'])
      subject = u'Aceplace | %s' % location.title
      html_message = render_to_string('email/email_letter_with_images.html', dict(form=form, location=location))
      from_email = settings.EMAIL_HOST_USER
      recipient_list = form['customer_email']
      email = EmailMessage(subject, html_message, from_email, recipient_list, None)
      email.attach(zip_filename, s_getvalue, 'application/zip')
      email.content_subtype = "html"
      email.send()
      thank_you = render_to_string('popup/success/letter_to_customer.html')
      return HttpResponse(
        json.dumps({'response': thank_you, 'result': 'success'}),
        content_type='application/json'
      )
    else:
      response = {}
      for k, v in form.errors.items():
        response[k] = v[0]
      return HttpResponse(
        json.dumps({'response': response, 'result': 'error'}),
        content_type='application/json'
      )
  else:
    return render(
      request,
      'popup/letter_to_customer.html',
      {'form': forms.LetterToCutomerForm(),
       'form_image': forms.ImageToSelect(location),
       'location': location }
    )
예제 #2
0
파일: views.py 프로젝트: KateKate/aceplace
def image_load(request, pk):
  location = get_object_or_404(models.Locations, id=pk)
  # images = location.locatadminimages_set.all()
  if request.method == 'POST':
    form_image = forms.ImageToSelect(location, request.POST)
    if form_image.is_valid():
      s_getvalue, zip_filename = pack_to_zip(location, form_image.cleaned_data['image_select'])
      response = HttpResponse(s_getvalue, content_type = "application/x-zip-compressed")
      response['Content-Disposition'] = 'attachment; filename=%s' % zip_filename
      return response
    else:
      response = {}
      for k, v in form_image.errors.items():
        response[k] = v[0]
      return HttpResponse(
        json.dumps({'response': response, 'result': 'error'}),
        content_type='application/json'
      )
  else:
    return render(
      request,
      'popup/location_image_load.html',
      {'form_image': forms.ImageToSelect(location), 'location': location}
    )