0% found this document useful (0 votes)
162 views

IT 5th Semester Full Stack Web Development Lab - IT3511 - Lab Manual

Uploaded by

M.Poornima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
162 views

IT 5th Semester Full Stack Web Development Lab - IT3511 - Lab Manual

Uploaded by

M.Poornima
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Click on Subject/Paper under Semester to enter.

Environmental Sciences
Professional English and Sustainability -
Professional English - - II - HS3252 Discrete Mathematics - GE3451
I - HS3152 MA3354
Statistics and Theory of Computation
Matrices and Calculus Numerical Methods - Digital Principles and - CS3452
3rd Semester

4th Semester
- MA3151 MA3251 Computer Organization
1st Semester

2nd Semester

- CS3351 Artificial Intelligence


Engineering Graphics and Machine Learning
Engineering Physics - - CS3491
- GE3251 Foundation of Data
PH3151
Science - CS3352
Database Management
Physics for
Engineering Chemistry System - CS3492
Information Science Data Structures and
- CY3151 - PH3256 Algorithms - CD3291
Web Essentials -
Basic Electrical and IT3401
Problem Solving and Electronics Engineering - Object Oriented
Python Programming - BE3251 Programming - CS3391 Introduction to
GE3151 Operating Systems -
Programming in C -
CS3451
CS3251

Computer Networks -
CS3591
Object Oriented
Full Stack Web Software Engineering - Human Values and
5th Semester

Development - IT3501 CCS356 Ethics - GE3791


7th Semester

8th Semester
6th Semester

Distributed Computing Open Elective-1 Open Elective 2


- CS3551 Project Work /
Elective-3 Open Elective 3 Intership
Embedded Systems and
IoT - CS3691 Elective-4
Open Elective 4

Elective 1 Elective-5
Management Elective

Elective-6
Elective 2
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering
lOMoARcPSD|45374298

www.BrainKart.com

(ACADEMIC YEAR: 2023- 2024)

IT 3511 FULL STACK WEB DEVELOPMENT LAB

R - 2021

Name :

Register Number :

Department : INFORMATION TECHNOLOGY

Year/Semester : III / V

(ANNA UNIVERSITY: CHENNAI - 600 025)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

BONAFIDE CERTIFICATE

This is to certify that this is the Bonafide Record of work done by Mr.

/Ms.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . …

Register Number ............................................................................................. of

III YEAR / V Semester –INFORMATION TECHNOLOGY in the IT3511 FULL


STACK WEB DEVELOPMENT LAB during the academic year 2023-2024.

Staff In-Charge Head of the Department

Submitted for the Anna University B.Tech Practical Examination held on.
.. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Internal Examiner External Examiner

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

S.NO DATE LIST OF EXPERIMENTS MARKS SIGN

1 Develop a portfolio website for yourself which gives


details about yourself for a potential recruiter
2 Create a web application to manage the TO-DO list of
users, where users can login and manage their to-do
items
Create a simple micro blogging application (like
3 twitter) that allows people to post their content which
can be viewed by people who follow them.

4 Create a food delivery website where users can order


food from a particular restaurant listed in the website.

Develop a classifieds web application to buy and sell used products.


5

Develop a leave management system for an organization


6
where users can apply different types of leaves such as
casual leave and medical leave. They also can view the
availablenumber of days.

Develop a simple dashboard for project management


7
where the statuses of various tasks are available. New
tasks can be added and the status of existing tasks can be
changed among Pending, InProgress or Completed.

8 Develop an online survey application where a collection of


questions is available and users are asked to answer any
random 5 questions.

Content Beyond the Syllabus

9
Develop a program to create and build a password strength check

10 Write a program to create a voting application using MongoDB

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Ex.No : 1 Develop a portfolio website for yourself which gives


details about yourself for a potential recruiter.

Date:

Aim: To develop a full stack personal portfolio web application that uses python django
framework

Procedure:

 Open command prompt as administrator mode


 Then create project using django-admin start project project name
 Then go to project directory then create app using python manage.py start app app_name
command
 Now configure database to connect with mongodb using django in settings.py

 Now application structure will look like below image project structure

 The models.py file contains code for database design using django object relational
mapper(ORM)
 After models creation use python manage.py makemigrations and python manage.py
migrate for table creations

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

 In views.py the business logics will take place template folder contain all html file and
all static files placed inside static folder

Front End code:

1.Home.html:

{% extends 'base.html' %}

{% load static %}

{% block content %}

<div class="container">

<div class="row home ">

<div class="col-lg-12 text-center my-auto">

<small class="s-color">Welcome to my portfolio website!</small>

<div class="animated">

Hey, I'm<br>

<span class="color-primary" id="animated-name"></span>

</div>

<div class="row justify-content-center">

<div class="col-lg-6 text-center">

<p class="s-color mt-5">{{info.mini_about}}</p>

</div>

</div>

<div class="social-icons m-0 mt-3" style="justify-content: center;">

<a href="{{info.github}}" target="_blank">

<i class="fab fa-github"></i>

</a>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<a href="{{info.linkedin}}" target="_blank">

<i class="fab fa-linkedin-in"></i>

</a>

<a href="{{info.instagram}}" target="_blank">

<i class="fab fa-instagram"></i>

</a>

<a href="{{info.facebook}}" target="_blank">

<i class="fab fa-facebook-f"></i></i>

</a>

<a href="{{info.twitter}}" target="_blank">

<i class="fab fa-twitter"></i>

</a>

</div>

{% include 'nav.html' %}

</div>

</div>

<a href="/#education" class="scroll__down">

<span class="scroll__mouse">

<span class="scroll__wheel"></span>

</span>

</a>

<!-- Experiences and Education -->

{% include 'experiences_and_education.html' %}

<!-- Languages and Tools -->

{% include 'languages_and_tools.html' %}

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<!-- Projects -->

{% include 'projects.html' %}

<!-- About and Contact -->

{% include 'about_and_contact.html'%}

</div>

{% endblock content %}

Backend (model.py):

from django.db import models

import re

from ckeditor.fields import RichTextField

class Information(models.Model):

name_complete = models.CharField(max_length=50, blank=True, null=True)

avatar = models.ImageField(upload_to="avatar/", blank=True, null=True)

mini_about = models.TextField(blank=True, null=True)

