Commit 1e7ee690 authored by Anton Petrov's avatar Anton Petrov
Browse files

Flat pages and contact form

parent 0f34af20
from django import forms
from rnacentral import local_settings
class ContactForm(forms.Form):
subject = forms.CharField(max_length=100)
message = forms.CharField()
sender = forms.EmailField()
cc_myself = forms.BooleanField(required=False)
def send_email(self):
subject = '[RNAcentral Contact Us] ' + self.cleaned_data['subject']
message = self.cleaned_data['message']
sender = self.cleaned_data['sender']
recipients = [ local_settings.EMAIL_RNACENTRAL_HELPDESK ]
if self.cleaned_data['cc_myself']:
recipients.append(sender)
from django.core.mail import send_mail
send_mail(subject, message, sender, recipients)
......@@ -74,7 +74,7 @@
<script src="{% static "js/main.js" %}"></script>
<script>
$('form').on('submit', function(){
$('form.global-search').on('submit', function(){
window.location.href = '/search?q=' + $('#search').val();
return false;
});
......
{% extends "portal/base.html" %}
{% block title %}
Contact Us
{% endblock %}
{% block content %}
<div class="row">
<br>
<div class="col-md-8">
<h2>Contact us</h2>
<form action="/contact/" method="post" role="form">{% csrf_token %}
{{ form.non_field_errors }}
<div class="form-group {% if form.subject.errors %} has-error {% endif %}" >
{% if form.subject.errors %}
<label class="control-label" for="emailSubject">Email subject ({{ form.subject.errors|striptags }})</label>
{% else %}
<label for="emailSubject">Email subject</label>
{% endif %}
<input type="text" autofocus class="form-control" name="subject" id="emailSubject" placeholder="Enter subject" tabindex="1"
{% if form.subject.errors %}value="{{ form.subject.value }}"{% endif %}>
</div>
<div class="form-group {% if form.message.errors %} has-error {% endif %}" >
{% if form.message.errors %}
<label class="control-label" for="emailMessage">Your message ({{ form.message.errors|striptags }})</label>
{% else %}
<label for="emailSubject">Your message</label>
{% endif %}
<textarea type="text" class="form-control" name="message" id="emailMessage" placeholder="" tabindex="2" rows="4">{% if form.message.errors %}{{ form.message.value }}{% endif %}</textarea>
</div>
<div class="form-group">
<div class="form-group {% if form.sender.errors %} has-error {% endif %}" >
{% if form.sender.errors %}
<label class="control-label" for="emailSender">Your email address ({{ form.sender.errors|striptags }})</label>
{% else %}
<label for="emailSender">Your email address</label>
{% endif %}
<input type="email" class="form-control" name="sender" id="emailSender" placeholder="" tabindex="3"
{% if form.sender.errors %}value={{ form.sender.value }}{% endif %}>
</div>
<div class="checkbox">
{{ form.cc_myself.errors }}
<label>
<input type="checkbox" name="cc_myself" tabindex="4"> CC yourself?
</label>
</div>
<button type="submit" class="btn btn-primary" tabindex="5">Submit</button>
</form>
</div>
</div>
{% endblock %}
\ No newline at end of file
......@@ -20,7 +20,6 @@
</div>
<div class="col-md-4">
Sidebar
</div>
</div>
......
......@@ -11,7 +11,6 @@
</div>
<div class="col-md-4">
Sidebar
</div>
</div>
......
{% extends "portal/base.html" %}
{% block content %}
<div class="row">
<br>
<div class="col-md-8">
<h2>Your query has been submitted</h2>
<p>
The RNAcentral helpdesk will get back to you as soon as possible.
</p>
</div>
<div class="col-md-4">
</div>
</div>
{% endblock %}
\ No newline at end of file
......@@ -63,10 +63,10 @@
<div class="col-md-2">
<h3 class="about">Information</h3>
<ul>
<li><a href="/about" target="_blank">About RNAcentral</a></li>
<li><a href="/about">About RNAcentral</a></li>
<li><a href="http://rnajournal.cshlp.org/content/17/11/1941.full" target="_blank">RNAcentral vision paper</a></li>
<li><a href="/help">Help</a></li>
<li><a href="#">Contact us</a></li>
<li><a href="/contact">Contact us</a></li>
</ul>
</div>
......
......@@ -11,11 +11,11 @@
</div>
<div class="col-md-8 col-md-offset-1">
<form name="rnacentral-search" action="[search-action]" method="post">
<form name="rnacentral-search" action="[search-action]" method="post" class="global-search">
<fieldset>
<div class="input-group">
<input type="text" placeholder="Search terms" class="form-control" id="search">
<input type="text" placeholder="Search terms" class="form-control" id="search" tabindex=1>
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-search"></span> <span class="caret"></span></button>
<ul class="dropdown-menu pull-right">
......@@ -60,7 +60,7 @@
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="/help">Help</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="/contact">Contact</a></li>
<li><a href="#">Share</a></li>
</ul>
</div><!--/.nav-collapse -->
......
from portal.models import Rna, Database, Release, Xref
from rest_framework import viewsets
from portal.serializers import RnaSerializer, XrefSerializer
from portal.forms import ContactForm
from django.http import HttpResponse, Http404
from django.http import HttpResponse, Http404, HttpResponseRedirect
from django.shortcuts import render
from django.db.models import Count, Min, Max
from django.views.generic.base import TemplateView
from django.template import TemplateDoesNotExist
from django.views.generic.edit import FormView
class RnaViewSet(viewsets.ReadOnlyModelViewSet):
......@@ -53,4 +55,16 @@ class StaticView(TemplateView):
try:
return response.render()
except TemplateDoesNotExist:
raise Http404()
\ No newline at end of file
raise Http404()
class ContactView(FormView):
template_name = 'portal/contact.html'
form_class = ContactForm
success_url = '/thanks/'
def form_valid(self, form):
# This method is called when valid form data has been POSTed.
# It should return an HttpResponse.
form.send_email()
return HttpResponseRedirect('/thanks/')
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.',
'NAME': '',
'USER': '',
'PASSWORD': '',
'OPTIONS' : { 'init_command' : 'SET storage_engine=MyISAM', },
}
}
TEMPLATE_DIRS = (
'',
)
EMAIL_HOST = ''
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT =
EMAIL_USE_TLS = True
EMAIL_RNACENTRAL_HELPDESK = ''
SECRET_KEY = ''
ADMINS = (
('', ''),
)
......@@ -39,7 +39,7 @@ SITE_ID = 1
# If you set this to False, Django will make some optimizations so as not
# to load the internationalization machinery.
USE_I18N = True
USE_I18N = False
# If you set this to False, Django will not format dates, numbers and
# calendars according to the current locale.
......@@ -83,7 +83,7 @@ STATICFILES_FINDERS = (
)
# Make this unique, and don't share it with anybody.
SECRET_KEY = '5(nbgvg6y$c^@@yi-#2zz^vydfwu@f19-7cm7dkfp1x+la**i6'
SECRET_KEY = ''
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
......@@ -100,9 +100,7 @@ MIDDLEWARE_CLASSES = (
'django.contrib.messages.middleware.MessageMiddleware',
# Uncomment the next line for simple clickjacking protection:
# 'django.middleware.clickjacking.XFrameOptionsMiddleware',
# django-debug-toolbar
'debug_toolbar.middleware.DebugToolbarMiddleware',
'debug_toolbar.middleware.DebugToolbarMiddleware', # django-debug-toolbar
)
ROOT_URLCONF = 'rnacentral.urls'
......
......@@ -10,18 +10,15 @@ router.register(r'rna', views.RnaViewSet)
urlpatterns = patterns('',
url(r'^$', 'portal.views.index'),
url(r'^rna/(?P<upi>\w+)$', 'portal.views.rna_view'),
# haystack search
url(r'^search/', include('haystack.urls')),
# admin
url(r'^admin/', include(admin.site.urls)),
# flat pages
url(r'^(?P<page>about|help)/$', views.StaticView.as_view()),
url(r'^(?P<page>about|help|thanks)/$', views.StaticView.as_view()),
# contact us
url(r'^contact/$', views.ContactView.as_view()),
# API
url(r'^api/v1/', include(router.urls)),
url(r'^api-auth/v1/', include('rest_framework.urls', namespace='rest_framework'))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment