Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gupta-Anubhav12 committed Jan 31, 2021
0 parents commit cb0c8a2
Show file tree
Hide file tree
Showing 73 changed files with 12,802 additions and 0 deletions.
Empty file added books/__init__.py
Empty file.
Binary file added books/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added books/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added books/__pycache__/models.cpython-39.pyc
Binary file not shown.
Binary file added books/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added books/__pycache__/views.cpython-39.pyc
Binary file not shown.
7 changes: 7 additions & 0 deletions books/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin

# Register your models here.
from .models import Book


admin.site.register(Book)
5 changes: 5 additions & 0 deletions books/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class BooksConfig(AppConfig):
name = 'books'
24 changes: 24 additions & 0 deletions books/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated by Django 3.1.5 on 2021-01-30 12:42

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Book',
fields=[
('title', models.CharField(max_length=50)),
('author', models.CharField(max_length=50)),
('accessNo', models.CharField(max_length=50, primary_key=True, serialize=False)),
('availible', models.BooleanField(default=True)),
('image', models.ImageField(upload_to='images')),
],
),
]
Empty file added books/migrations/__init__.py
Empty file.
Binary file not shown.
Binary file added books/migrations/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
13 changes: 13 additions & 0 deletions books/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from django.db import models

# Create your models here.

class Book(models.Model):

title = models.CharField(max_length= 50)
author = models.CharField(max_length= 50)
accessNo = models.CharField(max_length= 50,primary_key=True)
availible = models.BooleanField(default=True)
image = models.ImageField(upload_to="images")
def __str__(self):
return self.title
5 changes: 5 additions & 0 deletions books/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.test import TestCase

# Create your tests here.


12 changes: 12 additions & 0 deletions books/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from django.urls import path
from .views import issue,home,Signin,dashboard


urlpatterns = [

path('issue',issue,name="issue"),
path("",home,name = 'home'),
path("login",Signin,name = 'login'),
path("dashboard",dashboard,name = 'dashboard'),

]
87 changes: 87 additions & 0 deletions books/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
from django.shortcuts import render , redirect
from django.contrib.auth.models import User
# Create your views here.
from django.contrib.auth import authenticate,login
from profiles.models import Profile ,Record
from books.models import Book
from django.utils.timezone import now

def issue(request):
code = request.GET.get('code')
book = Book.objects.filter(accessNo=code)
if book[0].availible==True:
if request.method == "POST":
username = request.POST["id"]
password = request.POST["pass"]

user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
record = Record(acc = code,issue=now(),user=user )
record.save()
book.update(availible=False)
return redirect('login')

else:
return render(request,"401.html")

elif request.method == "POST":
username = request.POST["id"]
password = request.POST["pass"]

if username == "librarian" and password == '25654':
record = Record.objects.filter(acc=code).filter(back=None)
record.update(back=now())
Book.objects.filter(accessNo=code).update(availible=True)





return render(request,"issue.html")





def home(request):

books = Book.objects.all()

return render(request,'index.html',{'books':books})



def Signin(request):

if request.method=="POST":

username = request.POST["id"]
password = request.POST["pass"]

user = authenticate(username=username, password=password)
if user is not None:
login(request, user)


return redirect('dashboard')

else:
return render(request,"401.html")
return render(request,'login.html')


def dashboard(request):

user = request.user

record = Record.objects.filter(user=user)
profile = Profile.objects.filter(user=user)


context = {
'record':record,
'profile':profile,

}
return render(request,'dashboard.html',context)
Binary file added db.sqlite3
Binary file not shown.
Empty file added library/__init__.py
Empty file.
Binary file added library/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added library/__pycache__/settings.cpython-39.pyc
Binary file not shown.
Binary file added library/__pycache__/urls.cpython-39.pyc
Binary file not shown.
Binary file added library/__pycache__/wsgi.cpython-39.pyc
Binary file not shown.
16 changes: 16 additions & 0 deletions library/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for library project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'library.settings')

application = get_asgi_application()
142 changes: 142 additions & 0 deletions library/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
"""
Django settings for library project.
Generated by 'django-admin startproject' using Django 3.1.1.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'eb%ycsb2(h!_%sxbqu9=w$$^pf_+bagr23e3o33$n^q&dcs8(^'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'books',
'profiles',
'main',
]

MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'library.urls'

TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]

WSGI_APPLICATION = 'library.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}


# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]


# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/


EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_FILE_PATH = os.path.join(BASE_DIR, 'media/emails')
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_USE_TLS = True
EMAIL_PORT = 587
EMAIL_HOST_USER = '[email protected]'
EMAIL_HOST_PASSWORD = 'fvmozldcqazvgtim'









STATIC_URL = '/static/'
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
28 changes: 28 additions & 0 deletions library/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""library URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path ,include
from django.conf.urls.static import static
from django.conf import settings
import books.urls

urlpatterns = [
path('admin/', admin.site.urls),
path('',include('books.urls'))
] + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

if settings.DEBUG:
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
16 changes: 16 additions & 0 deletions library/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
WSGI config for library project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""

import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'library.settings')

application = get_wsgi_application()
Empty file added main/__init__.py
Empty file.
Binary file added main/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file added main/__pycache__/admin.cpython-39.pyc
Binary file not shown.
Binary file added main/__pycache__/models.cpython-39.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions main/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions main/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class MainConfig(AppConfig):
name = 'main'
Empty file added main/migrations/__init__.py
Empty file.
Binary file added main/migrations/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions main/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
Loading

0 comments on commit cb0c8a2

Please sign in to comment.