Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

CSOC TASK 2 #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

I have completed the following tasks

- [ ] Stage 1
- [ ] Stage 2
- [ ] Stage 3
- [ ] Stage 4
- [x] Stage 1
- [x] Stage 2
- [x] Stage 3
- [x] Stage 4
3 changes: 0 additions & 3 deletions authentication/admin.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
from django.contrib import admin

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

# Create your models here.
15 changes: 15 additions & 0 deletions authentication/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{% extends "store/base.html" %}

{% block content %}
<h1>Login here :</h1>
<form method="post" action="{% url 'login' %}">
{% csrf_token %}
{# A more "HTML" way of creating the login form#}
<label for="username">Username:</label>
<input type="text" name="username" placeholder="Username">
<label for="password">Password:</label>
<input type="password" name="password" placeholder="Password">
<input type="submit" name="" value="Login">
<div id="error" style="color: red;">{%if error%}{{error}}{%endif%}</div>
</form>
{% endblock %}
6 changes: 6 additions & 0 deletions authentication/templates/registration/logout.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{% extends "store/base.html" %}

{% block content %}
<h2>Logged Out</h2>
<p>You have been logged out. You may <a href="{% url 'login' %}">log back in</a>.</p>
{% endblock %}
34 changes: 34 additions & 0 deletions authentication/templates/registration/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{% extends "store/base.html" %}

{% block content %}
<h2>Sign up</h2>
<form method="post">
{% csrf_token %}
<div class="form-group">
<label>First Name:</label>
<input type="text" name="firstname" class="form-control" placeholder="Enter First Name" id="inputFirstname" required/>
</div>
<div class="form-group">
<label>Last Name:</label>
<input type="text" name="lastname" class="form-control" placeholder="Enter Last Name" id="inputLastname" required/>
</div>
<div class="form-group">
<label>Username:</label>
<input type="text" class="form-control" placeholder="Enter Username" name="username" id="inputusername" required/>
</div>
<div class="form-group">
<label >Email:</label>
<input type="email" class="form-control" placeholder="Enter Email" name="email" id="inputEmail">
</div>
<div class="form-group">
<label>Password:</label>
<input type="password" class="form-control" placeholder="Enter password" name="password1" id="inputPassword1" required/>
</div>
<div class="form-group">
<label>Enter Password Again:</label>
<input type="password" class="form-control" placeholder="Re-Enter password" name="password2" id="inputPassword2" required/>
</div>
<button type="submit" class="btn btn-primary">Sign Up</button>
{% if msg %}<script>alert("{{msg}}")</script>{% endif %}
</form>
{% endblock %}
8 changes: 8 additions & 0 deletions authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from authentication.views import *

urlpatterns = [
path('login/', loginView, name="login"),
path('logout/', logoutView, name="logout" ),
path('register/', registerView, name="register" ),
]
56 changes: 51 additions & 5 deletions authentication/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,59 @@
from django.shortcuts import render
from django.shortcuts import render,redirect
from django.contrib.auth import login,logout,authenticate
from django.http import HttpResponseRedirect, HttpResponse
from django.urls import reverse
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
# Create your views here.


def loginView(request):
pass

if request.method == 'POST':
username = request.POST.get('username')
password = request.POST.get('password')
user = authenticate(username=username, password=password)
if user:
login(request,user)
return redirect('/')
else:
return render(request, 'registration/login.html', {'error':"Invalid UserName or Password"})
else:
return render(request, 'registration/login.html', {})
@login_required
def logoutView(request):
pass
logout(request)
return redirect('/')

def registerView(request):
pass
if request.method=="POST":
try:
username=request.POST['username']
password1=request.POST['password1']
password2=request.POST['password2']
firstname=request.POST['firstname']
lastname=request.POST['lastname']
email=request.POST['email']
except:
return render(request,'registration/register.html',{'msg':"Fill All The Fields"})
if password1 != password2:
return render(request, 'registration/register.html', { 'msg': "Passwords not matching" })
try:
user = User.objects.create_user(
username = username,
first_name = firstname,
last_name = lastname,
email = email,
password = password1
)
user.save()
except:
return render(request, 'registration/register.html', { 'msg': "Username already exists" })
user = authenticate(request, username=username, password=password1)
if user is not None:
login(request, user)
return redirect('/')
else:
return render(request, 'registration/register.html', { 'msg': "User created Successfully" })
else:
return render(request, 'registration/register.html')

1 change: 0 additions & 1 deletion library/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
STATIC_URL = '/static/'
STATIC_ROOT=os.path.join(BASE_DIR,'staticfiles/')
LOGIN_REDIRECT_URL='/'
LOGOUT_REDIRECT_URL = '/'

# Activate Django-Heroku.
django_heroku.settings(locals())
2 changes: 1 addition & 1 deletion library/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@
urlpatterns = [
path('',include('store.urls')),
path('admin/', admin.site.urls),
path('accounts/',include('django.contrib.auth.urls')),
path('',include('authentication.urls')),
]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
51 changes: 51 additions & 0 deletions myvenv/Scripts/Activate.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
function global:deactivate ([switch]$NonDestructive) {
# Revert to original values
if (Test-Path function:_OLD_VIRTUAL_PROMPT) {
copy-item function:_OLD_VIRTUAL_PROMPT function:prompt
remove-item function:_OLD_VIRTUAL_PROMPT
}

if (Test-Path env:_OLD_VIRTUAL_PYTHONHOME) {
copy-item env:_OLD_VIRTUAL_PYTHONHOME env:PYTHONHOME
remove-item env:_OLD_VIRTUAL_PYTHONHOME
}

if (Test-Path env:_OLD_VIRTUAL_PATH) {
copy-item env:_OLD_VIRTUAL_PATH env:PATH
remove-item env:_OLD_VIRTUAL_PATH
}

if (Test-Path env:VIRTUAL_ENV) {
remove-item env:VIRTUAL_ENV
}

if (!$NonDestructive) {
# Self destruct!
remove-item function:deactivate
}
}

deactivate -nondestructive

$env:VIRTUAL_ENV="C:\Users\gupta\csoc-2020-task-2\myvenv"

if (! $env:VIRTUAL_ENV_DISABLE_PROMPT) {
# Set the prompt to include the env name
# Make sure _OLD_VIRTUAL_PROMPT is global
function global:_OLD_VIRTUAL_PROMPT {""}
copy-item function:prompt function:_OLD_VIRTUAL_PROMPT
function global:prompt {
Write-Host -NoNewline -ForegroundColor Green '(myvenv) '
_OLD_VIRTUAL_PROMPT
}
}

# Clear PYTHONHOME
if (Test-Path env:PYTHONHOME) {
copy-item env:PYTHONHOME env:_OLD_VIRTUAL_PYTHONHOME
remove-item env:PYTHONHOME
}

# Add the venv to the PATH
copy-item env:PATH env:_OLD_VIRTUAL_PATH
$env:PATH = "$env:VIRTUAL_ENV\Scripts;$env:PATH"
76 changes: 76 additions & 0 deletions myvenv/Scripts/activate
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# This file must be used with "source bin/activate" *from bash*
# you cannot run it directly

deactivate () {
# reset old environment variables
if [ -n "${_OLD_VIRTUAL_PATH:-}" ] ; then
PATH="${_OLD_VIRTUAL_PATH:-}"
export PATH
unset _OLD_VIRTUAL_PATH
fi
if [ -n "${_OLD_VIRTUAL_PYTHONHOME:-}" ] ; then
PYTHONHOME="${_OLD_VIRTUAL_PYTHONHOME:-}"
export PYTHONHOME
unset _OLD_VIRTUAL_PYTHONHOME
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r
fi

if [ -n "${_OLD_VIRTUAL_PS1:-}" ] ; then
PS1="${_OLD_VIRTUAL_PS1:-}"
export PS1
unset _OLD_VIRTUAL_PS1
fi

unset VIRTUAL_ENV
if [ ! "${1:-}" = "nondestructive" ] ; then
# Self destruct!
unset -f deactivate
fi
}

# unset irrelevant variables
deactivate nondestructive

VIRTUAL_ENV="C:\Users\gupta\csoc-2020-task-2\myvenv"
export VIRTUAL_ENV

_OLD_VIRTUAL_PATH="$PATH"
PATH="$VIRTUAL_ENV/Scripts:$PATH"
export PATH

# unset PYTHONHOME if set
# this will fail if PYTHONHOME is set to the empty string (which is bad anyway)
# could use `if (set -u; : $PYTHONHOME) ;` in bash
if [ -n "${PYTHONHOME:-}" ] ; then
_OLD_VIRTUAL_PYTHONHOME="${PYTHONHOME:-}"
unset PYTHONHOME
fi

if [ -z "${VIRTUAL_ENV_DISABLE_PROMPT:-}" ] ; then
_OLD_VIRTUAL_PS1="${PS1:-}"
if [ "x(myvenv) " != x ] ; then
PS1="(myvenv) ${PS1:-}"
else
if [ "`basename \"$VIRTUAL_ENV\"`" = "__" ] ; then
# special case for Aspen magic directories
# see http://www.zetadev.com/software/aspen/
PS1="[`basename \`dirname \"$VIRTUAL_ENV\"\``] $PS1"
else
PS1="(`basename \"$VIRTUAL_ENV\"`)$PS1"
fi
fi
export PS1
fi

# This should detect bash and zsh, which have a hash command that must
# be called to get it to forget past commands. Without forgetting
# past commands the $PATH changes we made may not be respected
if [ -n "${BASH:-}" -o -n "${ZSH_VERSION:-}" ] ; then
hash -r
fi
33 changes: 33 additions & 0 deletions myvenv/Scripts/activate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@echo off

rem This file is UTF-8 encoded, so we need to update the current code page while executing it
for /f "tokens=2 delims=:." %%a in ('"%SystemRoot%\System32\chcp.com"') do (
set _OLD_CODEPAGE=%%a
)
if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" 65001 > nul
)

