예제 #1
0
def rent_book(request, k_id):
    """
    Metod za iznajmuvanje na kniga na user.
    requestot mora da se napravi od korisnik so can_add_rental permisija
    """
    kniga = get_object_or_404(Book, pk=k_id)
    if request.method == 'POST':
        if kniga.in_stock > 0:
            # kreiranje na forma so podatocite zemeni od POST
            form = RentalForm(request.POST)
            if form.is_valid():
                # korisnikot na koj mu se iznajmuva knigata
                user = form.cleaned_data['user']
                Rental.active_objects.rent_book(user, kniga)
                return HttpResponseRedirect(reverse('hacklab.biblioteka.views.index'))
        else:
            h = u'Изнајмувањето неможе да се изведе бидејќи нема преостанати копии.'
            return render_to_response(request, 'biblioteka/rent.html', {'heading':h})
    else:
        form = RentalForm()
        field = form.fields['user']
        qs = User.objects.exclude(rental__book=kniga, rental__returned_on=None)

        if qs.count() > 0:
            field.queryset = qs
    return render_to_response(request, 'biblioteka/rent.html',
            {'form':form, 'heading':u'Изнајмување на \"'+kniga.title+'\"'})
예제 #2
0
def rent_book(request, k_id):
    """
    Metod za iznajmuvanje na kniga na user.
    requestot mora da se napravi od korisnik so can_add_rental permisija
    """
    kniga = get_object_or_404(Book, pk=k_id)
    if request.method == 'POST':
        if kniga.in_stock > 0:
            # kreiranje na forma so podatocite zemeni od POST
            form = RentalForm(request.POST)
            if form.is_valid():
                # korisnikot na koj mu se iznajmuva knigata
                user = form.cleaned_data['user']
                Rental.active_objects.rent_book(user, kniga)
                return HttpResponseRedirect(
                    reverse('hacklab.biblioteka.views.index'))
        else:
            h = u'Изнајмувањето неможе да се изведе бидејќи нема преостанати копии.'
            return render_to_response(request, 'biblioteka/rent.html',
                                      {'heading': h})
    else:
        form = RentalForm()
        field = form.fields['user']
        qs = User.objects.exclude(rental__book=kniga, rental__returned_on=None)

        if qs.count() > 0:
            field.queryset = qs
    return render_to_response(
        request, 'biblioteka/rent.html', {
            'form': form,
            'heading': u'Изнајмување на \"' + kniga.title + '\"'
        })
예제 #3
0
def return_book(request, k_id):
    """
    Metod za vrakjanje na rezervirana kniga
    """
    # import na datetime za da se zapise vremeto na vrakjanje
    from datetime import datetime
    kniga = get_object_or_404(Book, pk=k_id)
    # zemanje na site korisnici koi ja imaat iznajmeno knigata (ako ima poveke kopii)
    users = User.objects.filter(rental__book=kniga, rental__returned_on=None)

    if request.method == "POST":
        # kreiranje na forma so podatocite zemeni od POST
        form = RentalForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data['user']
            Rental.active_objects.return_book(user, kniga)
    else:
        form = RentalForm()
        qs = User.objects.filter(rental__book=kniga, rental__returned_on=None)

        if qs.count() > 0:
            field = form.fields['user']
            field.queryset = qs
        return render_to_response(request, 'biblioteka/return.html', {
            'kniga': kniga,
            'form': form
        })
    return HttpResponseRedirect(reverse('hacklab.biblioteka.views.index'))
예제 #4
0
def history(request, rented_by=None, year=None, month=None):
    dates = Rental.objects.dates('rented_on', 'month')
    isbn = None
    if request.method == 'POST':
        try:
            isbn = request.POST['ISBN'].strip()
        except:
            pass

    if rented_by is None:
        if request.user.has_perm('can_add_rental'):
            rental_list = get_rental_list(year=year, month=month, ISBN=isbn)
        else:
            rental_list = get_rental_list(user=request.user,
                                          year=year,
                                          month=month,
                                          ISBN=isbn)
    else:
        rental_list = get_rental_list(user=rented_by,
                                      year=year,
                                      month=month,
                                      ISBN=isbn)
    path = "/".join(request.path.split('/')[1:3])
    return render_to_response(request, 'biblioteka/history.html', {
        'list': rental_list,
        'dates': dates,
        'path': path
    })
예제 #5
0
def by_author(request, a_id):
    """
    Metod za listanje na site knigi od avtor
    """
    author = get_object_or_404(Author, pk=a_id)
    return render_to_response(request, 'biblioteka/list.html',
            {'knigi':author.book_set.all(), 'heading':u'Листа на сите книги од \"'+author.name+'\"'})