about = models.TextField(blank=True, null=True)

born_date = models.DateField(blank=True, null=True)

address = models.CharField(max_length=100, blank=True, null=True)

phone = models.CharField(max_length=20, blank=True, null=True)

email = models.EmailField(max_length=255, blank=True, null=True)

cv = models.FileField(upload_to='cv', blank=True, null=True)

# Social Network

github = models.URLField(blank=True, null=True)

linkedin = models.URLField(blank=True, null=True)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

facebook = models.URLField(blank=True, null=True)

twitter = models.URLField(blank=True, null=True)

instagram = models.URLField(blank=True, null=True)

def __str__(self):

return self.name_complete

class Competence(models.Model):

title = models.CharField(max_length=50, blank=False, null=False)

description = models.TextField(blank=False, null=False)

image = models.FileField(upload_to='competence/', blank=False, null=False)

def __str__(self):

return self.title

class Education(models.Model):

title = models.CharField(max_length=50, blank=False, null=False)

description = models.TextField(blank=False, null=False)

the_year = models.CharField(max_length=50, blank=False, null=False)

def __str__(self):

return self.title

class Experience(models.Model):

title = models.CharField(max_length=50, blank=False, null=False)

description = models.TextField(blank=False, null=False)

the_year = models.CharField(max_length=50, blank=False, null=False)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

def __str__(self):

return self.title

class Project(models.Model):

title = models.CharField(max_length=200, blank=False, null=False)

slug = models.SlugField(max_length=200, blank=True, null=True)

description = RichTextField(blank=False, null=False)

image = models.ImageField(upload_to="projects/", blank=False, null=False)

tools = models.CharField(max_length=200, blank=False, null=False)

demo = models.URLField()

github = models.URLField()

show_in_slider = models.BooleanField(default=False)

def __str__(self):

return self.title

def get_project_absolute_url(self):

return "/projects/{}".format(self.slug)

def save(self, *args, **kwargs):

self.slug = self.slug_generate()

super(Project, self).save(*args, **kwargs)

def slug_generate(self):

slug = self.title.strip()

slug = re.sub(" ", "_", slug)

return slug.lower()

class Message(models.Model):

name = models.CharField(max_length=100, null=False, blank=False)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

email = models.EmailField(max_length=255, null=False, blank=False)

message = models.TextField(null=False, blank=False)

send_time = models.DateTimeField(auto_now_add=True)

is_read = models.BooleanField(default=False)

def __str__(self):

return self.name

Business Logic(views.py)

from django.shortcuts import render, get_object_or_404, HttpResponse

from django.http import JsonResponse

from django.core import serializers

import json

from django.db.models import Q

from decouple import config

from django.core.mail import send_mail

from django.conf import settings

from info.forms import MessageForm

from info.models import (

Competence,

Education,

Experience,

Project,

Information,

Message

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

def email_send(data):

old_message = Message.objects.last()

if old_message.name == data['name'] and old_message.email == data['email'] and


old_message.message == data['message']:

return False

subject = 'Portfolio : Mail from {}'.format(data['name'])

message = '{}\nSender Email: {}'.format(data['message'], data['email'])

email_from = settings.EMAIL_HOST_USER

recipient_list = [settings.EMAIL_HOST_USER, ]

send_mail(subject, message, email_from, recipient_list)

return True

def homePage(request):

template_name = 'homePage.html'

context = {}

if request.method == 'POST':

if request.POST.get('rechaptcha', None):

form = MessageForm(request.POST)

if form.is_valid():

form.save(commit=False)

data = {

'name': request.POST['name'],

'email': request.POST['email'],

'message': request.POST['message']

if email_send(data):

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

form.save()

return JsonResponse({'success': True})

else:

return JsonResponse({'success': False, 'errors': form.errors})

return JsonResponse({'success': False, 'errors': "Oops, you have to check the recaptcha !"})

if request.method == 'GET':

form = MessageForm()

competences = Competence.objects.all().order_by('id')

education = Education.objects.all().order_by('-id')

experiences = Experience.objects.all().order_by('-id')

projects = Project.objects.filter(show_in_slider=True).order_by('-id')

info = Information.objects.first()

context = {

'info': info,

'competences': competences,

'education': education,

'experiences': experiences,

'projects': projects,

'form': form,

'recaptcha_key': config("recaptcha_site_key", default="")

return render(request, template_name, context)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Output:

Homepage:

About:

Projects:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Contact:

RESULT:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Ex.No:2 Create a web application to manage the TO-DO list of users,


where users can login and manage their to-do items

Date:

Aim: To create full stack TODO application with users authentication and Updation

Procedure:

 Open command prompt as administrator mode


 Then create project using django-admin startproject projectname
 Then go to project directory then create app using python manage.py start app app_name
command
 Now configure database to connect with mongodb using djongo in settings.py

 The models.py file contains code for database design using django object relational
mapper(ORM)
 After models creation use python manage.py makemigrations and python manage.py
migrate for table creations
 In views.py the business logics will take place template folder contain all html file and
all static files placed inside static folder

Front End Code:

Index.html:
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>TODO APP</title>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<!-- Bootstrap CSS -->


<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
rel="stylesheet">
<link type="text/css" rel="stylesheet" href="{% static '/css/style.css' %}">
<link rel="stylesheet" href="{% static '/css/login.css' %}">
<link rel="stylesheet" href="{% static '/css/register.css' %}">
</head>

<body>
<nav class="navbar">
<p class="navbar-brand">TODO APP</p>

{% if user.is_authenticated %}
<p id="welcome-user">Welcome, {{ request.user.username }}</p>

<ul>
<li class="navbar-item">
<a class="link" href="{% url 'logout' %}">Logout</a>
</li>
</ul>
{% else %}
<ul>
{% if request.path == '/register/' %}
<li>
<a class="link" href="{% url 'login' %}">Login</a>
</li>
{% elif request.path == '/login/' %}
<li>
<a class="link" href="{% url 'register' %}">Register</a>
</li>
{% endif %}
</ul>
{% endif %}
</nav>

{% block content %}
{% endblock %}
<!-- Below jquery javascript is required for modal functionalities -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<!—

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script
> -->
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
</body>
</html>

Login.html

{% extends 'todo/index.html' %}
{% load crispy_forms_tags %}

{% block content %}
<div class="content-section">
<form action="" method="POST">
{% csrf_token %}
<fieldset class="form-group">
<legend>Login</legend>
<hr>
{{ form | crispy }}
</fieldset>

<div class="form-submit">
<button class="login-submit-btn" type="submit">Login</button>
</div>
<hr>
<div id="create-account">
<medium class="text-muted">
Don't Have an Account?
<a href="{% url 'register' %}" class="register-link">Sign Up</a>
</medium>
</div>
</form>
</div>
{% endblock %}

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

register.html

{% extends 'todo/index.html' %}
{% load crispy_forms_tags %}
{% block content %}

<div class="register-content">
<form action="" method="POST">
{% csrf_token %}
<fieldset class="register-form-group">
<legend>Register</legend>
<hr>
{{ form | crispy }}
</fieldset>
<div class="form-submit">
<button class="btn btn-success" type="submit">Sign Up</button>
</div>
<hr>
<div class="login-account">
<medium class="text-muted">
Already Have an Account?
<a href="{% url 'login' %}" class="login-link">Login</a>
</medium>
</div>
</form>
</div>
{% endblock %}

Backend(models.py):

from django.db import models

from django.conf import settings

class TodoItem(models.Model):

"""

Todo Item Model

"""

name = models.CharField(max_length=100)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

created_on = models.DateTimeField(auto_now_add=True)

updated_on = models.DateTimeField(auto_now=True)

is_completed = models.BooleanField(default=False)

user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,

related_name="todo_item")

class Meta:

"""

Meta Information

"""

app_label = "todo"

db_table = "todo_item"

verbose_name = "todo_item"

verbose_name_plural = "todo_items"

def __str__(self):

return self.name

views.py:

login_required

def home(request):

"""

Create todo item and view other todo items as well.

"""

if request.method == 'POST':

todo_name = request.POST.get("new-todo")

todo = TodoItem.objects.create(name=todo_name, user=request.user)

return redirect("home")

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

# todo items

todos = TodoItem.objects.filter(user=request.user, is_completed=False).order_by("-id")

# pagination 4 items per page

paginator = Paginator(todos, 4)

page_number = request.GET.get("page")

page_obj = paginator.get_page(page_number)

context = {"todos": todos, "page_obj": page_obj}

# NOTE: Need to change the html file to crud.html for displaying the todo's

return render(request, "todo/crud.html", context)

def register(request):

"""

User Registration form

Args:

request (POST): New user registered

"""

form = UserRegistrationForm()

if request.method == "POST":

form = UserRegistrationForm(request.POST)

if form.is_valid():

form.save()

return redirect("login")

else:

form = UserRegistrationForm()

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

context = {"form": form}

return render(request, "todo/register.html", context)

Output:

Register:

Login:

Add page:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Update:

RESULT:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Ex.No:3 Create a simple micro blogging application (like


twitter) that allows people to post their content which can be
viewed by people who follow them.

DATE:

Aim: To create a simple micro blogging application with user post and follower comments on
post

Procedure:

 Open command prompt as administrator mode


 Then create project using django-admin startproject projectname
 Then go to project directory then create app using python manage.py start app app_name
command
 Now configure database to connect with mongodb using djongo in settings.py

 The models.py file contains code for database design using django object relational
mapper(ORM)
 After models creation use python manage.py makemigrations and python manage.py
migrate for table creations
 In views.py the business logics will take place template folder contain all html file and
all static files placed inside static folder

Frontend:

Bloghome.html

{% extends 'base.html' %}

{% load static %}

{% block content %}

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<!-- Hero Section-->

<section style="background: url({% static 'img/inn.jpg'%}); background-size: cover;


background-position: center center" class="hero">

<div class="container">

<div class="row">

<div class="col-lg-7">

<h1>Blog App</h1><a href="#" class="hero-link">Discover More</a>

</div>

</div><a href=".intro" class="continue link-scroll"><i class="fa fa-long-arrow-down"></i>


Scroll Down</a>

</div>

</section>

<!-- Intro Section-->

<section class="intro">

<div class="container">

<div class="row">

<div class="col-lg-8">

<h2 class="h3">Some great intro here</h2>

<p class="text-big">Place a nice <strong>introduction</strong> here <strong>to catch


reader's attention</strong>. Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
nostrud nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderi.</p>

</div>

</div>

</div>

</section>

<section class="featured-posts no-padding-top">

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<div class="container">

<!-- Post-->

{% for obj in object_list %}

{% if forloop.counter < 5 %}

<!-- Do your something here -->

<div class="row d-flex align-items-stretch">

{% if not forloop.first and not forloop.last %}

<div class="image col-lg-5"><img src="{{obj.thumbnail.url}}" alt="..."></div>

{% endif %}

<div class="text col-lg-7">

<div class="text-inner d-flex align-items-center">

<div class="content">

<header class="post-header">

<div class="category">

{% for cat in obj.categories.all %}

<a href="#">{{cat}}</a>

{% endfor %}

</div>

<a href="{{ obj.get_absolute_url }}">

<h2 class="h4">{{obj.title}}</h2></a>

</header>

<p>{{obj.overview}}</p>

<footer class="post-footer d-flex align-items-center"><a href="#" class="author d-flex


align-items-center flex-wrap">

<div class="avatar"><img src="https://flyclipart.com/thumb2/avatar-my-profile-


profile-user-user-profile-icon-196366.png" alt="..." class="img-fluid"></div>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<div class="title"><span>{{obj.author}}</span></div></a>

<div class="date"><i class="icon-clock"></i> {{obj.timestamp | timesince}}


ago</div>

<div class="comments">

<i class="icon comment"></i>{{obj.comment_count}}</div>

</footer>

</div>

</div>

</div>

{% if forloop.first or forloop.last %}

<div class="image col-lg-5"><img src="{{obj.thumbnail.url}}" alt="..."></div>

{% endif %}

</div>

{% endif %}

{% endfor %}

</div>

</section>

<!-- Divider Section-->

<section style="background: url({% static 'img/divider-bg.jpg'%}); background-size: cover;


background-position: center bottom" class="divider">

<div class="container">

<div class="row">

<div class="col-md-7">

<h2>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua</h2><a href="#" class="hero-link">View More</a>

</div>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

</div>

</div>

</section>

<!-- Latest Posts -->

<section class="latest-posts">

<div class="container">

<header>

<h2>Newly Updated Places</h2>

<p class="text-big">.</p>

</header>

<div class="row">

{% for obj in latest%}

<div class="post col-md-4">

<div class="post-thumbnail"><a href="{{ obj.get_absolute_url }}"><img src="{{


obj.thumbnail.url}}" alt="..." class="img-fluid" style="height: 300px;"></a></div>

