Beispiel #1
0
def returnBook_view(request, pk):
    book_instance = get_object_or_404(BookInstance, pk=pk)

    if book_instance.status == 'r':
        book_instance.returnedBooks = ReturnedBooks(
            user=book_instance.borrower,
            return_date=datetime.date.today(),
            book=book_instance.book)
        book_instance.returnedBooks.save()
        book_instance.status = 'a'
        book_instance.borrower = None
        book_instance.due_back = None
        book_instance.save()

        actionString = request.user.first_name + ' returned book  "' + book_instance.book.title + '".'
        log = Log(user=request.user,
                  action=actionString,
                  item="book instance",
                  timestamp=datetime.datetime.now())
        log.save()

        return redirect('/catalog/onloan/')
    else:
        return redirect('/catalog/')
    return render(request, 'book_detail.html')
Beispiel #2
0
 def form_valid(self, form):
     self.object = form.save()
     actionString = self.request.user.first_name + " " + self.request.user.last_name + " added author '" + self.object.given_name + " " + self.object.last_name + "'."
     log = Log(user=self.request.user,
               action=actionString,
               item=self.object,
               timestamp=datetime.datetime.now())
     log.save()
     return super(AuthorCreate, self).form_valid(form)
Beispiel #3
0
 def form_valid(self, form):
     self.object = form.save()
     actionString = self.request.user.first_name + " " + self.request.user.last_name + " modified genre '" + self.object.name + "'."
     log = Log(user=self.request.user,
               action=actionString,
               item=self.object,
               timestamp=datetime.datetime.now())
     log.save()
     #print("REACH BOOK INSTANCE CREATE IF VALID")
     return super(GenreUpdate, self).form_valid(form)
Beispiel #4
0
 def form_valid(self, form):
     self.object = form.save()
     actionString = self.request.user.first_name + " " + self.request.user.last_name + " edited a book instance " + self.object.book.title + "'."
     log = Log(user=self.request.user,
               action=actionString,
               item=self.object,
               timestamp=datetime.datetime.now())
     log.save()
     #print("REACH BOOK UPDATE IF VALID")
     return super(BookInstanceUpdate, self).form_valid(form)
Beispiel #5
0
 def form_valid(self, form):
     self.object = form.save()
     actionString = self.request.user.first_name + " " + self.request.user.last_name + " added book '" + self.object.title + "'."
     log = Log(user=self.request.user,
               action=actionString,
               item=self.object,
               timestamp=datetime.datetime.now())
     log.save()
     print("REACH BOOK CREATE IF VALID")
     return super(BookCreate, self).form_valid(form)
Beispiel #6
0
 def delete(self, request, *args, **kwargs):
     actionString = self.request.user.first_name + " " + self.request.user.last_name + ' deleted a genre.'
     Book.objects.filter(name=self.object.pk).delete()
     self.object.delete()
     log = Log(user=self.request.user,
               action=actionString,
               item="book",
               timestamp=datetime.datetime.now())
     log.save()
     #print("REACH BOOK DELETE")
     return HttpResponseRedirect(reverse_lazy('bookinstance_modify'))
Beispiel #7
0
 def delete(self, request, *args, **kwargs):
     self.object = self.get_object()
     Book.objects.filter(author=self.object.pk).delete()
     BookInstance.objects.filter(book__isnull=True).delete()
     actionString = self.request.user.first_name + " " + self.request.user.last_name + ' deleted a book.'
     self.object.delete()
     log = Log(user=self.request.user,
               action=actionString,
               item="book",
               timestamp=datetime.datetime.now())
     log.save()
     print("REACH BOOK DELETE")
     return HttpResponseRedirect(reverse_lazy('author_modify'))
Beispiel #8
0
def passwordReset_view(request):
    form = QuestionForm(request.POST)
    uEmail = request.session['user_email']
    request.user = uEmail
    user = request.user
    print(user)
    if form.is_valid():
        answer = form.cleaned_data['answer']
        print(user.profile.answer)
        if answer == user.profile.answer:
            actionString = user.profile.first_name + " " + user.profile.last_name + ' reseted password.'
            log = Log(user=request.user,
                      action=actionString,
                      item="User",
                      timestamp=datetime.datetime.now())
            log.save()
            return redirect('/passwordchange/')
        else:
            print(form.errors)
    else:
        form = QuestionForm()
    return render(request, 'password_question.html', {'form': form})
Beispiel #9
0
def staff_add_view(request):
    form = SignUpForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            user = form.save()
            user.refresh_from_db()
            user.profile.first_name = form.cleaned_data.get('first_name')
            user.profile.last_name = form.cleaned_data.get('last_name')
            user.profile.idno = form.cleaned_data.get('idno')
            user.profile.email = form.cleaned_data.get('email')
            user.profile.question = form.cleaned_data.get('question')
            user.profile.answer = form.cleaned_data.get('answer')
            permission = Permission.objects.get(codename='can_mark_returned')
            user.user_permissions.add(permission)
            user.save()
            my_group = Group.objects.get(name='Staff')
            my_group.user_set.add(user)
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')

            user = authenticate(username=username,
                                password=password,
                                request=request)
            login(request, user)
            messages.success(request, f'Account created for {username}!')

            actionString = user.profile.first_name + " " + user.profile.last_name + ' created an account.'
            log = Log(user=request.user,
                      action=actionString,
                      item="User",
                      timestamp=datetime.datetime.now())
            log.save()
            return redirect('/catalog/')
        else:
            print(form.errors)
            messages.error(request, "Can't SignUp")
    else:
        form = SignUpForm()
    return render(request, 'staff_form.html', {'form': form})
Beispiel #10
0
def reviewCreate_view(request, pk):
    book = get_object_or_404(Book, pk=pk)
    form = commentForm(request.POST)
    if request.method == "POST":
        if form.is_valid():
            review = form.save(commit=False)
            review.user = request.user
            review.book = book
            review.rating = form.cleaned_data.get('rating')
            review.save()

            actionString = request.user.first_name + ' commented on ' + review.book.title
            log = Log(user=request.user,
                      action=actionString,
                      item=book,
                      timestamp=datetime.datetime.now())
            log.save()
            return redirect('/catalog/book/' + str(book.pk))
        else:
            print(form.errors)
    else:
        form = commentForm()
    return render(request, 'catalog/review_form.html', {'form': form})