Commit 37e0591a authored by EL HASSANE GARGEM's avatar EL HASSANE GARGEM
Browse files

contact us page

parent 57af9eb3
......@@ -26,7 +26,7 @@ class BootstrapFormMixin():
class_ += ' form-control'
if issubclass(field.widget.__class__, forms.Select):
class_ += ' custom-select'
if field.widget.input_type == 'select':
if hasattr(field.widget,'input_type') and field.widget.input_type == 'select':
field.widget.need_label = True
field.widget.attrs['class'] = class_
......
......@@ -6,7 +6,7 @@ from django.contrib import messages
from django.utils.translation import ngettext
from users.models import User, ResearchField, Invitation
from users.models import User, ResearchField, Invitation, ContactUs
class MyUserChangeForm(UserChangeForm):
......@@ -62,3 +62,5 @@ class InvitationAdmin(admin.ModelAdmin):
admin.site.register(User, MyUserAdmin)
admin.site.register(ResearchField)
admin.site.register(Invitation, InvitationAdmin)
admin.site.register(ContactUs)
......@@ -3,7 +3,7 @@ from django.contrib.auth.forms import UserChangeForm, UserCreationForm
from django.utils.translation import gettext as _
from bootstrap.forms import BootstrapFormMixin
from users.models import Invitation, User
from users.models import Invitation, User, ContactUs
class InvitationForm(BootstrapFormMixin, forms.ModelForm):
......@@ -52,3 +52,11 @@ class ProfileForm(BootstrapFormMixin, forms.ModelForm):
class Meta:
model = User
fields = ('email', 'first_name', 'last_name')
class ContactUsForm(BootstrapFormMixin, forms.ModelForm):
class Meta:
model = ContactUs
fields = ('name','subject','email','message')
# Generated by Django 2.1.4 on 2020-08-20 16:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('users', '0008_auto_20200520_1007'),
]
operations = [
migrations.CreateModel(
name='ContactUs',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=255)),
('subject', models.CharField(max_length=255)),
('email', models.EmailField(max_length=255, verbose_name='email address')),
('message', models.TextField()),
],
),
]
......@@ -133,3 +133,43 @@ class Invitation(models.Model):
_('{username} accepted your invitation!').format(
username=self.recipient.username),
level='success')
class ContactUs(models.Model):
"""
Represents Contact Us form
"""
name = models.CharField(max_length=255)
subject = models.CharField(max_length=255)
email = models.EmailField(
verbose_name=_('email address'),
max_length=255,
)
message = models.TextField()
class Meta:
verbose_name ="message"
verbose_name_plural = "messages"
def __str__(self):
return "from {}({})".format(self.name,self.email)
def save(self, *args, **kwargs):
context = {
"sender_name": self.name,
"sender_email": self.email,
"message": self.message,
"subject": self.subject
}
send_email(
'users/email/contactus_subject.txt',
'users/email/contactus_message.txt',
'users/email/contactus_html.html',
'elhassanegargem@gmail.com',
context=context,
result_interface=None
)
super().save(*args, **kwargs)
from django.urls import path, include
from users.views import SendInvitation, AcceptInvitation, Profile
from users.views import SendInvitation, AcceptInvitation, Profile, ContactUsView
from django.contrib.auth.decorators import permission_required
urlpatterns = [
path('', include('django.contrib.auth.urls')),
path('profile/', Profile.as_view(), name='user_profile'),
path('contact/', ContactUsView.as_view(), name='contactus'),
path('invite/',
permission_required('users.can_invite', raise_exception=True)(SendInvitation.as_view()),
name='send-invitation'),
......
from os import listdir, stat
from os.path import isfile, join, relpath
from django.shortcuts import reverse
from django.conf import settings
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.messages.views import SuccessMessageMixin
......@@ -12,8 +12,8 @@ from django.views.generic.edit import CreateView, UpdateView
from rest_framework.authtoken.models import Token
from users.models import User, Invitation
from users.forms import InvitationForm, InvitationAcceptForm, ProfileForm
from users.models import User, Invitation, ContactUs
from users.forms import InvitationForm, InvitationAcceptForm, ProfileForm, ContactUsForm
class SendInvitation(LoginRequiredMixin, SuccessMessageMixin, CreateView):
......@@ -103,3 +103,15 @@ class Profile(SuccessMessageMixin, UpdateView):
context['is_paginated'] = paginator.count != 0
context['page_obj'] = paginator.get_page(page_number)
return context
class ContactUsView(SuccessMessageMixin, CreateView):
model = ContactUs
form_class = ContactUsForm
success_message = _('Your message successfully sent.')
template_name = 'users/contactus.html'
def get_success_url(self):
return reverse('home')
......@@ -616,3 +616,7 @@ i.panel-icon {
.cmp-del {
color: red;
}
#contact-form{
width: 100%;
}
\ No newline at end of file
......@@ -47,7 +47,7 @@
<a class="nav-link" href="#">{% trans 'About' %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">{% trans 'Contact' %}</a>
<a class="nav-link" href="{% url 'contactus' %}">{% trans 'Contact' %}</a>
</li>
{% comment %}
......
<p>Hello escriptorium Admin</p>
<p>{{sender_name}} wants to send you a message, you will find it bellow.</br>
{{message}}
<p>You can contact him on this email : {{ sender_email }}</p>
<p>Sincerely, the eScriptorium team.</p>
Dear escriptorium Admin,
{{sender_name}} wants to send you a message, you will find it bellow.
{{message}}
You can contact him on this email : {{ sender_email }}
Sincerely, the eScriptorium team.
Supports Markdown
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