<div class="post-details">

<div class="post-meta d-flex justify-content-between">

<div class="date">{{obj.timestamp}}</div>

<div class="category">

{% for cat in obj.categories.all %}

<a href="#">{{cat}}</a>

{% endfor %}

</div>

</div><a href="{{ obj.get_absolute_url }}">

<h3 class="h4">{{obj.title}}</h3></a>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<p class="text-muted">{{obj.content}}</p>

</div>

</div>

{% endfor %}

</div>

</div>

</section>

<!-- Gallery Section-->

<section class="gallery no-padding">

<div class="row">

<div class="mix col-lg-3 col-md-3 col-sm-6">

<div class="item"><a href="img/gallery-1.jpg" data-fancybox="gallery"


class="image"><img src="{% static 'img/gallery-1.jpg'%}" alt="..." class="img-fluid">

<div class="overlay d-flex align-items-center justify-content-center"><i class="icon-


search"></i></div></a></div>

</div>

<div class="mix col-lg-3 col-md-3 col-sm-6">

<div class="item"><a href="img/gallery-2.jpg" data-fancybox="gallery"


class="image"><img src="{% static 'img/gallery-2.jpg'%}" alt="..." class="img-fluid">

<div class="overlay d-flex align-items-center justify-content-center"><i class="icon-


search"></i></div></a></div>

</div>

<div class="mix col-lg-3 col-md-3 col-sm-6">

<div class="item"><a href="img/gallery-3.jpg" data-fancybox="gallery"


class="image"><img src="{% static 'img/gallery-3.jpg'%}" alt="..." class="img-fluid">

<div class="overlay d-flex align-items-center justify-content-center"><i class="icon-


search"></i></div></a></div>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

</div>

<div class="mix col-lg-3 col-md-3 col-sm-6">

<div class="item"><a href="img/gallery-4.jpg" data-fancybox="gallery"


class="image"><img src="{% static 'img/gallery-4.jpg'%}" alt="..." class="img-fluid">

<div class="overlay d-flex align-items-center justify-content-center"><i class="icon-


search"></i></div></a></div>

</div>

</div>

</section>

{% endblock content %}

Database(models.py):

class Category(models.Model):

title = models.CharField(max_length=30)

def __str__(self):

return self.title

class Comment(models.Model):

user = models.ForeignKey(User, on_delete=models.CASCADE)

timestamp = models.DateTimeField(auto_now_add=True)

content =tinymce_models.HTMLField('Content')

post = models.ForeignKey(

'Post', related_name='comments', on_delete=models.CASCADE)

def __str__(self):

return self.user.username

class account(models.Model):

user = models.ForeignKey(User, on_delete=models.CASCADE)

email_id=models.CharField("email id",max_length=100)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

password=models.CharField("user password",max_length=100)

def __str__(self):

return self.name;

class Post(models.Model):

title = models.CharField(max_length=100)

overview = models.TextField()

timestamp = models.DateTimeField(auto_now_add=True)

content =models.TextField(max_length=10000)

# comment_count = models.IntegerField(default = 0)

# view_count = models.IntegerField(default = 0)

author = models.ForeignKey(Author, on_delete=models.CASCADE)

thumbnail = models.ImageField()

categories = models.ManyToManyField(Category)

features = models.BooleanField()