예제 #6
0
def return_book(request, k_id):
    """
    Metod za vrakjanje na rezervirana kniga
    """
    # import na datetime za da se zapise vremeto na vrakjanje
    from datetime import datetime
    kniga = get_object_or_404(Book, pk=k_id)
    # zemanje na site korisnici koi ja imaat iznajmeno knigata (ako ima poveke kopii)
    users = User.objects.filter(rental__book=kniga, rental__returned_on=None)

    if request.method=="POST":
        # kreiranje na forma so podatocite zemeni od POST
        form = RentalForm(request.POST)
        if form.is_valid():
            user = form.cleaned_data['user']
            Rental.active_objects.return_book(user, kniga)
    else:
        form = RentalForm()
        qs = User.objects.filter(rental__book=kniga, rental__returned_on=None)

        if qs.count() > 0:
            field = form.fields['user']
            field.queryset = qs
        return render_to_response(request, 'biblioteka/return.html', {'kniga':kniga, 'form':form})
    return HttpResponseRedirect(reverse('hacklab.biblioteka.views.index'))
예제 #7
0
def by_publisher(request, p_id):
    """
    Metod za listanje na site knigi od izdavac
    """
    publisher = get_object_or_404(Publisher, pk=p_id)
    return render_to_response(request, 'biblioteka/list.html',
            {'knigi':publisher.book_set.all(), 'heading':u'Листа на сите книги од \"'+publisher.name+'\"'})
예제 #8
0
def by_year(request, godina):
    """
    Metod za listanje na site knigi od godina
    """
    books = Book.objects.filter(release_year=godina)
    return render_to_response(request, 'biblioteka/list.html',
            {'knigi':books, 'heading':'Листа на сите книги од ' + str(godina) +' година'})
예제 #9
0
def by_tag(request, tag):
    """
    Metod za listanje na site knigi spored odbran tag
    """
    books = Book.objects.filter(tags__contains=tag)
    return render_to_response(request, 'biblioteka/list.html',
            {'knigi':books, 'heading':u'Листа на сите книги со клучен збор \"'+tag+'\"'})
예제 #10
0
def index(request):
    """
    Metod za listanje na site knigi
    """
    books = Book.objects.all()
    return render_to_response(request, 'biblioteka/list.html',
            {'knigi':books, 'heading':'Листа на сите книги во ХакЛаб КИКА'})
예제 #11
0
def index(request):
    """
    Metod za listanje na site knigi
    """
    books = Book.objects.all()
    return render_to_response(request, 'biblioteka/list.html', {
        'knigi': books,
        'heading': 'Листа на сите книги во ХакЛаб КИКА'
    })
예제 #12
0
def by_publisher(request, p_id):
    """
    Metod za listanje na site knigi od izdavac
    """
    publisher = get_object_or_404(Publisher, pk=p_id)
    return render_to_response(
        request, 'biblioteka/list.html', {
            'knigi': publisher.book_set.all(),
            'heading': u'Листа на сите книги од \"' + publisher.name + '\"'
        })
예제 #13
0
def by_tag(request, tag):
    """
    Metod za listanje na site knigi spored odbran tag
    """
    books = Book.objects.filter(tags__contains=tag)
    return render_to_response(
        request, 'biblioteka/list.html', {
            'knigi': books,
            'heading': u'Листа на сите книги со клучен збор \"' + tag + '\"'
        })
예제 #14
0
def by_year(request, godina):
    """
    Metod za listanje na site knigi od godina
    """
    books = Book.objects.filter(release_year=godina)
    return render_to_response(
        request, 'biblioteka/list.html', {
            'knigi': books,
            'heading': 'Листа на сите книги од ' + str(godina) + ' година'
        })
예제 #15
0
def by_author(request, a_id):
    """
    Metod za listanje na site knigi od avtor
    """
    author = get_object_or_404(Author, pk=a_id)
    return render_to_response(
        request, 'biblioteka/list.html', {
            'knigi': author.book_set.all(),
            'heading': u'Листа на сите книги од \"' + author.name + '\"'
        })
예제 #16
0
def reserved_books(request):
    """
    Metod za listanje na site rezervirani knigi.
    Potrebna e permisija za dodavanje na rental.
    """
    reservations = Reservation.objects.all()
    if request.method == 'POST':
        try:
            reservations = reservations.filter(book__ISBN=request.POST['ISBN'])
        except:
            pass
    return render_to_response(request, 'biblioteka/res_list.html',
            {'reservations':reservations, 'heading':'Листа на сите резервирани книги'})