set VIRTUAL_ENV=C:\Users\gupta\csoc-2020-task-2\myvenv

if not defined PROMPT set PROMPT=$P$G

if defined _OLD_VIRTUAL_PROMPT set PROMPT=%_OLD_VIRTUAL_PROMPT%
if defined _OLD_VIRTUAL_PYTHONHOME set PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%

set _OLD_VIRTUAL_PROMPT=%PROMPT%
set PROMPT=(myvenv) %PROMPT%

if defined PYTHONHOME set _OLD_VIRTUAL_PYTHONHOME=%PYTHONHOME%
set PYTHONHOME=

if defined _OLD_VIRTUAL_PATH set PATH=%_OLD_VIRTUAL_PATH%
if not defined _OLD_VIRTUAL_PATH set _OLD_VIRTUAL_PATH=%PATH%

set PATH=%VIRTUAL_ENV%\Scripts;%PATH%

:END
if defined _OLD_CODEPAGE (
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
set _OLD_CODEPAGE=
)
21 changes: 21 additions & 0 deletions myvenv/Scripts/deactivate.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
@echo off

if defined _OLD_VIRTUAL_PROMPT (
set "PROMPT=%_OLD_VIRTUAL_PROMPT%"
)
set _OLD_VIRTUAL_PROMPT=

