diff options
-rw-r--r-- | tbc/forms.py | 2 | ||||
-rw-r--r-- | tbc/models.py | 2 | ||||
-rw-r--r-- | tbc/templates/tbc/books.html | 27 | ||||
-rw-r--r-- | tbc/templates/tbc/edit-book.html | 30 | ||||
-rw-r--r-- | tbc/urls.py | 2 | ||||
-rw-r--r-- | tbc/views.py | 40 |
6 files changed, 103 insertions, 0 deletions
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 %} +<div class="row-fluid"> + <div class="span6"> + <u> Books without start and end time </u> + <ol> + {% for book in books_incomplete %} + <li><a href="{% url 'tbc:edit_book' book.id %}"> {{ book.title }} </a> </li> + {% endfor %} + </ol> + </div> + <div class="span6"> + <u> Books with start and end time </u> + <ol> + {% for book in books_complete %} + <li><a href="{% url 'tbc:edit_book' book.id %}"> {{ book.title }} </a></li> + {% endfor %} + </ol> + </div> +</div> + + + +{% 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 %} +<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet"> +<script src="http://code.jquery.com/jquery-1.10.2.js"></script> +<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script> +<script> + +$(document).ready(function() { + console.log("rogkor") + $(".datepicker" ).datepicker({ + changeMonth: true, + changeYear: true, + yearRange: "2000:2030", + }); + }); +</script> +{% endblock %} +{% block content %} +<div class="well"> + <center><a href="{% url 'tbc:books' %}" class="btn btn-primary"> BACK </a></center> + <form action="{% url 'tbc:edit_book' book.id %}" method="POST"> + {% csrf_token %} + {{ form.as_p }} + <center><input class="btn btn-primary" type="submit" value="SAVE"></center> + </form> +</div> + +{% 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<book_id>\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<book_id>\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(): |