예제 #17
0
def reserved_books(request):
    """
    Metod za listanje na site rezervirani knigi.
    Potrebna e permisija za dodavanje na rental.
    """
    reservations = Reservation.objects.all()
    if request.method == 'POST':
        try:
            reservations = reservations.filter(book__ISBN=request.POST['ISBN'])
        except:
            pass
    return render_to_response(request, 'biblioteka/res_list.html', {
        'reservations': reservations,
        'heading': 'Листа на сите резервирани книги'
    })
예제 #18
0
def register(request):#, success_url=reverse('registrationsuccess')):
	"""
	Allows a new user to register an account.

	"""
	if request.method == 'POST':
		form = RegistrationForm(request.POST)
		if form.is_valid():
			new_user = RegistrationProfile.objects.create_inactive_user(username=form.cleaned_data['username'],
																		password=form.cleaned_data['password1'],
																		email=form.cleaned_data['email'],
																		name=form.cleaned_data['first_name'],
																		surname=form.cleaned_data['last_name'])
			return HttpResponseRedirect(reverse('registrationsuccess'))
	else:
		form = RegistrationForm()
	return render_to_response(request, 'registration/registration_form.html', {'form': form })
예제 #19
0
def history(request, rented_by=None, year=None, month=None):
    dates = Rental.objects.dates('rented_on', 'month')
    isbn = None
    if request.method == 'POST':
        try:
            isbn = request.POST['ISBN'].strip()
        except:
            pass

    if rented_by is None:
        if request.user.has_perm('can_add_rental'):
            rental_list = get_rental_list(year=year, month=month, ISBN=isbn)
        else:
            rental_list = get_rental_list(user=request.user, year=year, month=month, ISBN=isbn)
    else:
        rental_list = get_rental_list(user=rented_by, year=year, month=month, ISBN=isbn)
    path = "/".join(request.path.split('/')[1:3])
    return render_to_response(request, 'biblioteka/history.html', {'list':rental_list, 'dates':dates, 'path':path})
예제 #20
0
def edit_account(request):
	if request.method == 'POST':
		form = EditAccountForm(request.POST)
		if form.is_valid():
			u = User.objects.get(pk=request.user.id)
			u.first_name = form.cleaned_data['first_name']
			u.last_name = form.cleaned_data['last_name']
			u.email = form.cleaned_data['email']
			u.save()
	else:
		data = {
			'username':request.user.username,
			'first_name':request.user.first_name,
			'last_name':request.user.last_name,
			'email':request.user.email,
		}
		form = EditAccountForm(data)

	return render_to_response(request, 'account/edit_account.html', {'form':form})
예제 #21
0
    """
    Metod za gledanje na detali na odredena kniga
    """
    book = get_object_or_404(Book, pk=k_id)
    tags = book.tags.split(', ')
    try:
        while (True):
            tags.remove('')
    except Exception, e:
        pass
    tags = tags if len(tags) > 0 else None
    heading = '"' + book.title + u'" од ' + u', '.join(
        [a.name for a in book.authors.all()])
    return render_to_response(request, 'biblioteka/detali.html', {
        'kniga': book,
        'heading': heading,
        'tags': tags
    })


def by_year(request, godina):
    """
    Metod za listanje na site knigi od godina
    """
    books = Book.objects.filter(release_year=godina)
    return render_to_response(
        request, 'biblioteka/list.html', {
            'knigi': books,
            'heading': 'Листа на сите книги од ' + str(godina) + ' година'
        })
예제 #22
0

def view_book_details(request, k_id):
    """
    Metod za gledanje na detali na odredena kniga
    """
    book = get_object_or_404(Book, pk=k_id)
    tags = book.tags.split(', ')
    try:
        while(True):
            tags.remove('')
    except Exception,  e:
        pass
    tags = tags if len(tags) > 0 else None
    heading = '"'+ book.title + u'" од ' + u', '.join([a.name for a in book.authors.all()])
    return render_to_response(request, 'biblioteka/detali.html',
            {'kniga':book, 'heading':heading, 'tags':tags})


def by_year(request, godina):
    """
    Metod za listanje na site knigi od godina
    """
    books = Book.objects.filter(release_year=godina)
    return render_to_response(request, 'biblioteka/list.html',
            {'knigi':books, 'heading':'Листа на сите книги од ' + str(godina) +' година'})


def by_tag(request, tag):
    """
    Metod za listanje na site knigi spored odbran tag
    """