Skip to content

Commit 793b87a

Browse files
committed
Update of Documentation improvement.
Appropriate comment lines for easy understanding of the code.
1 parent c60dc53 commit 793b87a

File tree

13 files changed

+54
-21
lines changed

13 files changed

+54
-21
lines changed

Base_Master/settings.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1616
BASE_DIR = Path(__file__).resolve().parent.parent
1717

18-
1918
# Quick-start development settings - unsuitable for production
2019
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
2120

2221
# SECURITY WARNING: keep the secret key used in production secret!
2322
SECRET_KEY = 'django-insecure-k6k-x^q$jjp*@bs#_7yw-!&cyn4g^byvr*lseiok=h=t#!)bw4'
2423
ENCRYPT_KEY = b'Py6zhVP-eFxkfq0kHUN0ZmIePwwaOeQ12ZmrFAVLbI8='
24+
2525
# SECURITY WARNING: don't run with debug turned on in production!
2626
DEBUG = True
2727

@@ -31,7 +31,7 @@
3131
# Application definition
3232

3333
INSTALLED_APPS = [
34-
'jazzmin',
34+
'jazzmin', #Package used to customize the Django Admin Panel
3535
'django.contrib.admin',
3636
'django.contrib.auth',
3737
'django.contrib.contenttypes',
@@ -45,7 +45,7 @@
4545
'import_export',
4646
'django_cleanup.apps.CleanupConfig',
4747
]
48-
IMPORT_EXPORT_USE_TRANSACTIONS = True
48+
IMPORT_EXPORT_USE_TRANSACTIONS = True #Mandatory for Transactions perfomred with import_export package
4949
CRISPY_TEMPLATE_PACK = 'bootstrap4'
5050

