Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'all_task_done' #10

Open
wants to merge 1 commit 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
15 changes: 15 additions & 0 deletions authentication/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> Library|authentication </title>
</head>
<body>
{% block content %}

{% endblock %}
</body>
</html>

12 changes: 12 additions & 0 deletions authentication/templates/register.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'home.html' %}

{% block content %}
<h1>Create New Account</h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button>
Register
</button>
</form>
{% endblock %}
12 changes: 12 additions & 0 deletions authentication/templates/registration/login.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends 'home.html' %}

{% block content %}
<h1>Login to account</h1>
<form method="POST">
{% csrf_token %}
{{ form.as_p }}
<button>
login
</button>
</form>
{% endblock %}
10 changes: 10 additions & 0 deletions authentication/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

from django.urls import path
from . import views
from django.contrib.auth.views import LoginView
urlpatterns = [
path('',views.indexView, name="home"),
path('login/',LoginView.as_view(),name="login_url"),
path('register/',views.registerView,name="register_url"),
# path('logout/',),
]
21 changes: 13 additions & 8 deletions authentication/views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.contrib.auth import login,logout,authenticate
from django.contrib.auth.forms import UserCreationForm
# Create your views here.


def loginView(request):
pass

def logoutView(request):
pass
def indexView(request):
return render(request,'home.html')

def registerView(request):
pass
if request.method == "POST":
form = UserCreationForm(request.POST)
if form.is_valid():
form.save()
return redirect('login_url')
else:
form = UserCreationForm()
return render(request,'register.html', { 'form': form })

2 changes: 1 addition & 1 deletion library/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'
TIME_ZONE = 'Asia/Kolkata'

USE_I18N = True

Expand Down
2 changes: 2 additions & 0 deletions library/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
from django.contrib import admin
from django.urls import path,include
from django.conf.urls.static import static
from django.views.generic import RedirectView
from django.conf import settings

urlpatterns = [
path('',include('store.urls')),
path('',include('authentication.urls')),
path('admin/', admin.site.urls),
path('accounts/',include('django.contrib.auth.urls')),
]+static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
25 changes: 25 additions & 0 deletions store/migrations/0003_auto_20210717_1506.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.2.1 on 2021-07-17 09:36

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('store', '0002_auto_20190607_1302'),
]

operations = [
migrations.AlterField(
model_name='bookcopy',
name='borrow_date',
field=models.DateField(blank=True, null=True),
),
migrations.AlterField(
model_name='bookcopy',
name='borrower',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='borrower', to=settings.AUTH_USER_MODEL),
),
]
25 changes: 25 additions & 0 deletions store/migrations/0004_bookrating.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 2.2.1 on 2021-07-21 10:16

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('store', '0003_auto_20210717_1506'),
]

operations = [
migrations.CreateModel(
name='BookRating',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('rate', models.FloatField(default=0.0)),
('book', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='store.Book')),
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)),
],
),
]
15 changes: 13 additions & 2 deletions store/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from django.db import models
from django.contrib.auth.models import User

# Create your models here.

class Book(models.Model):
Expand All @@ -8,7 +9,7 @@ class Book(models.Model):
genre = models.CharField(max_length=50)
description = models.TextField(null=True)
mrp = models.PositiveIntegerField()
rating = models.FloatField(default=0.0)
rating = models.PositiveIntegerField(default=0)

class Meta:
ordering = ('title',)
Expand All @@ -17,10 +18,20 @@ def __str__(self):
return f'{self.title} by {self.author}'


class BookRating(models.Model):
book = models.ForeignKey(Book, on_delete=models.CASCADE)
rate = models.PositiveIntegerField(default=0)
user = models.ForeignKey(User,null=True,blank=True, on_delete=models.SET_NULL)

def __str__(self):
return f'{self.book}'




class BookCopy(models.Model):
book = models.ForeignKey(Book, on_delete=models.CASCADE)
borrow_date = models.DateField(null=True, blank=True)
# True status means that the copy is available for issue, False means unavailable
status = models.BooleanField(default=False)
borrower = models.ForeignKey(User, related_name='borrower', null=True, blank=True, on_delete=models.SET_NULL)

Expand Down
14 changes: 8 additions & 6 deletions store/templates/store/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,31 @@

<div class="container-fluid">

