contact form
This commit is contained in:
parent
e9fad9eabf
commit
d5bd8d2da8
13 changed files with 96 additions and 0 deletions
0
app/contact/__init__.py
Normal file
0
app/contact/__init__.py
Normal file
2
app/contact/admin.py
Normal file
2
app/contact/admin.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
from django.contrib import admin
|
||||
|
6
app/contact/apps.py
Normal file
6
app/contact/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
|||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class ContactConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'app.contact'
|
7
app/contact/forms.py
Normal file
7
app/contact/forms.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
from django import forms
|
||||
from django.conf import settings
|
||||
|
||||
class ContactForm(forms.Form):
|
||||
email = forms.EmailField(label='EMail', required=False)
|
||||
message = forms.CharField(label='Message', required=True)
|
||||
|
0
app/contact/migrations/__init__.py
Normal file
0
app/contact/migrations/__init__.py
Normal file
2
app/contact/models.py
Normal file
2
app/contact/models.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
from django.db import models
|
||||
|
3
app/contact/tests.py
Normal file
3
app/contact/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
20
app/contact/views.py
Normal file
20
app/contact/views.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
from django.shortcuts import render
|
||||
|
||||
from . import forms
|
||||
from . import models
|
||||
|
||||
def index(request):
|
||||
context = {
|
||||
}
|
||||
if request.method == 'POST':
|
||||
form = forms.ContactForm(request.POST)
|
||||
if form.is_valid():
|
||||
message = 'From: %s\n\n%s' % (form.cleaned_data['email'], form.cleaned_data['message'])
|
||||
subject = 'Phantas.ma/polis contact message'
|
||||
from_ = settings.CONTACT_FROM_EMAIL
|
||||
to = settings.CONTACT_TO_EMAIL
|
||||
msg = EmailMessage(subject, message, from_, to, reply_to=[form.cleaned_data['email']])
|
||||
msg.send(fail_silently=True)
|
||||
else:
|
||||
context['form'] = form
|
||||
return render(request, 'contact.html', context)
|
|
@ -41,6 +41,7 @@ INSTALLED_APPS = [
|
|||
'app.user',
|
||||
'app.video',
|
||||
'app.text',
|
||||
'app.contact',
|
||||
|
||||
]
|
||||
|
||||
|
@ -148,6 +149,9 @@ DEFAULT_PANDORA_API = "https://pad.ma/api/"
|
|||
|
||||
URL_PREFIX = 'polis+'
|
||||
|
||||
CONTACT_TO_EMAIL = 'polis@phantas.ma'
|
||||
CONTACT_FROM_EMAIL = 'polis@phantas.ma'
|
||||
|
||||
try:
|
||||
from .local_settings import *
|
||||
except ImportError:
|
||||
|
|
27
app/static/css/partials/_contact.scss
Normal file
27
app/static/css/partials/_contact.scss
Normal file
|
@ -0,0 +1,27 @@
|
|||
main > .contact {
|
||||
max-width: var(--container-lg-width);
|
||||
margin: 0 auto;
|
||||
padding: var(--spacing-2);
|
||||
|
||||
h1 {
|
||||
font-size: 22px;
|
||||
margin: 0 0 var(--spacing) 0;
|
||||
}
|
||||
|
||||
input[type=email], textarea {
|
||||
border: 0;
|
||||
background: blue;
|
||||
color: red;
|
||||
font-size: 20px;
|
||||
line-height: 1.3;
|
||||
}
|
||||
textarea {
|
||||
width: 500px;
|
||||
height: 300px;
|
||||
}
|
||||
input[type=submit] {
|
||||
border: 0;
|
||||
background: green;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,3 +8,4 @@
|
|||
@import "partials/text";
|
||||
@import "partials/ascroll";
|
||||
@import "partials/about";
|
||||
@import "partials/contact";
|
||||
|
|
22
app/templates/contact.html
Normal file
22
app/templates/contact.html
Normal file
|
@ -0,0 +1,22 @@
|
|||
{% extends "base.html" %}
|
||||
{% block title %}Contact 聯絡{% endblock title %}
|
||||
{% block body_class%}animated animated-text{% endblock %}
|
||||
{% block main %}
|
||||
<div class="contact">
|
||||
<h1>Contact 聯絡</h1>
|
||||
<form method="post">
|
||||
<label>
|
||||
Your Email:
|
||||
<input name="email" type="email" required>
|
||||
</label>
|
||||
<br>
|
||||
<label>Message 訊息:<br>
|
||||
<textarea name="message" required></textarea>
|
||||
</label>
|
||||
<br>
|
||||
<input type="submit" value="Send Message">
|
||||
{% csrf_token %}
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
@ -19,6 +19,7 @@ from django.conf import settings
|
|||
|
||||
from .video import views as video
|
||||
from .text import views as text
|
||||
from .contact.views import index as contact
|
||||
|
||||
urlpatterns = [
|
||||
path('admin/', admin.site.urls),
|
||||
|
@ -34,6 +35,7 @@ urlpatterns = [
|
|||
path(settings.URL_PREFIX + 'assemblies/<str:slug>', text.text, name='text'),
|
||||
#path(settings.URL_PREFIX + 'index-alt/', text.index_alt, name='index_alt'),
|
||||
path(settings.URL_PREFIX + 'about/', text.about, name='about'),
|
||||
path(settings.URL_PREFIX + 'contact/', contact, name='contact'),
|
||||
path(settings.URL_PREFIX + '<str:slug>/', text.page, name='page'),
|
||||
path(settings.URL_PREFIX[:-1], text.index, name='index'),
|
||||
path('', text.fallback, name='fallback'),
|
||||
|
|
Loading…
Reference in a new issue