5151
MIDDLEWARE = [
@@ -126,6 +126,8 @@
126126

127127
STATIC_URL = 'static/'
128128
STATICFILES_DIRS = [BASE_DIR / 'static']
129+
130+
# Media Files (Images, Files...), This files are stored with associate with databse
129131
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
130132
MEDIA_URL = '/media/'
131133

@@ -134,13 +136,14 @@
134136

135137
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
136138

139+
###### Message Rendering tags ######
137140
from django.contrib.messages import constants as messages
138141
MESSAGE_TAGS = {
139-
messages.DEBUG: 'alert-secondary',
140-
messages.INFO: 'alert-info',
141-
messages.SUCCESS: 'alert-success',
142-
messages.WARNING: 'alert-warning',
143-
messages.ERROR: 'alert-danger',
142+
messages.DEBUG: 'alert-secondary',
143+
messages.INFO: 'alert-info',
144+
messages.SUCCESS: 'alert-success',
145+
messages.WARNING: 'alert-warning',
146+
messages.ERROR: 'alert-danger',
144147
}
145148

146149
#### Email Intergration ###
@@ -151,8 +154,8 @@
151154
EMAIL_HOST_PASSWORD = 'password' #You should type your Email password
152155
EMAIL_USE_TLS = True
153156

154-
LOGIN_REDIRECT_URL = 'home'
155-
LOGOUT_REDIRECT_URL = 'login'
157+
LOGIN_REDIRECT_URL = 'home' #this Url is used to redirect Users after login
158+
LOGOUT_REDIRECT_URL = 'login' #this Url is used to redirect Users after logout
156159

157160
###################### ADMIN DASHBOARD OVERWRITE ######################
158161
JAZZMIN_SETTINGS = {

Base_Master/urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.contrib import admin
2-
from django.urls import path,include, re_path
2+
from django.urls import path,include
33
from django.contrib.auth.views import LoginView
44
from firstapp import views
55
from django.conf import settings

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ Project is created with:
2929
7. Theme Customizer.<br>
3030
8. Bulk Import & Export data.<br>
3131
9. Automation in creating profile.<br>
32-
10. Automatically Delete profile photos which are unused.
32+
10. Automatically Delete files/images from media which are unused.<br>
33+
11. Highly documented with appropriate comment lines for easy understading of the code.
3334

3435
## Setup
3536

firstapp/admin.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@
88
admin.site.unregister(Group)
99
admin.site.register(Group, ImportExportModelAdmin)
1010
admin.site.register(Theme)
11-
admin.site.register(Profile)
11+
admin.site.register(Profile)
12+
13+
# Add import export model mixin to the model while registering the model in admin.py
14+
# Example:
15+
# admin.site.register(Theme, ImportExportModelAdmin)

firstapp/apps.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
class FirstappConfig(AppConfig):
55
default_auto_field = 'django.db.models.BigAutoField'
66
name = 'firstapp'
7+
8+
# This signal is integrated in this app
79
def ready(self):
810
import firstapp.signals

firstapp/forms.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from django.contrib.auth.models import User
44
from firstapp.models import Profile
55

6+
### This is the Sign Up Form
67
class SignUpForm(UserCreationForm):
78
first_name = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control', 'placeholder': 'Enter First name'}), required=True)
89
last_name = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control', 'placeholder': 'Enter last name'}), required=True)
@@ -14,13 +15,15 @@ class Meta:
1415
model = User
1516
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', )
1617

18+
### This is used to check if the registering email is exists in the database or not.
1719
def clean_email(self):
1820
email = self.cleaned_data.get("email")
1921
user_count = User.objects.filter(email=email).count()
2022
if user_count > 0:
2123
raise forms.ValidationError("This email is already exists.")
2224
return email
2325

26+
### This is the User editing form
2427
class User_edit(forms.ModelForm):
2528
first_name = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control', 'placeholder': 'Enter First name'}), required=True)
2629
last_name = forms.CharField(widget=forms.TextInput(attrs={'class':'form-control', 'placeholder': 'Enter last name'}), required=True)
@@ -29,6 +32,7 @@ class Meta:
2932
model = User
3033
fields=['email','first_name','last_name',]
3134

35+
### This is the Profile editing form
3236
class profile_edit(forms.ModelForm):
3337
profile_img = forms.ImageField(widget=forms.FileInput(attrs={'class':'form-control', 'onchange':'preview()','id':'formFile'}))
3438

firstapp/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
from django.db import models
22
from django.contrib.auth.models import User
33
# Create your models here.
4+
5+
## These are the options for the colors in Theme model.
46
themes = (
57
("dark", "dark"),
68
("light", "light"),

firstapp/signals.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
from django.dispatch import receiver
44
from .models import Profile
55

6+
### This signal used to create the Profile once the users gets added into the User table
67
@receiver(post_save, sender=User)
78
def create_profile(sender, instance, created, **kwargs):
89
if created:
910
Profile.objects.create(user=instance)
1011

11-
12+
### The profile created will be saved to the database.
1213
@receiver(post_save, sender=User)
1314
def save_profile(sender, instance, **kwargs):
1415
instance.profile.save()

firstapp/views.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
from firstapp.models import Theme
66
from django.contrib.admin.models import LogEntry
77
# Create your views here.
8+
9+
## Home page view
810
@login_required
911
def home(request):
1012
theme = theme_custom(request)
11-
logs = LogEntry.objects.filter(user_id=request.user.id)
13+
logs = LogEntry.objects.filter(user_id=request.user.id) ## This retrives the Log entry of the User
1214
return render(request, 'home.html', {'color':theme,'log':logs,})
1315

16+
### User Registration view
1417
from .forms import SignUpForm, User_edit, profile_edit
1518
def signup_view(request):
1619
if request.method == 'POST':
@@ -26,19 +29,21 @@ def signup_view(request):
2629
form = SignUpForm()
2730
return render(request, 'registration/registration.html', {'form': form})
2831

32+
### user Profile view
33+
from firstapp.encryption_util import *
2934
@login_required
3035
def profile(request):
3136
theme = theme_custom(request)
3237
lst = User.objects.filter(username=request.user).values('id')
3338
l=[]
34-
for i in lst:
39+
for i in lst: ## This will encrypt the Url for each User, So that the sensitive information is secure
3540
i['encrypt_key']=encrypt(i['id'])
3641
i['id']=i['id']
3742
l.append(i)
3843
return render(request, 'profile/profile.html', {'lst':l,'color':theme,})
3944

45+
# Profile Update view
4046
from django.shortcuts import redirect, render, get_object_or_404
41-
from firstapp.encryption_util import *
4247
@login_required
4348
def profile_update(request):
4449
theme = theme_custom(request)
@@ -61,7 +66,7 @@ def profile_update(request):
6166
}
6267
return render(request, 'profile/edit_profile.html', context)
6368

64-
69+
### Disable User view
6570
from django.contrib.auth import logout
6671
@login_required
6772
def disable_user(request, id):

static/dashboard/style.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// This is the first bar grpah chart
12
const BarGraph = document.getElementById("BarGraphChart");
23
new Chart(BarGraph, {
34
type: "bar",
@@ -20,6 +21,7 @@ new Chart(BarGraph, {
2021
}
2122
});
2223

24+
// This is the Line graph chart
2325
const LineGraph = document.getElementById("LineGraphChart");
2426
new Chart(LineGraph, {
2527
type: "line",
@@ -55,14 +57,17 @@ new Chart(LineGraph, {
5557
}
5658
});
5759

58-
60+
// This line of code used to enable tooltips in Bootstrap
5961
const tooltipTriggerList = document.querySelectorAll('[data-bs-toggle="tooltip"]')
6062
const tooltipList = [...tooltipTriggerList].map(tooltipTriggerEl => new bootstrap.Tooltip(tooltipTriggerEl))
6163

64+
65+
// These two functions are used to show preview of the image uploaded in image feild
6266
function preview() {
6367
frame.src = URL.createObjectURL(event.target.files[0]);
6468
}
6569

70+
// This founction refresh the preview if the image is changed in the image feild
6671
function clearImage() {
6772
document.getElementById('formFile').value = null;
6873
frame.src = "";

0 commit comments

Comments
 (0)