<div class="row">
<div class="row" >
<div class="col-sm-2">
{% block sidebar %}
<ul class="sidebar-nav">
<ul class="sidebar-nav" style="margin-top:50px; font-size:20px">
<li><a href="{% url 'index' %}">Home</a></li>
<li><a href="{% url 'book-list' %}">All books</a></li>
</ul>

<ul class="sidebar-nav">
<ul class="sidebar-nav" style="font-size:20px">
{% if user.is_authenticated %}
<li>User: {{ user.first_name }}</li>
<li>User: {{ user.username }}</li>
<li><a href="{% url 'view-loaned' %}">My Borrowed</a></li>
<li><a href="{% url 'logout' %}">Logout</a></li>
{% else %}
<!-- <li><a href="{% url 'login'%}">Login</a></li> -->
<li><a href="{% url 'register_url'%}">Register</a></li>
<li><a href="{% url 'login_url'%}">Login</a></li>
{% endif %}
</ul>


{% endblock %}
</div>
<div class="col-sm-10 ">
{% block content %}{% endblock %}
{% block content %}
{% endblock %}
</div>
</div>

Expand Down
63 changes: 50 additions & 13 deletions store/templates/store/book_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,30 +20,67 @@ <h2>Title: {{ book.title }}</h2>
<dd>Rs. {{ book.mrp }}</dd>
<dt>Available Copies:</dt>
<dd>{{ num_available }}</dd>


{% if user.is_authenticated %}
<dt>Rate Book:</dt>
<dd>
<input id="rating" type="number" min="0" max="10" value="{{ book.rating }}">
<button class="btn btn-primary" id= "rate-button" onclick="rateBook()">Rate {{ book.title }}</button>
</dd>
<br>
<button class="btn btn-primary" id="loan-button">Loan {{ book.title }}</button>
{% endif %}
</dl>
<button class="btn btn-primary" id="loan-button">Loan {{ book.title }}</button>

<script>
$("#loan-button").click(function(){
$.ajax({
url: "{% url 'loan-book' %}",
method: "POST",
data: {
bid: {{ book.id }}
$.ajax({
url: "{% url 'loan-book' %}",
method: "POST",
data: {
bid: {{ book.id }}
},
success: function(data, status, xhr){
if(data['message'] == "success"){
alert("Book successfully issued");
window.location.replace("/books/loaned");
}
else{
alert("No copies available for this book");
}
},
error: function(xhr, status, err){
alert("Some error occured");
}

})
})


function rateBook(){
const rating = document.getElementById("rating").value
$.ajax({
url: "{% url 'rate-book'%}",
method:"POST",
data:{
bid: {{ book.id }},
rating: rating,
},
success: function(data, status, xhr){
if(data['message'] == "success"){
alert("Book successfully issued");
window.location.replace("/books/loaned");
if(data['message']=="success"){
location.reload();
alert('Thanks for rating');
}
else{
alert("Unable to issue this book");
alert("Unable to rate this book");
}
},
error: function(xhr, status, err){
alert("Some error occured");
alert(err);
}

})
})
}

</script>
{% endblock %}
2 changes: 1 addition & 1 deletion store/templates/store/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@

{% block content %}

<h3>Welcome to the library. This is your homepage.</h3>
<h3 style="margin-top: 20px; margin-left:10%; font-size:45px"> <b> Welcome to the library. This is your homepage.</b> </h3>
{% endblock %}
23 changes: 21 additions & 2 deletions store/templates/store/loaned_books.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,26 @@ <h3>Loaned Books list</h3>
<script>
// Fill in this function by yourself. It should make a post call to the returnBookView and display an appropriate message
function returnBook(bid){
;
}
$.ajax({
url: '{%url "return-book"%}',
method: "POST",
data: {
'id':bid,
},
success: function(data, status, xhr){
if(data['message'] == "success"){
alert("Book returned!");
location.reload();
}
else{
alert(data['message']);
}
},
error: function(xhr, status, err){
alert('login error');
}
})
};

</script>
{% endblock %}
3 changes: 2 additions & 1 deletion store/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
path('books/loaned/', viewLoanedBooks, name="view-loaned"),
path('books/loan/', loanBookView, name="loan-book"),
path('books/return/', returnBookView, name="return-book"),
]
path('book/rate/',rateBookView,name='rate-book'),
]
Loading