mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Polished email template and django admin for custom user
This commit is contained in:
parent
f6cbe1941e
commit
267e331be7
4 changed files with 65 additions and 2 deletions
|
@ -1,10 +1,29 @@
|
||||||
|
from django import forms
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
from django.contrib.auth.admin import UserAdmin
|
from django.contrib.auth.admin import UserAdmin
|
||||||
from .models import CustomUser
|
from .models import CustomUser
|
||||||
|
from year_levels.models import Year_Level
|
||||||
|
from semesters.models import Semester
|
||||||
|
from courses.models import Course
|
||||||
|
|
||||||
|
|
||||||
|
class CustomUserForm(forms.ModelForm):
|
||||||
|
year_level = forms.ModelChoiceField(
|
||||||
|
queryset=Year_Level.objects.all(), required=False)
|
||||||
|
semester = forms.ModelChoiceField(
|
||||||
|
queryset=Semester.objects.all(), required=False)
|
||||||
|
course = forms.ModelChoiceField(
|
||||||
|
queryset=Course.objects.all(), required=False)
|
||||||
|
avatar = forms.ImageField(required=False)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = CustomUser
|
||||||
|
fields = '__all__'
|
||||||
|
|
||||||
|
|
||||||
class CustomUserAdmin(UserAdmin):
|
class CustomUserAdmin(UserAdmin):
|
||||||
model = CustomUser
|
model = CustomUser
|
||||||
|
form = CustomUserForm
|
||||||
|
|
||||||
fieldsets = UserAdmin.fieldsets + (
|
fieldsets = UserAdmin.fieldsets + (
|
||||||
(None, {'fields': ('student_id_number',
|
(None, {'fields': ('student_id_number',
|
||||||
|
|
5
stude/config/email.py
Normal file
5
stude/config/email.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
from djoser import email
|
||||||
|
|
||||||
|
|
||||||
|
class ActivationEmail(email.ActivationEmail):
|
||||||
|
template_name = 'email_activation/email_activation.html'
|
|
@ -36,6 +36,7 @@ EMAIL_HOST = ''
|
||||||
EMAIL_HOST_USER = ''
|
EMAIL_HOST_USER = ''
|
||||||
EMAIL_HOST_PASSWORD = ''
|
EMAIL_HOST_PASSWORD = ''
|
||||||
EMAIL_PORT = ''
|
EMAIL_PORT = ''
|
||||||
|
EMAIL_USE_TLS = False
|
||||||
|
|
||||||
if (DEBUG == True):
|
if (DEBUG == True):
|
||||||
EMAIL_HOST = str(os.getenv('DEV_EMAIL_HOST'))
|
EMAIL_HOST = str(os.getenv('DEV_EMAIL_HOST'))
|
||||||
|
@ -47,6 +48,7 @@ else:
|
||||||
EMAIL_HOST_USER = str(os.getenv('PROD_EMAIL_HOST_USER'))
|
EMAIL_HOST_USER = str(os.getenv('PROD_EMAIL_HOST_USER'))
|
||||||
EMAIL_HOST_PASSWORD = str(os.getenv('PROD_EMAIL_HOST_PASSWORD'))
|
EMAIL_HOST_PASSWORD = str(os.getenv('PROD_EMAIL_HOST_PASSWORD'))
|
||||||
EMAIL_PORT = str(os.getenv('PROD_EMAIL_PORT'))
|
EMAIL_PORT = str(os.getenv('PROD_EMAIL_PORT'))
|
||||||
|
EMAIL_USE_TLS = str(os.getenv('PROD_EMAIL_TLS'))
|
||||||
|
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
@ -94,7 +96,9 @@ ASGI_APPLICATION = "config.asgi.application"
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
||||||
'DIRS': [],
|
'DIRS': [
|
||||||
|
BASE_DIR / 'templates',
|
||||||
|
],
|
||||||
'APP_DIRS': True,
|
'APP_DIRS': True,
|
||||||
'OPTIONS': {
|
'OPTIONS': {
|
||||||
'context_processors': [
|
'context_processors': [
|
||||||
|
@ -131,6 +135,9 @@ AUTH_USER_MODEL = 'accounts.CustomUser'
|
||||||
DJOSER = {
|
DJOSER = {
|
||||||
'SEND_ACTIVATION_EMAIL': True,
|
'SEND_ACTIVATION_EMAIL': True,
|
||||||
'SEND_CONFIRMATION_EMAIL': True,
|
'SEND_CONFIRMATION_EMAIL': True,
|
||||||
|
'EMAIL': {
|
||||||
|
'activation': 'config.email.ActivationEmail'
|
||||||
|
},
|
||||||
'ACTIVATION_URL': 'activation/{uid}/{token}',
|
'ACTIVATION_URL': 'activation/{uid}/{token}',
|
||||||
'USER_AUTHENTICATION_RULES': ['djoser.authentication.TokenAuthenticationRule'],
|
'USER_AUTHENTICATION_RULES': ['djoser.authentication.TokenAuthenticationRule'],
|
||||||
'SERIALIZERS': {
|
'SERIALIZERS': {
|
||||||
|
@ -183,4 +190,10 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
|
||||||
|
|
||||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||||
|
|
||||||
DOMAIN = 'stude://'
|
DOMAIN = ''
|
||||||
|
if (DEBUG):
|
||||||
|
DOMAIN = 'exp'
|
||||||
|
else:
|
||||||
|
DOMAIN = 'stude'
|
||||||
|
|
||||||
|
SITE_NAME = 'Stud-E'
|
||||||
|
|
26
stude/templates/email_activation/email_activation.html
Normal file
26
stude/templates/email_activation/email_activation.html
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{% load i18n %}
|
||||||
|
|
||||||
|
{% block subject %}
|
||||||
|
{% blocktrans %}Account activation on {{ site_name }}{% endblocktrans %}
|
||||||
|
{% endblock subject %}
|
||||||
|
|
||||||
|
{% block text_body %}
|
||||||
|
{% blocktrans %}You're receiving this email because you need to finish activation process on {{ site_name }}.{% endblocktrans %}
|
||||||
|
|
||||||
|
{% trans "Please open the following link to activate your account in-app:" %}
|
||||||
|
{{ domain }}://{{ url|safe }}
|
||||||
|
|
||||||
|
{% trans "Thanks you for using StudE!" %}
|
||||||
|
|
||||||
|
{% blocktrans %}The {{ site_name }} team{% endblocktrans %}
|
||||||
|
{% endblock text_body %}
|
||||||
|
|
||||||
|
{% block html_body %}
|
||||||
|
<p>{% blocktrans %}You're receiving this email because you need to finish activation process on {{ site_name }}.{% endblocktrans %}</p>
|
||||||
|
|
||||||
|
<p>{% trans "Please go to the following page to activate your account in-app:" %}</p>
|
||||||
|
<p><a href="{{ domain }}://{{ url|safe }}">{{ domain }}://--/{{ url|safe }}</a></p>
|
||||||
|
|
||||||
|
<p>{% blocktrans %}Many thnaks from the {{ site_name }} team{% endblocktrans %}</p>
|
||||||
|
|
||||||
|
{% endblock html_body %}
|
Loading…
Reference in a new issue