From 3928f602bf0e4d36db3e702990bf129867bd4f28 Mon Sep 17 00:00:00 2001
From: prathamesh
Date: Mon, 12 Sep 2016 17:54:06 +0530
Subject: interface to add start date and end time for book.
Initial books log were not maintained by the app as they were completed
before the TBC interface.
Interface to manually enter their details.
---
tbc/forms.py | 2 ++
tbc/models.py | 2 ++
tbc/templates/tbc/books.html | 27 +++++++++++++++++++++++++++
tbc/templates/tbc/edit-book.html | 30 ++++++++++++++++++++++++++++++
tbc/urls.py | 2 ++
tbc/views.py | 40 ++++++++++++++++++++++++++++++++++++++++
6 files changed, 103 insertions(+)
create mode 100644 tbc/templates/tbc/books.html
create mode 100644 tbc/templates/tbc/edit-book.html
diff --git a/tbc/forms.py b/tbc/forms.py
index f1a1328..1aa1e6c 100644
--- a/tbc/forms.py
+++ b/tbc/forms.py
@@ -71,4 +71,6 @@ class BookForm(forms.ModelForm):
'edition':forms.TextInput(attrs={'placeholder':'Edition of the Book'}),
'year_of_pub':forms.TextInput(attrs={'placeholder':'Year when the Book was published'}),
'no_chapters':forms.TextInput(attrs={'placeholder':'Total number of chapters in the Book (only include chapters that have solved examples)'}),
+ 'start_time': forms.DateInput(attrs={'class':'datepicker'}),
+ 'end_time': forms.DateInput(attrs={'class':'datepicker'}),
}
diff --git a/tbc/models.py b/tbc/models.py
index 44571ba..0747882 100644
--- a/tbc/models.py
+++ b/tbc/models.py
@@ -104,6 +104,8 @@ class Book(models.Model):
contributor = models.ForeignKey(Profile)
reviewer = models.ForeignKey(Reviewer)
approved = models.BooleanField(default=False)
+ start_time = models.DateField(null=True, default=None)
+ end_time = models.DateField(null=True, default=None)
tags = TaggableManager()
def __unicode__(self):
name = self.title or 'Book'
diff --git a/tbc/templates/tbc/books.html b/tbc/templates/tbc/books.html
new file mode 100644
index 0000000..b1d975f
--- /dev/null
+++ b/tbc/templates/tbc/books.html
@@ -0,0 +1,27 @@
+{% extends 'base.html' %}
+{% load static %}
+
+{% block content %}
+
+
+
Books without start and end time
+
+ {% for book in books_incomplete %}
+ - {{ book.title }}
+ {% endfor %}
+
+
+
+
Books with start and end time
+
+ {% for book in books_complete %}
+ - {{ book.title }}
+ {% endfor %}
+
+
+
+
+
+
+{% endblock %}
+
diff --git a/tbc/templates/tbc/edit-book.html b/tbc/templates/tbc/edit-book.html
new file mode 100644
index 0000000..e630e78
--- /dev/null
+++ b/tbc/templates/tbc/edit-book.html
@@ -0,0 +1,30 @@
+{% extends 'base.html' %}
+{% load static %}
+{% block script %}
+
+
+
+
+{% endblock %}
+{% block content %}
+
+
+{% endblock %}
+
diff --git a/tbc/urls.py b/tbc/urls.py
index 6c75ab3..3db075b 100644
--- a/tbc/urls.py
+++ b/tbc/urls.py
@@ -52,6 +52,8 @@ urlpatterns = patterns('',
url(r'^notify-changes/(?P\d+)$', 'tbc.views.notify_changes', name='notify_changes'),
url(r'^brokenbooks/$', 'tbc.views.get_broken_books', name='broken_books'),
url(r'^link-image/$', 'tbc.views.link_image', name='link_image'),
+ url(r'^books/$', 'tbc.views.books', name='books'),
+ url(r'^edit-book/(?P\d+)/$', 'tbc.views.edit_book', name='edit_book'),
# ajax urls
url(r'^ajax/matching-books/$', 'tbc.views.ajax_matching_books', name='AjaxMatchingBooks'),
diff --git a/tbc/views.py b/tbc/views.py
index 63de3f8..647037d 100644
--- a/tbc/views.py
+++ b/tbc/views.py
@@ -366,6 +366,46 @@ def update_password(request):
return render_to_response("tbc/login.html", context)
+def books(request):
+ user = request.user
+ if user.is_superuser:
+ books = Book.objects.all()
+ books_incomplete = []
+ books_complete = []
+ for book in books:
+ if book.start_time is None or book.end_time is None:
+ books_incomplete.append(book)
+ else:
+ books_complete.append(book)
+ context = {'books_incomplete': books_incomplete, 'books_complete': books_complete}
+ return render_to_response('tbc/books.html', context)
+ else:
+ return HttpResponseRedirect("/login/?require_login=true")
+
+
+def edit_book(request, book_id):
+ user = request.user
+ if user.is_superuser:
+ book = Book.objects.get(id=book_id)
+ context = {}
+ context.update(csrf(request))
+ if request.method == 'POST':
+ form = BookForm(request.POST, instance=book)
+ if form.is_valid():
+ form.save()
+ return books(request)
+ else:
+ context['form'] = form
+ context['book'] = book
+ return render_to_response('tbc/edit-book.html', context)
+ form = BookForm(instance=book)
+ context['form'] = form
+ context['book'] = book
+ return render_to_response('tbc/edit-book.html', context)
+ else:
+ return HttpResponseRedirect("/login/?require_login=true")
+
+
def submit_book(request):
context = {}
if request.user.is_anonymous():
--
cgit