if defined _OLD_VIRTUAL_PYTHONHOME (
set "PYTHONHOME=%_OLD_VIRTUAL_PYTHONHOME%"
set _OLD_VIRTUAL_PYTHONHOME=
)

if defined _OLD_VIRTUAL_PATH (
set "PATH=%_OLD_VIRTUAL_PATH%"
)

set _OLD_VIRTUAL_PATH=

set VIRTUAL_ENV=

:END
Binary file added myvenv/Scripts/django-admin.exe
Binary file not shown.
5 changes: 5 additions & 0 deletions myvenv/Scripts/django-admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!c:\users\gupta\csoc-2020-task-2\myvenv\scripts\python.exe
from django.core import management

if __name__ == "__main__":
management.execute_from_command_line()
Binary file added myvenv/Scripts/easy_install-3.7.exe
Binary file not shown.
Binary file added myvenv/Scripts/easy_install.exe
Binary file not shown.
Binary file added myvenv/Scripts/epylint.exe
Binary file not shown.
Binary file added myvenv/Scripts/gunicorn.exe
Binary file not shown.
Binary file added myvenv/Scripts/isort.exe
Binary file not shown.
Binary file added myvenv/Scripts/pip.exe
Binary file not shown.
Binary file added myvenv/Scripts/pip3.7.exe
Binary file not shown.
Binary file added myvenv/Scripts/pip3.exe
Binary file not shown.
Binary file added myvenv/Scripts/pylint.exe
Binary file not shown.
Binary file added myvenv/Scripts/pyreverse.exe
Binary file not shown.
Binary file added myvenv/Scripts/python.exe
Binary file not shown.
Binary file added myvenv/Scripts/pythonw.exe
Binary file not shown.
Binary file added myvenv/Scripts/sqlformat.exe
Binary file not shown.
Binary file added myvenv/Scripts/symilar.exe
Binary file not shown.
Binary file added myvenv/Scripts/wheel.exe
Binary file not shown.
3 changes: 3 additions & 0 deletions myvenv/pyvenv.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
home = C:\Users\gupta\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0
include-system-site-packages = false
version = 3.7.7
15 changes: 13 additions & 2 deletions store/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,16 @@
from store.models import *
# Register your models here.

admin.site.register(Book)
admin.site.register(BookCopy)
#admin.site.register(Book)
#admin.site.register(BookCopy)
@admin.register(Book)
class BookAdmin(admin.ModelAdmin):
list_display = ('title', 'author', 'genre')

# Register the Admin classes for BookInstance using the decorator
@admin.register(BookCopy)
class BookInstanceAdmin(admin.ModelAdmin):
list_filter = ('status', 'borrow_date')
list_display = ('book','status', 'borrow_date')

admin.site.register(BookRating)
Comment on lines +7 to +17
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Loading