Graduation project – Python graduation source code case design based on HTML5 responsive design of Django shopping website

Python_Django_HTML5_shopping

Python based on Django shopping website HTML5 responsive design graduation source code case design

Development technology: Python + Django framework + mysql database

Development tools: PyCharm

A shopping website built using the MVC framework, using the Bootstrap framework at the front desk, with two identities: administrator and user! After registering and logging in, users can check the products they are interested in, add the products to the shopping cart, and submit an order for purchase! Administrators can manage product classification information in the background, publish and manage product information, and query orders submitted by users to arrange delivery. After receiving the goods, users can confirm receipt and then evaluate. Administrators can query users’ evaluations in the background! The products on the website also include modules such as the latest products, hot-selling products, and Guess You Like It. The website is rich in content, and you can also check logistics updates based on the order number!

Part of the source code:

import xlrd

from django.shortcuts import render, HttpResponse
from django.contrib.auth.decorators import login_required
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.models import User, Group
from django.contrib.auth.views import login
from django.contrib.admin.views.decorators import staff_member_required
from django.db import IntegrityError

from student.models import StudentInfo
from teacher.models import TeacherInfo
from notice.models import Notice
from department.models import Department, Office, Major, Year
from department.views import get_department


# Login restrictions
def limited_login(request):
    if 'username' in request.POST:
        username = request.POST['username']
        user = User.objects.filter(username=username).first()
    else:
        user=None

    if user is not None and user.username in request.session:
        if not user.is_superuser and request.session[user.username] >= 3:
            user.is_staff = False
            user.save()
            return HttpResponse('Password entered incorrectly 3 times, account has been locked!')

    rep = login(request)
    status_code = rep.status_code
    if status_code == 200 and user is not None:
        if user.username in request.session:
            request.session[user.username] + = 1
        else:
            request.session[user.username] = 1
    return rep


# front page
@login_required
@staff_member_required(login_url='login')
def index(request):
    department = get_department(request)
    if department is not None:
        latest_notice = Notice.objects.filter(
            department=department).order_by('-pub_date')[:3]
    else:
        latest_notice = Notice.objects.order_by('-pub_date')[:3]

    context = {<!-- -->'latest_notice': latest_notice}
    return render(request, 'index.html', context)


# Get the table
def get_xls_table(sheet_name):
    try:
        data = xlrd.open_workbook('GDMS/data.xls')
    exceptException:
        return None
    return data.sheet_by_name(sheet_name)


# Row iterator generator
def get_xls_line(sheet_name):
    table = get_xls_table(sheet_name)
    if table is None:
        return None
    for r in range(1, table.nrows):
        yield table.row_values(r)


# Add college, major, teaching and research section, grade
def add_basis():
    s_table = get_xls_table('students')
    t_table = get_xls_table('teachers')
    s_department = s_table.col_values(0)[1:]
    t_department = t_table.col_values(0)[1:]
    department = s_department + t_department
    office = t_table.col_values(1)[1:]
    major = s_table.col_values(1)[1:]
    year = s_table.col_values(2)[1:]

    for d in set(department):
        try:
            Department.objects.create(name=d)
        except IntegrityError:
            continue

    for o in set(zip(t_department, office)):
        try:
            Office.objects.create(
                department=Department.objects.get(name=o[0]),
                name=o[1],
            )
        except IntegrityError:
            continue

    for m in set(zip(s_department, major)):
        try:
            Major.objects.create(
                department=Department.objects.get(name=m[0]),
                name=m[1]
            )
        except IntegrityError:
            continue

    for y in set(year):
        try:
            Year.objects.create(value=int(y))
        except IntegrityError:
            continue


#Add teacher
def add_teachers():
    values = get_xls_line('teachers')
    if values is None:
        return False

    for line in values:
        (department, office, username, name, title, contact, maxchoice) = line

        try:
            teacher = User.objects.create_user(
                username=username,
                password='asdfasdfasdf',
                first_name=name,
            )
        except IntegrityError:
            teacher = User.objects.get(username=username)
        finally:
            teacher.is_staff = True
            teacher.groups.add(Group.objects.get(name='teachers'))
            teacher.save()

        try:
            TeacherInfo.objects.create(
                t_id=teacher,
                t_department=Department.objects.get(name=department),
                t_office=Office.objects.get(name=office),
                t_title=title,
                t_contact=contact,
                t_maxchoice=int(maxchoice),
            )
        except IntegrityError:
            pass


#Add students
def add_students():
    values = get_xls_line('students')
    if values is None:
        return False

    for line in values:
        (department, major, year, username, name, contact) = line

        try:
            student = User.objects.create_user(
                username=username,
                password='asdfasdfasdf',
                first_name=name,
            )
        except IntegrityError:
            student = User.objects.get(username=username)
        finally:
            student.is_staff = True
            student.groups.add(Group.objects.get(name='students'))
            student.save()

        try:
            StudentInfo.objects.create(
                s_id=student,
                s_department=Department.objects.get(name=department),
                s_major=Major.objects.get(name=major),
                s_year=Year.objects.get(value=year),
                s_contact=contact,
            )
        except IntegrityError:
            pass


# Import Data
@permission_required('is_superuser')
def add(request):
    add_basis()
    add_teachers()
    add_students()
    return render(request, 'index.html')

Get the complete source code via private message!