Exemple #1
0
def contact_show(request, key_name):
  entry = ContactMessage.get(key_name)
  area = 'contact'
  
  c = template.RequestContext(request, locals())
  _flag_as_admin(c)
  return render_to_response('contact_entry.html', c)
Exemple #2
0
def contact_form(request):
  contact_form = loader.render_to_string("contact_form.html", {"form":ContactForm()})
  tpl = ContactMessage.get_intro()
  contact_content = tpl.replace('{{form}}', contact_form)
  model=ContactMessage

  if request.method == 'POST':
    form = ContactForm(request.POST)
    if form.is_valid():
      item = form.save()
      msg_key = "success_%s_new" % ContactForm._meta.model.object_name()
      message = util.get_message(msg_key, 'success_content_new')
      util.success(request, message)
      return http.HttpResponseRedirect(ContactMessage.form_url())

  c = template.RequestContext(request, locals())
  return render_to_response('contact_send.html', c)
Exemple #3
0
def email_contact(name, email, message):
  params = {'name':name, 'email':email, 'message':message}
  message = mail.get_mail_message('mail_contact.txt', **params)
  html_message = mail.get_mail_message('mail_contact.html', **params)
  
  subject = "Contact: %s (%s)" % (name, email)
  for to_mail in ContactMessage.get_mails():
    mail.send_mail(to_mail, subject, message, html_message=html_message)
Exemple #4
0
 def save(self):
   ContactMessage.set_mails(self.cleaned_data['mails'])
   ContactMessage.set_intro(self.cleaned_data['intro'])
Exemple #5
0
 def __init__(self, *args, **kwargs):
   super(ContactSettings, self).__init__(*args, **kwargs)
   self.fields['mails'].initial = ', '.join(ContactMessage.get_mails())
   self.fields['intro'].initial = ContactMessage.get_intro()
def contact_index(request):

    # Create objects for context

    # Retrieve contact points (social media, github, etc.)
    contact_points = ContactPoint.objects.order_by('n_page_order')
    # Create empty form
    contact_form = ContactForm()

    if request.method == 'POST':
        contact_form = ContactForm(request.POST)
        if contact_form.is_valid():
            # Get value of input from spam check field
            spam_check = contact_form.cleaned_data['spam_check']

            # Check spam check input
            if not spam_check:
                # Create email contents
                # Get the person's name
                name = contact_form.cleaned_data['name']
                # Create the email subject using their name
                subject = 'New message from ' + name
                # Get the person's message
                message = contact_form.cleaned_data['message']

                # Before emailing, write message to DB so that it is not lost if the email fails
                contact_message = ContactMessage(t_name=name,
                                                 t_message=message)
                # Save the message to the DB
                contact_message.save()
                # Try sending the email
                try:
                    # Send email using send_mail function
                    send_mail(subject,
                              message,
                              settings.EMAIL_HOST_USER,
                              ['*****@*****.**'],
                              fail_silently=False)
                    # Add code here for success message
                    messages.success(request, 'Message sent!')
                    return HttpResponseRedirect('/contact/')
                except BadHeaderError:
                    # Add code here for failure message
                    messages.failure(request, 'Uhh, what are you doing?')
                    return HttpResponseRedirect('/contact/')
                except Exception as e:
                    print(e)
                    # Display this anyway - we at least stored the message
                    # Could add code to email admin that message was saved, but not emailed
                    messages.success(request, 'Your message was sent!')
                    return HttpResponseRedirect('/contact/')
            else:
                messages.success(request, 'Message sent! ;)')
                return HttpResponseRedirect('/contact/')
        else:
            return HttpResponseRedirect('/contact/')
    # Anything but a POST request
    else:
        # Create context
        context = {
            'contact_points': contact_points,
            'contact_form': contact_form,
        }

    # Return request with context
    return render(request, 'contact_index.html', context)
Exemple #7
0
def get_content():
  return {"Contact Form":[{"name":"Contact us", "url":ContactMessage.form_url()}]}