Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
scripta
eScriptorium
Commits
b5841ce1
Commit
b5841ce1
authored
Aug 28, 2020
by
EL HASSANE GARGEM
Browse files
Merge branch 'contact' into 'develop'
Contact Us See merge request
!47
parents
57af9eb3
cd6d0570
Changes
16
Hide whitespace changes
Inline
Side-by-side
app/apps/bootstrap/forms.py
View file @
b5841ce1
...
...
@@ -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_
...
...
app/apps/users/admin.py
View file @
b5841ce1
...
...
@@ -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
)
app/apps/users/forms.py
View file @
b5841ce1
from
django
import
forms
from
django.contrib.auth.forms
import
UserChangeForm
,
UserCreationForm
from
django.utils.translation
import
gettext
as
_
from
captcha.fields
import
CaptchaField
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 +53,14 @@ class ProfileForm(BootstrapFormMixin, forms.ModelForm):
class
Meta
:
model
=
User
fields
=
(
'email'
,
'first_name'
,
'last_name'
)
class
ContactUsForm
(
BootstrapFormMixin
,
forms
.
ModelForm
):
message
=
forms
.
CharField
(
label
=
"Message : Please precise your institution or research center if applicable"
,
widget
=
forms
.
Textarea
(
attrs
=
{
'placeholder'
:
'Message : Please precise your institution or research center if applicable'
}))
captcha
=
CaptchaField
()
class
Meta
:
model
=
ContactUs
fields
=
(
'name'
,
'email'
,
'message'
,
'captcha'
)
app/apps/users/migrations/0009_contactus.py
0 → 100644
View file @
b5841ce1
# 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
()),
],
),
]
app/apps/users/models.py
View file @
b5841ce1
...
...
@@ -133,3 +133,41 @@ 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
)
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
,
}
send_email
(
'users/email/contactus_subject.txt'
,
'users/email/contactus_message.txt'
,
'users/email/contactus_html.html'
,
settings
.
ADMINS
,
context
=
context
,
result_interface
=
None
)
super
().
save
(
*
args
,
**
kwargs
)
app/apps/users/urls.py
View file @
b5841ce1
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'
),
...
...
app/apps/users/views.py
View file @
b5841ce1
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,14 @@ 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'
success_url
=
'/contact/'
app/escriptorium/settings.py
View file @
b5841ce1
...
...
@@ -62,6 +62,7 @@ INSTALLED_APPS = [
'rest_framework'
,
'rest_framework.authtoken'
,
'compressor'
,
'captcha'
,
'bootstrap'
,
'versioning'
,
...
...
app/escriptorium/static/css/escriptorium.css
View file @
b5841ce1
...
...
@@ -616,3 +616,7 @@ i.panel-icon {
.cmp-del
{
color
:
red
;
}
#contact-form
{
width
:
100%
;
}
\ No newline at end of file
app/escriptorium/templates/base.html
View file @
b5841ce1
...
...
@@ -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 %}
...
...
app/escriptorium/templates/users/contactus.html
0 → 100644
View file @
b5841ce1
{% extends "base.html" %}
{% load i18n bootstrap static %}
{% block body %}
<div
class=
"container"
>
<div
class=
"row"
>
<form
id=
"contact-form"
method=
"post"
>
{% csrf_token %}
<fieldset>
<div
class=
"form-group"
>
{% for error in form.non_field_errors %}
<p
class=
"error"
>
{{ error }}
</p>
{% endfor %}
</div>
{% render_field form.name %}
{% render_field form.email %}
{% render_field form.message %}
{{ form.captcha }}
<input
type=
"submit"
value=
"{% trans 'Send' %}"
class=
"btn btn-success btn-block my-3"
{%
if
object
%}
autofocus
{%
endif
%}
>
</fieldset>
</form>
</div>
</div>
{% endblock %}
\ No newline at end of file
app/escriptorium/templates/users/email/contactus_html.html
0 → 100644
View file @
b5841ce1
<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>
app/escriptorium/templates/users/email/contactus_message.txt
0 → 100644
View file @
b5841ce1
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.
app/escriptorium/templates/users/email/contactus_subject.txt
0 → 100644
View file @
b5841ce1
message from : {{ sender_name }}({{sender_email }})
\ No newline at end of file
app/escriptorium/urls.py
View file @
b5841ce1
...
...
@@ -26,7 +26,8 @@ urlpatterns = [
path
(
'api/'
,
include
(
'api.urls'
,
namespace
=
'api'
)),
# sandbox
path
(
'baseline-editor/'
,
TemplateView
.
as_view
(
template_name
=
'baseline_editor.html'
))
path
(
'baseline-editor/'
,
TemplateView
.
as_view
(
template_name
=
'baseline_editor.html'
)),
path
(
r
'captcha/'
,
include
(
'captcha.urls'
)),
]
if
settings
.
DEBUG
:
...
...
app/requirements.txt
View file @
b5841ce1
...
...
@@ -22,3 +22,4 @@ requests==2.21.0
numpy>=1.17
django-compressor==2.4
albumentations
django-simple-captcha==0.5.12
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment