OneLab Contact Us form created. Email to be tested from dev machine.
authorYasin <mohammed-yasin.rahman@lip6.fr>
Thu, 25 Jul 2013 14:16:18 +0000 (16:16 +0200)
committerYasin <mohammed-yasin.rahman@lip6.fr>
Thu, 25 Jul 2013 14:16:18 +0000 (16:16 +0200)
portal/forms.py
portal/models.py
portal/templates/contact.html [new file with mode: 0644]
portal/templates/contact_sent.html [new file with mode: 0644]
portal/urls.py
portal/views.py

index 513b952..f28a9ed 100644 (file)
@@ -5,6 +5,7 @@
 #
 # Authors:
 #   Jordan Augé <jordan.auge@lip6.fr>
+#   Mohammed-Yasin Rahman <mohammed-yasin.rahman@lip6.fr>
 # Copyright 2013, UPMC Sorbonne Universités / LIP6
 #
 # This program is free software; you can redistribute it and/or modify it under
@@ -49,6 +50,11 @@ class UserRegisterForm(forms.Form): # Not ModelForm
                                  max_length=30,
                                  label=_("Last name"),
                                  error_messages={'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
+    affiliation = forms.RegexField(regex=r'^[\w.@+-]+$',
+                             max_length=30,
+                             label=_("Affiliation"),
+                             error_messages={'invalid': _("This value may contain only letters, numbers and @/./+/-/_ characters.")})
+
     email = forms.EmailField(label=_("E-mail"))
     password1 = forms.CharField(widget=forms.PasswordInput,
                                 label=_("Password"))
@@ -106,3 +112,12 @@ class SliceRequestForm(forms.ModelForm):
 # DEPRECATED #class RegisterUserStep2Form(forms.ModelForm):
 # DEPRECATED #    class Meta:
 # DEPRECATED #        model = PendingUser
+
+class ContactForm(forms.Form):
+    first_name = forms.CharField()
+    last_name = forms.CharField()
+    affiliation = forms.CharField()
+    subject = forms.CharField(max_length=100)
+    message = forms.CharField(widget=forms.Textarea)
+    email = forms.EmailField()
+    cc_myself = forms.BooleanField(required=False)
index da0e086..0dcbc6d 100644 (file)
@@ -210,6 +210,7 @@ class PendingUser(models.Model):
     # simplify form creation in forms.py
     first_name  = models.TextField()
     last_name   = models.TextField()
+    affiliation = models.TextField()
     email       = models.EmailField() #validators=[validate_email])
     password    = models.TextField()
     keypair     = models.TextField()
diff --git a/portal/templates/contact.html b/portal/templates/contact.html
new file mode 100644 (file)
index 0000000..f9e2e4e
--- /dev/null
@@ -0,0 +1,22 @@
+{% extends "layout-unfold1.html" %}
+{% load i18n %}
+
+{% block head %}
+{{ wizard.form.media }}
+{% endblock %}
+
+{% block unfold1_main %}
+
+
+<div style=" padding-top: 12px; background-color: orange; border: 1px solid #61210B; text-align: center;">
+         <h3>Onelab Support</h3>
+         <h3>If you have already registered then send an <a href="mailto:support@myslice.info"> e-mail </a>  or <a href="http://trac.myslice.info/" >visit us</a></h3>
+</div>
+
+<form action="#" method="post">{% csrf_token %}
+{{ form.as_p }}
+<input type="submit" value="Submit" />
+</form>
+
+{% endblock %}
+
diff --git a/portal/templates/contact_sent.html b/portal/templates/contact_sent.html
new file mode 100644 (file)
index 0000000..ca12d5f
--- /dev/null
@@ -0,0 +1,9 @@
+{% extends "layout-unfold1.html" %}
+
+{% block unfold1_main %}
+
+  <h1>Query Received !</h1>
+
+We will study your problem and get back to you as soon as possible.
+{% endblock %}
+
index 53d4b7c..1cb551e 100644 (file)
@@ -42,6 +42,7 @@ urlpatterns = patterns('',
     # User validation
     url(r'^user/validate/?$', UserValidateView.as_view(), name='user_validate'),
     url(r'^dashboard/?$', DashboardView.as_view(), name='dashboard'),
+    url(r'^contact/?$', views.contact),
     # Slice request
     #url(r'^slice/request/?$',  views.slice_request,  name='slice_request'),
     # Slice confirmation
index 597f319..c3466d4 100644 (file)
@@ -5,6 +5,7 @@
 #
 # Authors:
 #   Jordan Augé <jordan.auge@lip6.fr>
+#   Mohammed Yasin Rahman <mohammed-yasin.rahman@lip6.fr>
 # Copyright 2013, UPMC Sorbonne Universités / LIP6
 #
 # This program is free software; you can redistribute it and/or modify it under
@@ -28,12 +29,13 @@ from django.views.generic.base   import TemplateView
 from django.shortcuts            import render
 from plugins.lists.simplelist    import SimpleList
 from portal                      import signals
-from portal.forms                import UserRegisterForm, SliceRequestForm
+from portal.forms                import UserRegisterForm, SliceRequestForm, ContactForm
 from portal.util                 import RegistrationView, ActivationView
 from portal.models               import PendingUser, PendingSlice
 from manifold.core.query         import Query
 from unfold.page                 import Page
 from myslice.viewutils           import topmenu_items, the_user
+from django.http                 import HttpResponseRedirect
 
 class DashboardView(TemplateView):
     template_name = "dashboard.html"
@@ -153,8 +155,10 @@ class UserRegisterView(RegistrationView):
         """
         first_name = cleaned_data['first_name']
         last_name  = cleaned_data['last_name']
+        affiliation= cleaned_data['affiliation']
         email      = cleaned_data['email']
         password   = cleaned_data['password1']
+        
         #password2  = cleaned_data['password2']
         keypair    = cleaned_data['keypair']
 
@@ -420,3 +424,33 @@ class UserValidateView(ActivationView):
 # DEPRECATED #    p << wizard.render(request) # in portal page if possible
 # DEPRECATED #
 # DEPRECATED #    return p.render()
+
+
+# view for contact form
+def contact(request):
+    if request.method == 'POST': # If the form has been submitted...
+        form = ContactForm(request.POST) # A form bound to the POST data
+        if form.is_valid(): # All validation rules pass
+            # Process the data in form.cleaned_data
+            first_name = form.cleaned_data['first_name']
+            last_name = form.cleaned_data['last_name']
+            affiliation = form.cleaned_data['affiliation']
+            subject = form.cleaned_data['subject']
+            message = form.cleaned_data['message']
+            email = form.cleaned_data['email']
+            cc_myself = form.cleaned_data['cc_myself']
+
+            recipients = ['yasin.upmc@gmail.com']
+            if cc_myself:
+                recipients.append(sender)
+
+            from django.core.mail import send_mail
+            send_mail(subject, message, email, recipients)
+            return render(request,'contact_sent.html') # Redirect after POST
+    else:
+        form = ContactForm() # An unbound form
+
+    return render(request, 'contact.html', {
+        'form': form,
+    })
+