Polished email template and django admin for custom user

This commit is contained in:
Keannu Bernasol 2023-07-04 19:22:21 +08:00
parent f6cbe1941e
commit 267e331be7
4 changed files with 65 additions and 2 deletions

View file

@ -1,10 +1,29 @@
from django import forms
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
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):
model = CustomUser
form = CustomUserForm
fieldsets = UserAdmin.fieldsets + (
(None, {'fields': ('student_id_number',

5
stude/config/email.py Normal file
View file

@ -0,0 +1,5 @@
from djoser import email
class ActivationEmail(email.ActivationEmail):
template_name = 'email_activation/email_activation.html'

View file

@ -36,6 +36,7 @@ EMAIL_HOST = ''
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_PORT = ''
EMAIL_USE_TLS = False
if (DEBUG == True):
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_PASSWORD = str(os.getenv('PROD_EMAIL_HOST_PASSWORD'))
EMAIL_PORT = str(os.getenv('PROD_EMAIL_PORT'))
EMAIL_USE_TLS = str(os.getenv('PROD_EMAIL_TLS'))
# Application definition
@ -94,7 +96,9 @@ ASGI_APPLICATION = "config.asgi.application"
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'DIRS': [
BASE_DIR / 'templates',
],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
@ -131,6 +135,9 @@ AUTH_USER_MODEL = 'accounts.CustomUser'
DJOSER = {
'SEND_ACTIVATION_EMAIL': True,
'SEND_CONFIRMATION_EMAIL': True,
'EMAIL': {
'activation': 'config.email.ActivationEmail'
},
'ACTIVATION_URL': 'activation/{uid}/{token}',
'USER_AUTHENTICATION_RULES': ['djoser.authentication.TokenAuthenticationRule'],
'SERIALIZERS': {
@ -183,4 +190,10 @@ MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
DOMAIN = 'stude://'
DOMAIN = ''
if (DEBUG):
DOMAIN = 'exp'
else:
DOMAIN = 'stude'
SITE_NAME = 'Stud-E'

View 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 %}