previous_post = models.ForeignKey(

'self', related_name = 'previous', on_delete= models.SET_NULL, blank=True, null= True

next_post = models.ForeignKey(

'self', related_name = 'next', on_delete= models.SET_NULL, blank=True, null= True

location=models.CharField(max_length=10000,null=True)

phone=models.CharField(max_length=1000)

timing=models.CharField(max_length=100)

address=models.CharField(max_length=1000)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

views.py:

def index(request):

featured = Post.objects.all()

latest = Post.objects.order_by('-timestamp')[0:3]

if request.method == "POST":

email = request.POST["email"]

new_signup = Signup()

new_signup.email = email

new_signup.save()

context = {

'object_list' : featured,

'latest': latest

return render(request, 'index.html',context)

def blog(request):

category_count = get_category_count()

most_recent = Post.objects.order_by('-timestamp')[:3]

post_list = Post.objects.all()

paginator = Paginator(post_list, 4)

page_request_var = 'page'

page = request.GET.get(page_request_var)

try:

paginated_queryset = paginator.page(page)

except PageNotAnInteger:

paginated_queryset = paginator.page(1)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

except EmptyPage:

paginated_queryset = paginator.page(paginator.num_pages)

context = {

'queryset' : paginated_queryset,

'most_recent': most_recent,

'page_request_var': page_request_var,

'category_count': category_count

return render(request, 'blog.html',context)

Outome:

Home:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Blog Post:

Display blog content:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Post comments:

RESULT:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Ex. No: 4 Create a food delivery website where users can order food from a
particular restaurant listed in the website.

Aim:To Create Full functional Food ordering application with users can select food and make

order online

Procedure:

 Open command prompt as administrator mode


 Then create project using django-admin startproject projectname
 Then go to project directory then create app using python manage.py start app app_name
command
 Now configure database to connect with mongodb using djongo in settings.py

 The models.py file contains code for database design using django object relational
mapper(ORM)
 After models creation use python manage.py makemigrations and python manage.py
migrate for table creations
 In views.py the business logics will take place template folder contain all html file and
all static files placed inside static folder

Frontend code:

Home.html:

<!DOCTYPE html>

<html lang="en" dir="ltr">

<head>

{% load static %}

<meta charset="utf-8">

<link rel="stylesheet" type="text/css" href="{% static 'css/imperial_style.css' %}" />

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<link rel="stylesheet" type="text/css" href="{% static 'css/master.css' %}" />

<link href="https://fonts.googleapis.com/css?family=Caveat:700&display=swap"
rel="stylesheet">

<link
href="https://fonts.googleapis.com/css?family=Poppins:300,300i,400,400i,500,500i,600,600i,70
0,700i" rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Bevan&display=swap" rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Caveat:400,700&subset=cyrillic"
rel="stylesheet">

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.2/css/all.css"


integrity="sha384-
fnmOCqbTlWIlj8LyTjo7mOUStjsKC4pOpQbqyi7RrhN7udi9RwhKkMHpvLbHG9Sr"
crossorigin="anonymous">

<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.3.1/css/all.css">

<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-
Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-


J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-
Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo"
crossorigin="anonymous"></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384-
wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6"
crossorigin="anonymous"></script>

<title>foodApp | Home</title>

<link rel="shortcut icon" href="{% static 'images/favico.png' %}" type="image/x-icon">

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

</head>

<nav class="navbar navbar-expand-lg navbar-light" style="position:


fixed;width:100%;background-image: linear-gradient(180deg,#FFF,#FFF);box-shadow: 0px 0px
7px 0px #404040;">

<a class="navbar-brand" href="/"><h2 style="color:black;font-family:sans-serif;font-


weight:bolder;"><b>Food Ordering App</b></h2></a>

<button class="navbar-toggler" type="button" data-toggle="collapse" data-


target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-
expanded="false" aria-label="Toggle navigation">

<span class="navbar-toggler-icon"></span>

</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">

<ul class="navbar-nav" style="margin-left:auto!important;margin-right:30px;">

<li class="nav-item active">

<a class="nav-link" id="nav-link" href="home">Home <span class="sr-


only">(current)</span></a>

</li>

{% if request.session.CustId is None and request.session.AdminId is not None %}

<li class="nav-item active">

<a class="nav-link" id="nav-link" href="addfoods">Add Food <span class="sr-


only">(current)</span></a>

</li>

{% endif %}

{% if request.session.CustId is not None and request.session.AdminId is None %}

<a class="dropdown-item" href="getcustomer">Edit Profile</a>

<div class="dropdown-divider"></div>

<a class="dropdown-item" href="orders"><i class="fas fa-clipboard-list" style="font-


size:20px;"></i>&nbsp;&nbsp;&nbsp;Orders</a>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<a class="dropdown-item" href="orders"><i class="fas fa-history" style="font-


size:20px;"></i>&nbsp;&nbsp;Order History</a>

<div class="dropdown-divider"></div>

{% endif %}

<a class="dropdown-item" style="background:red;width:1;border-radius:4px;"


href="logout"><i class="fas fa-sign-out-alt" style="font-
size:20px;color:white;"></i>&nbsp;&nbsp;<font color="white">Logout</font></a>

</div>

</li>

{% endif %}

</ul>

</div>

</nav>

</body>

</html>

Database(models.py):
lass Food(models.Model)

FoodId = models.AutoField(primary_key=True)

FoodName = models.CharField(max_length=30)

FoodCat = models.CharField(max_length=30)

FoodPrice = models.FloatField(max_length=15)

FoodImage = models.ImageField(upload_to='media',default='')

class Meta:

db_table = "FP_Food"

class Cust(models.Model):

CustId = models.AutoField(primary_key=True)

CustFName = models.CharField(max_length=30)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

CustLName = models.CharField(max_length=30)

CustCont = models.CharField(max_length=10)

CustEmail = models.CharField(max_length=50)

CustPass = models.CharField(max_length=60)

Address = models.CharField(max_length=150,default='')

class Meta:

db_table = "FP_Cust"

views.py:

def addfood(request):

if request.method=="POST":

form = FoodForm(request.POST,request.FILES)

if form.is_valid():

try:

form.save()

return redirect("/allfood")

except:

return render(request,"error.html")

else :

form = FoodForm()

return render(request,'addfood.html',{'form':form})

def showfood(request):

foods = Food.objects.all()

return render(request,'foodlist.html',{'foodlist':foods})

def deletefood(request,FoodId):

foods = Food.objects.get(FoodId=FoodId)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

foods.delete()

return redirect("/allfood")

def getfood(request,FoodId):

foods = Food.objects.get(FoodId=FoodId)

return render(request,'updatefood.html',{'f':foods})

def updatefood(request,FoodId):

foods = Food.objects.get(FoodId=FoodId)

form = FoodForm(request.POST,request.FILES,instance=foods)

if form.is_valid():

form.save()

return redirect("/allfood")

return render(request,'updatefood.html',{'f':foods})

def addcust(request):

if request.method=="POST":

form = CustForm(request.POST)

if form.is_valid():

try:

form.save()

return redirect("/login")

except:

return render(request,"error.html")

else :

form = CustForm()

return render(request,'addcust.html',{'form':form})

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Output:

Home

Menu page:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Cart:

Invoice:

RESULT:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Ex.No: 5 Develop a classifieds web application to buy and sell used


products.

Aim: To create a full stack we application where user can sell their products and can purchase
the products online

Procedure:

 Open command prompt as administrator mode


 Then create project using django-admin startproject projectname
 Then go to project directory then create app using python manage.py start app app_name
command
 Now configure database to connect with mongodb using djongo in settings.py

 The models.py file contains code for database design using django object relational
mapper(ORM)
 After models creation use python manage.py makemigrations and python manage.py
migrate for table creations
 In views.py the business logics will take place template folder contain all html file and
all static files placed inside static folder

Frontend code:

Base.html:

{% load static %}

<!DOCTYPE html>

<html lang="en">

<head>

<title>Test</title>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<meta charset="utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

<link rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-
Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh"
crossorigin="anonymous">

<link rel="stylesheet" type="text/css" href="{% static 'store/style.css' %}">

</head>

<body>

<nav class="navbar navbar-expand-lg navbar-dark bg-dark">

<a class="navbar-brand" href="#">Hello</a>

<button class="navbar-toggler" type="button" data-toggle="collapse" data-


target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-
expanded="false" aria-label="Toggle navigation">

<span class="navbar-toggler-icon"></span>

</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">

<ul class="navbar-nav mr-auto">

<li class="nav-item active">

<a class="nav-link" href="{% url 'home' %}">Home <span class="sr-


only">(current)</span></a>

</li>

{% if user.is_authenticated %}

<li class="nav-item"><a class="nav-link" href="{% url 'product-create' %}">New


product</a></li>

<li class="nav-item"><a class="nav-link" href="{% url 'profile' %}">Profile</a></li>

<li class="nav-item"><a class="nav-link" href="{% url 'logout' %}">Logout</a></li>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

{% else %}

<li class="nav-item"><a class="nav-link" href="{% url 'login' %}">Login</a></li>

<li class="nav-item"><a class="nav-link" href="{% url


'register'%}">Register</a></li>

{% endif %}

</ul>

</div>

</nav>

<div class="container">

<!--Displaying any flash message -->

{% if messages %}

{% for message in messages %}

{{ message }}

{% endfor%}

{% endif %}

<!--Main info block -->

{% block content%} {% endblock %}

</div>

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384


J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n"
crossorigin="anonymous"></script>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxM
fooAo" crossorigin="anonymous"></script>

<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"
integrity="sha384wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8
ifwB6" crossorigin="anonymous"></script>

</body>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Home.html

{% extends "store/base.html" %}

{% block content %}

<h1 class="store-heading">Listed items </h1>

<hr class="style1">

{% for product in products %}

<h2><a href="{% url 'product-detail' product.id %}">{{ product.name }} </a></h2>

<h4 class="item-title"> Seller : {{ product.seller}}</h4>

<h4 class="item-title"> Contact : {{ product.seller.email}}</h4>

<h4 class="item-title"> Cost : {{ product.cost}}</h4>

{% if product.image1 %}

<img class="img-thumbnail" src={{ product.image1.url}} height=100/>

{% endif %}

{% if product.image2 %}

<img class="img-thumbnail" src={{ product.image2.url}} height=100/>

{% endif %}

<hr>

{% endfor %}

{% endblock content %}

Database(models.py):

from django.db import models

from django.contrib.auth.models import User

from django.urls import reverse

def user_directory_path(instance, filename):

return 'uploads/user_{0}/{1}'.format(instance.user.id, filename)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

class Product(models.Model):

"""Product model with seller as foreign key on user"""

name = models.CharField(max_length=30)

description = models.TextField()

age = models.FloatField()

cost = models.PositiveIntegerField()

address = models.CharField(max_length=100)

seller = models.ForeignKey(User, on_delete=models.CASCADE)

image1 = models.ImageField(upload_to='uploads/', null=True, blank=True)

image2 = models.ImageField(upload_to='uploads/', null=True, blank=True)

def __str__(self):

return self.name

#function to return url string for displaying product after its creation

def get_absolute_url(self):

return reverse('product-detail', kwargs={'pk':self.pk})

Views.py:

ef home(request):

context = {

'products' : Product.objects.all()

return render(request, 'store/home.html', context)

class ProductListView(ListView):

"""Class based view for displaying Product"""

model = Product

template_name = 'store/home.html'

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

context_object_name = 'products'

class ProductDetailView(DetailView):

model = Product

class ProductCreateView(LoginRequiredMixin, CreateView):

"""Class based view for creating a new Product with login required mixin"""

model = Product

fields = ['name', 'description', 'age', 'cost', 'image1', 'image2']

def form_valid(self, form):

form.instance.seller = self.request.user

return super().form_valid(form)

class ProductUpdateView(LoginRequiredMixin, UserPassesTestMixin, UpdateView):

"""Class based view for updating a Product with login required mixin"""

model = Product

fields = ['name', 'description', 'age', 'cost', 'image1', 'image2']

def form_valid(self, form):

form.instance.seller = self.request.user

return super().form_valid(form)

# function for testing if user tying to udpate the product is seller itself

def test_func(self):

product = self.get_object()

if self.request.user == product.seller:

return True

return False

class ProductDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):

model = Product

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

success_url = '/' #setting success url to home

# function for testing if user tying to delete the product is seller itself

def test_func(self):

product = self.get_object()

if self.request.user == product.seller:

return True

return False

@login_required

def BuyProduct(request, pk):

""" View and logic for buying a product"""

product = get_object_or_404(Product, pk=pk)

user = request.user

buyerInstance = User.objects.get(username=request.user.username)

sellerInstance = User.objects.get(username=product.seller.username)

#if seller tries to buy him own item

if user == product.seller:

return redirect('home')

#wallet should contain more money than cost

if user.profile.wallet >= product.cost:

user.profile.wallet -= product.cost

product.seller.profile.wallet += product.cost

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

new_trans = Transaction.objects.create(item=product.name, buyer=buyerInstance,


seller=sellerInstance, value=product.cost)

user.save()

product.seller.save()

product.delete()

messages.success(request, f'Item successfully bought!')

else:

messages.error(request, f'Item cannot be bought not enough money!')

return redirect('home')

OutPut:

Post selling product:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Wallet:

Listed products:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

BuyPage:

RESULT:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Ex.No: 6 Develop a leave management system for an


organization where users can apply different types of leaves such as
casual leave and medical leave. They also can view the available
number of days.

Aim:To develop a employee leave management and approval system with tracking management
using python django framework

Procedure:

 Open command prompt as administrator mode


 Then create project using django-admin startproject projectname
 Then go to project directory then create app using python manage.py start app app_name
command
 Now configure database to connect with mongodb using djongo in settings.py

 The models.py file contains code for database design using django object relational
mapper(ORM)
 After models creation use python manage.py makemigrations and python manage.py
migrate for table creations
 In views.py the business logics will take place template folder contain all html file and
all static files placed inside static folder

Frontend code:

Index.html:

{% load static %}

<!doctype html>

<html lang="en">

<head>

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<meta charset="utf-8" />

<link rel="icon" type="image/png" href="assets/img/favicon.ico">

<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />

<title>Leave Management</title>

<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-


scalable=0' name='viewport' />

<meta name="viewport" content="width=device-width" />

<!-- Bootstrap core CSS -->

<link href="{% static 'css/bootstrap.min.css' %}" rel="stylesheet" />

<link href="{% static 'css/pe-icon-7-stroke.css' %}" rel="stylesheet" />

<!-- Google Fonts -->

<link href="https://fonts.googleapis.com/css?family=Anton|Russo+One" rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Luckiest+Guy" rel="stylesheet">

<link href="https://fonts.googleapis.com/css?family=Alice" rel="stylesheet">

</head>

<body>

<style type="text/css">

body{

position: relative;

background: #243177;

a{

font-variant: petite-caps;

font-weight: 100;

font-size: 16px;

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

navbar-brand{

font-variant: petite-caps;

font-family: 'Luckiest Guy', cursive;

font-weight: 600;

font-size: 3.1rem;

color: #e4a530;

text-shadow:1px 2px 1px rgba(0,0,0,0.2);

h2{

font-family: 'Alice', serif;

color: gold;

font-size: 4.9rem;

p{

font-variant: small-caps;

color: #cecece;

p span{

color: #a5a5a5;

font-weight: bold;

span.icon{

font-size: 15px;

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

.content{

position: relative;

height: 100vh;

.sub-title{

vertical-align: -webkit-baseline-middle;

font-size: 12px !important;

font-family: 'Luckiest Guy', cursive;

.back-link{

color: #fff;

font-size: 2.6rem;

font-weight: 900;

transition: all 400ms ease-in-out;

.back-link:hover{

color: #fff;

font-size: 2.8rem;

transition: all 400ms ease-in-out;

.container-centered-items{

position: absolute;

top: 50%;

left: 0;

right: 0;

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

</style>

<!--CONTENTS-->

<section class="content">

<!-- Navigation -->

<nav class="navbar navbar-default">

<div class="container-fluid">

<!-- Brand and toggle get grouped for better mobile display -->

<div class="navbar-header">

<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"


data-target="#bs-example-navbar-collapse-1" aria-expanded="false">

<span class="sr-only"></span>

<span class="icon-bar"></span>

<span class="icon-bar"></span>

<span class="icon-bar"></span>

</button>

{% if request.user.is_authenticated %}

<a class="navbar-brand" href="{% url 'dashboard:dashboard' %}">Leave


Management<span class="sub-title">HRM</span></a>

{% else %}

<a class="navbar-brand" href="/">Leave Management</a>

{% endif %}

</div>

<!-- Collect the nav links, forms, and other content for toggling -->

<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">

<ul class="nav navbar-nav">

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<li class=""><a href="" target="_blank">Leave Management<span class="sr-


only">(current)</span></a></li>

</ul>

<ul class="nav navbar-nav navbar-right">

<li><a href="{% url 'accounts:login' %}">Login</a></li>

</ul>

</div><!-- /.navbar-collapse -->

</div><!-- /.container-fluid -->

</nav>

<!-- /Naivagtion -->

<div class="container-fluid container-centered-items">

<section class="row">

<section class="">

<section class="col col-lg-12 text-center">

<div class="center-me-please"

</p>

</div>

</section>

</section>

</section>

</div>

</section> <!-- /content -->

<div>

{% if request.user.is_authenticated %}

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

<p style="position: absolute;bottom: 0;"><a


href="{{request.META.HTTP_REFERER|escape}}" class="back-link" title="back to previous
page"><i class="pe-7s-back-2"></i></a></p>

{% endif %}

</div>

</body>

<!-- Core JS Files -->

<script src="{% static 'js/jquery.3.2.1.min.js' %}" type="text/javascript"></script>

<script src="{% static 'js/bootstrap.min.js' %}" type="text/javascript"></script>

<script type="text/javascript">

</script>

</html>

Database(Models.py):

import datetime

from employee.utility import code_format

from django.db import models

from employee.managers import EmployeeManager

from phonenumber_field.modelfields import PhoneNumberField

from django.utils.translation import ugettext as _

from django.contrib.auth.models import User

from leave.models import Leave

# Create your models here.

class Role(models.Model):

name = models.CharField(max_length=125)

description = models.CharField(max_length=125,null=True,blank=True)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

created = models.DateTimeField(verbose_name=_('Created'),auto_now_add=True)

updated = models.DateTimeField(verbose_name=_('Updated'),auto_now=True)

class Meta:

verbose_name = _('Role')

verbose_name_plural = _('Roles')

ordering = ['name','created']

def __str__(self):

return self.name

class Department(models.Model):

name = models.CharField(max_length=125)

description = models.CharField(max_length=125,null=True,blank=True)

created = models.DateTimeField(verbose_name=_('Created'),auto_now_add=True)

updated = models.DateTimeField(verbose_name=_('Updated'),auto_now=True)

class Meta:

verbose_name = _('Department')

verbose_name_plural = _('Departments')

ordering = ['name','created']

def __str__(self):

return self.name

class Employee(models.Model):

MALE = 'male'

FEMALE = 'female'

OTHER = 'other'

NOT_KNOWN = 'Not Known'

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

GENDER = (

(MALE,'Male'),

(FEMALE,'Female'),

(OTHER,'Other'),

(NOT_KNOWN,'Not Known'),

MR = 'Mr'

MRS = 'Mrs'

MSS = 'Mss'

DR = 'Dr'

SIR = 'Sir'

MADAM = 'Madam'

TITLE = (

(MR,'Mr'),

(MRS,'Mrs'),

(MSS,'Mss'),

(DR,'Dr'),

(SIR,'Sir'),

(MADAM,'Madam'),

FULL_TIME = 'Full-Time'

PART_TIME = 'Part-Time'

CONTRACT = 'Contract'

INTERN = 'Intern'

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

EMPLOYEETYPE = (

(FULL_TIME,'Full-Time'),

(PART_TIME,'Part-Time'),

(CONTRACT,'Contract'),

(INTERN,'Intern'),

# PERSONAL DATA

user = models.ForeignKey(User,on_delete=models.CASCADE,default=1)

image = models.FileField(_('Profile
Image'),upload_to='profiles',default='default.png',blank=True,null=True,help_text='upload
image size less than 2.0MB')#work on path username-date/image

firstname = models.CharField(_('Firstname'),max_length=125,null=False,blank=False)

lastname = models.CharField(_('Lastname'),max_length=125,null=False,blank=False)

othername = models.CharField(_('Othername
(optional)'),max_length=125,null=True,blank=True)

birthday = models.DateField(_('Birthday'),blank=False,null=False)

department = models.ForeignKey(Department,verbose_name
=_('Department'),on_delete=models.SET_NULL,null=True,default=None)

role = models.ForeignKey(Role,verbose_name
=_('Role'),on_delete=models.SET_NULL,null=True,default=None)

startdate = models.DateField(_('Employement Date'),help_text='date of


employement',blank=False,null=True)

employeetype = models.CharField(_('Employee
Type'),max_length=15,default=FULL_TIME,choices=EMPLOYEETYPE,blank=False,null=Tru
e)

employeeid = models.CharField(_('Employee ID
Number'),max_length=10,null=True,blank=True)

dateissued = models.DateField(_('Date Issued'),help_text='date staff id was


issued',blank=False,null=True)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

# app related

is_blocked = models.BooleanField(_('Is Blocked'),help_text='button to toggle employee block


and unblock',default=False)

is_deleted = models.BooleanField(_('Is Deleted'),help_text='button to toggle employee deleted


and undelete',default=False)

created = models.DateTimeField(verbose_name=_('Created'),auto_now_add=True,null=True)

updated = models.DateTimeField(verbose_name=_('Updated'),auto_now=True,null=True)

#PLUG MANAGERS

objects = EmployeeManager()

class Meta:

verbose_name = _('Employee')

verbose_name_plural = _('Employees')

ordering = ['-created']

def __str__(self):

return self.get_full_name

@property

def get_full_name(self):

fullname = ''

firstname = self.firstname

lastname = self.lastname

othername = self.othername

if (firstname and lastname) or othername is None:

fullname = firstname +' '+ lastname

return fullname

elif othername:

fullname = firstname + ' '+ lastname +' '+othername

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

return fullname

return

@property

def get_age(self):

current_year = datetime.date.today().year

dateofbirth_year = self.birthday.year

if dateofbirth_year:

return current_year - dateofbirth_year

return

@property

def can_apply_leave(self):

pass

def save(self,*args,**kwargs):

'''

overriding the save method - for every instance that calls the save method

perform this action on its employee_id

added : March, 03 2019 - 11:08 PM

'''

get_id = self.employeeid #grab employee_id number from submitted form field

data = code_format(get_id)

self.employeeid = data #pass the new code to the employee_id as its orifinal or actual code

super().save(*args,**kwargs) # call the parent save method

# print(self.employeeid)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Views.py

ef dashboard_employees(request):

if not (request.user.is_authenticated and request.user.is_superuser and


request.user.is_staff):

return redirect('/')

dataset = dict()

departments = Department.objects.all()

employees = Employee.objects.all()

#pagination

query = request.GET.get('search')

if query:

employees = employees.filter(

Q(firstname__icontains = query) |

Q(lastname__icontains = query)

paginator = Paginator(employees, 10) #show 10 employee lists per page

page = request.GET.get('page')

employees_paginated = paginator.get_page(page)

blocked_employees = Employee.objects.all_blocked_employees()

return render(request,'dashboard/employee_app.html',dataset)

def dashboard_employees_create(request):

if not (request.user.is_authenticated and request.user.is_superuser and


request.user.is_staff):

return redirect('/')

if request.method == 'POST':

form = EmployeeCreateForm(request.POST,request.FILES)

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

if form.is_valid():

instance = form.save(commit = False)

user = request.POST.get('user')

assigned_user = User.objects.get(id = user)

instance.user = assigned_user

instance.title = request.POST.get('title')

instance.image = request.FILES.get('image')

instance.firstname = request.POST.get('firstname')

instance.lastname = request.POST.get('lastname')

instance.othername = request.POST.get('othername')

instance.birthday = request.POST.get('birthday')

Output:

HR Page:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Add employee:

Apply for leave:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
lOMoARcPSD|45374298

www.BrainKart.com

Pending leaves:

Approve leaves:

RESULT:

https://play.google.com/store/apps/details?id=info.therithal.brainkart.annauniversitynotes
Click on Subject/Paper under Semester to enter.
Environmental Sciences
Professional English and Sustainability -
Professional English - - II - HS3252 Discrete Mathematics - GE3451
I - HS3152 MA3354
Statistics and Theory of Computation
Matrices and Calculus Numerical Methods - Digital Principles and - CS3452
3rd Semester

4th Semester
- MA3151 MA3251 Computer Organization
1st Semester

2nd Semester

- CS3351 Artificial Intelligence


Engineering Graphics and Machine Learning
Engineering Physics - - CS3491
- GE3251 Foundation of Data
PH3151
Science - CS3352
Database Management
Physics for
Engineering Chemistry System - CS3492
Information Science Data Structures and
- CY3151 - PH3256 Algorithms - CD3291
Web Essentials -
Basic Electrical and IT3401
Problem Solving and Electronics Engineering - Object Oriented
Python Programming - BE3251 Programming - CS3391 Introduction to
GE3151 Operating Systems -
Programming in C -
CS3451
CS3251

Computer Networks -
CS3591
Object Oriented
Full Stack Web Software Engineering - Human Values and
5th Semester

Development - IT3501 CCS356 Ethics - GE3791


7th Semester

8th Semester
6th Semester

Distributed Computing Open Elective-1 Open Elective 2


- CS3551 Project Work /
Elective-3 Open Elective 3 Intership
Embedded Systems and
IoT - CS3691 Elective-4
Open Elective 4

Elective 1 Elective-5
Management Elective

Elective-6
Elective 2
All Computer Engg Subjects - [ B.E., M.E., ] (Click on Subjects to enter)
Programming in C Computer Networks Operating Systems
Programming and Data Programming and Data Problem Solving and Python
Structures I Structure II Programming
Database Management Systems Computer Architecture Analog and Digital
Communication
Design and Analysis of Microprocessors and Object Oriented Analysis
Algorithms Microcontrollers and Design
Software Engineering Discrete Mathematics Internet Programming
Theory of Computation Computer Graphics Distributed Systems
Mobile Computing Compiler Design Digital Signal Processing
Artificial Intelligence Software Testing Grid and Cloud Computing
Data Ware Housing and Data Cryptography and Resource Management
Mining Network Security Techniques
Service Oriented Architecture Embedded and Real Time Multi - Core Architectures
Systems and Programming
Probability and Queueing Theory Physics for Information Transforms and Partial
Science Differential Equations
Technical English Engineering Physics Engineering Chemistry
Engineering Graphics Total Quality Professional Ethics in
Management Engineering
Basic Electrical and Electronics Problem Solving and Environmental Science and
and Measurement Engineering Python Programming Engineering

You might also like