Exemplo n.º 1
0
def index(request):    
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_shelfsale = ShelfSaleForm()
        return render_to_response('bookstore/sell_books.html', 
                                  {'form_shelf_sale': form_shelfsale,
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request)
                                   },
                                  context_instance=RequestContext(request)) 
Exemplo n.º 2
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_shelfsale = ShelfSaleForm()
        return render_to_response(
            'bookstore/sell_books.html', {
                'form_shelf_sale': form_shelfsale,
                'is_manager': validate_manager_session(request),
                'is_seller': validate_seller_session(request)
            },
            context_instance=RequestContext(request))
Exemplo n.º 3
0
def change_status(request):   
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    
    if request.method == 'POST': 
        
        user = None   
        id = request.session['user_id']          
        if User.objects.filter(id=id).exists() == True:
                user = User.objects.get(id=id)
                       
        profile_phrase = request.POST['description'] 
               
        if len(profile_phrase) > 100:
            error_msg = ERROR_MAX_LENGTH_STATUS
            return render_to_response('user_profiles/profile.html', 
                                      {'user': user,
                                       'error_msg': error_msg,
                                       'profile_phrase': profile_phrase, 
                                       'is_manager': validate_manager_session(request),
                                       'is_seller': validate_seller_session(request)}, 
                                       context_instance=RequestContext(request))
        else:
            user.set_profile_phrase(profile_phrase)
            user.save()
    return HttpResponseRedirect('/perfil/')
Exemplo n.º 4
0
def register_distributor(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    if validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')

    registration_result = ""

    if request.method == 'POST':  # Formulário enviado
        form = RegisterDistributorForm(request.POST, request.FILES)

        if form.is_valid():
            checked_form = form.cleaned_data
            new_distributor = Distributor(name=checked_form['name'].strip())

            new_distributor.save()
            registration_result = SUCCESS_REGISTER_NEW_DISTRIBUTOR

            form = RegisterDistributorForm()

    else:  # Página acessada via link (método GET)
        form = RegisterDistributorForm()

    return render_to_response('bookstore/register_distributor.html', {
        'form': form,
        'registration_result': registration_result,
        'is_manager': validate_manager_session(request),
        'is_seller': validate_seller_session(request)
    },
                              context_instance=RequestContext(request))
Exemplo n.º 5
0
def show_user_informations(request, id):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        user = User.objects.get(id=id)
        phones = Phone.objects.filter(user=user.id)

        information = {}
        str_phones = []

        for phone in phones:
            str_phones.append("( " + phone.ddd + " ) " + phone.number)

        information['name'] = user.first_name + " " + user.last_name
        information['login'] = user.login
        information['email'] = user.email
        information['phones'] = str_phones
        if len(user.address.all()) == 0:
            information['address'] = ""
        else:
            address = user.address.all()[0]
            information['address'] = address.street + " " + address.number + " " + \
            address.complement + " - " + address.neighborhood + " - CEP: " + \
            address.zipcode

        return render_to_response(
            'library/show_user_informations.html', {
                'information': information,
                'is_manager': validate_manager_session(request),
                'is_seller': validate_seller_session(request)
            },
            context_instance=RequestContext(request))
Exemplo n.º 6
0
def register_distributor(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    if validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    
    registration_result = ""
        
    if request.method == 'POST': # Formulário enviado
        form = RegisterDistributorForm(request.POST, request.FILES)
        
        if form.is_valid():
            checked_form = form.cleaned_data            
            new_distributor = Distributor(name = checked_form['name'].strip())
            
            new_distributor.save()                        
            registration_result = SUCCESS_REGISTER_NEW_DISTRIBUTOR
            
            form = RegisterDistributorForm()    
            
    else: # Página acessada via link (método GET)
        form = RegisterDistributorForm()
        
    return render_to_response('bookstore/register_distributor.html', 
                              {'form': form,
                               'registration_result': registration_result,
                               'is_manager': validate_manager_session(request),
                               'is_seller': validate_seller_session(request)
                               }, 
                              context_instance=RequestContext(request))
Exemplo n.º 7
0
def search_user_orders(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        if request.method == 'GET' and 'login' in request.GET and 'email' in request.GET:
            user_login = request.GET['login'].strip()
            user_email = request.GET['email'].strip()
            user = None
            available_orders = []

            kwargs = {}
            if (user_login != ""):
                kwargs['login'] = user_login
            if (user_email != ""):
                kwargs['email'] = user_email

            if (kwargs != {}):
                if User.objects.filter(**kwargs).exists() == True:
                    user = User.objects.get(**kwargs)

            if user is not None:
                if BookOrder.objects.filter(user=user.id,
                                            situation="D").exists() == True:
                    available_orders = BookOrder.objects.filter(user=user.id,
                                                                situation="D")

            user_orders = transform_to_grid_order_list(available_orders)

            response = serializers.serialize("json", user_orders)
            return HttpResponse(response, mimetype="text/javascript")
        else:
            return HttpResponseRedirect('/vendas/')
Exemplo n.º 8
0
def show_user_informations(request, id):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        user = User.objects.get(id=id)
        phones = Phone.objects.filter(user = user.id)

        information = {}   
        str_phones = []
             
        for phone in phones:
            str_phones.append("( " + phone.ddd + " ) " + phone.number)
            
        information['name'] = user.first_name + " " + user.last_name
        information['login'] = user.login
        information['email'] = user.email
        information['phones'] = str_phones
        if len(user.address.all()) == 0:
            information['address'] = ""
        else:
            address = user.address.all()[0]
            information['address'] = address.street + " " + address.number + " " + \
            address.complement + " - " + address.neighborhood + " - CEP: " + \
            address.zipcode
        
        return render_to_response('library/show_user_informations.html', 
                                  {'information': information,
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request)
                                   }, 
                                  context_instance=RequestContext(request))   
Exemplo n.º 9
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')

    id = request.session['user_id']

    user = None
    if User.objects.filter(id=id).exists() == True:
        user = User.objects.get(id=id)

    result = ""

    if request.method == 'POST':  # Formulário enviado
        form = LibraryRegisterForm(request.POST, request.FILES)

        if form.is_valid():
            checked_form = form.cleaned_data
            street = checked_form['street']
            number = checked_form['number']
            complement = checked_form['complement']
            zipcode = checked_form['zipcode']
            neighborhood = checked_form['neighborhood']

            if len(user.address.all()) == 0:
                address = Address(user=user,
                                  street=street,
                                  number=number,
                                  complement=complement,
                                  zipcode=zipcode,
                                  neighborhood=neighborhood)
            else:
                address = user.address.all()[0]
                address.set_data(street, number, complement, zipcode,
                                 neighborhood)

            registered_phones = Phone.objects.filter(user=user.id)
            for phone in registered_phones:
                phone.delete()

            register_phone(user, checked_form['ddd1'], checked_form['phone1'])
            register_phone(user, checked_form['ddd2'], checked_form['phone2'])
            register_phone(user, checked_form['ddd3'], checked_form['phone3'])
            register_phone(user, checked_form['ddd4'], checked_form['phone4'])

            address.save()

            result = SUCCESS_LIBRARY_REGISTER

    else:  #método GET

        form = LibraryRegisterForm(instance=user)

    return render_to_response('library/library.html', {
        'form': form,
        'result': result,
        'is_manager': validate_manager_session(request),
        'is_seller': validate_seller_session(request)
    },
                              context_instance=RequestContext(request))
Exemplo n.º 10
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
               
    return render_to_response('user_profiles/favorite_books.html', 
                              {'is_manager': validate_manager_session(request),
                               'is_seller': validate_seller_session(request)},
                              context_instance=RequestContext(request))
Exemplo n.º 11
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')

    return render_to_response('user_profiles/favorite_books.html', {
        'is_manager': validate_manager_session(request),
        'is_seller': validate_seller_session(request)
    },
                              context_instance=RequestContext(request))
Exemplo n.º 12
0
def index(request):   
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    else:   
        return render_to_response('bookstore/bookstore.html', 
                                  {
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request)
                                   }, 
                                   context_instance=RequestContext(request))
Exemplo n.º 13
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    else:
        return render_to_response(
            'bookstore/bookstore.html', {
                'is_manager': validate_manager_session(request),
                'is_seller': validate_seller_session(request)
            },
            context_instance=RequestContext(request))
Exemplo n.º 14
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')  #tela de login

    form = EditAccountForm()

    return render_to_response('user_profiles/edit_account.html', {
        'form': form,
        'is_manager': validate_manager_session(request),
        'is_seller': validate_seller_session(request)
    },
                              context_instance=RequestContext(request))
Exemplo n.º 15
0
def sell_order_book(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        result = {}
        result['validation_message'] = []
        result['success_message'] = ""
        result['error_message'] = ""

        if request.method == 'GET' and 'order_id' in request.GET and 'order_price' in request.GET:

            if request.GET['order_id'] == "":
                result['validation_message'].append(
                    ERROR_NO_ORDER_ROW_SELECTED)

            if request.GET['order_price'] == "":
                result['validation_message'].append(ERROR_REQUIRED_ORDER_PRICE)
            else:
                valid_price = validate_price(request.GET['order_price'])
                if valid_price == None:
                    result['validation_message'].append(
                        ERROR_INVALID_ORDER_PRICE)

            if is_valid_order(request.GET['order_id']) == True:
                order = BookOrder.objects.get(id=int(request.GET['order_id']))
                if order.situation != "D" and len(
                        result['validation_message']) == 0:
                    result['error_message'] = ERROR_UNAVAILABLE_ORDER
            else:
                order = None
                if len(result['validation_message']) == 0:
                    result['error_message'] = ERROR_INVALID_ORDER

            if len(result['validation_message']
                   ) == 0 and result['error_message'] == "":
                book = BookstoreBook.objects.get(id=order.book.id)
                book.sell_order()
                order.sell_order()
                sale = OrderSale(date_of_sale=date.today(),
                                 price_of_sale=valid_price,
                                 book_order=order)
                sale.save()
                order.save()
                result['success_message'] = SUCCESS_SELLING_ORDER

            response = json.dumps(result)
            return HttpResponse(response, mimetype="text/javascript")

        else:
            return HttpResponseRedirect('/vendas/')
Exemplo n.º 16
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') #tela de login
        
    form = EditAccountForm()  
        
    return render_to_response('user_profiles/edit_account.html', 
                              {
                               'form': form,
                               'is_manager': validate_manager_session(request),
                               'is_seller': validate_seller_session(request)
                               }, 
                               context_instance=RequestContext(request)) 
def index(request):    
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_bookstore_book = RegisterBookstoreBookForm()
        return render_to_response('bookstore/register_bookstore_book.html', 
                                  {'form_bookstore_book': form_bookstore_book,
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request)
                                   },
                                  context_instance=RequestContext(request)) 
Exemplo n.º 18
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_invoice = RegisterInvoiceForm()
        return render_to_response(
            'financial/register_invoice.html', {
                'form_invoice': form_invoice,
                'is_manager': validate_manager_session(request),
                'is_seller': validate_seller_session(request)
            },
            context_instance=RequestContext(request))
Exemplo n.º 19
0
def sell_shelf_book(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        result = {}
        result['validation_message'] = []
        result['success_message'] = ""
        result['error_message'] = ""

        if request.method == 'GET' and 'book_id' in request.GET and 'book_price' in request.GET:

            if request.GET['book_id'] == "":
                result['validation_message'].append(ERROR_REQUIRED_BOOK_ID)

            if request.GET['book_price'] == "":
                result['validation_message'].append(ERROR_REQUIRED_BOOK_PRICE)
            else:
                valid_price = validate_price(request.GET['book_price'])
                if valid_price == None:
                    result['validation_message'].append(
                        ERROR_INVALID_BOOK_PRICE)

            if is_valid_book(request.GET['book_id']) == True:
                book = BookstoreBook.objects.get(
                    id=int(request.GET['book_id']))
                if book.available_quantity == 0 and len(
                        result['validation_message']) == 0:
                    result['error_message'] = ERROR_UNAVAILABLE_BOOK
            else:
                book = None
                if len(result['validation_message']) == 0:
                    result['error_message'] = ERROR_INVALID_BOOK

            if len(result['validation_message']
                   ) == 0 and result['error_message'] == "":
                book.sell_book()
                sale = ShelfSale(date_of_sale=date.today(),
                                 price_of_sale=valid_price,
                                 book=book)
                sale.save()
                book.save()
                result['success_message'] = SUCCESS_SELLING_BOOK

            response = json.dumps(result)
            return HttpResponse(response, mimetype="text/javascript")

        else:
            return HttpResponseRedirect('/vendas/')
Exemplo n.º 20
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    if validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')

    form = GenerateSaleReportForm()

    return render_to_response('financial/generate_sale_report.html', {
        'form': form,
        'is_manager': validate_manager_session(request),
        'is_seller': validate_seller_session(request)
    },
                              context_instance=RequestContext(request))
Exemplo n.º 21
0
def index(request):    
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_payment = RegisterPaymentForm()
        return render_to_response('financial/register_payment.html', 
                                  {
                                   'form_payment': form_payment,
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request) 
                                   },
                                  context_instance=RequestContext(request)) 
Exemplo n.º 22
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_bookstore_book = RegisterBookstoreBookForm()
        return render_to_response(
            'bookstore/register_bookstore_book.html', {
                'form_bookstore_book': form_bookstore_book,
                'is_manager': validate_manager_session(request),
                'is_seller': validate_seller_session(request)
            },
            context_instance=RequestContext(request))
Exemplo n.º 23
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form = GenerateMonthBalanceForm()
            
        return render_to_response('financial/generate_month_balance.html', 
                                  {
                                   'form': form,
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request) 
                                   },
                                  context_instance=RequestContext(request))
Exemplo n.º 24
0
def sell_order_book(request):   
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else: 
        result = {}
        result['validation_message'] = []
        result['success_message'] = ""
        result['error_message'] = ""
            
        if request.method == 'GET' and 'order_id' in request.GET and 'order_price' in request.GET:   

            if request.GET['order_id'] == "":
                result['validation_message'].append(ERROR_NO_ORDER_ROW_SELECTED)
            
            if request.GET['order_price'] == "":
                result['validation_message'].append(ERROR_REQUIRED_ORDER_PRICE)
            else:
                valid_price = validate_price(request.GET['order_price']) 
                if valid_price == None:
                    result['validation_message'].append(ERROR_INVALID_ORDER_PRICE)

            if is_valid_order(request.GET['order_id']) == True:   
                order = BookOrder.objects.get(id=int(request.GET['order_id'])) 
                if order.situation != "D" and len(result['validation_message']) == 0:
                    result['error_message'] = ERROR_UNAVAILABLE_ORDER
            else:
                order = None
                if len(result['validation_message']) == 0:
                    result['error_message'] = ERROR_INVALID_ORDER

            if len(result['validation_message']) == 0 and result['error_message'] == "":   
                book = BookstoreBook.objects.get(id=order.book.id)
                book.sell_order()
                order.sell_order()
                sale = OrderSale(date_of_sale = date.today(),
                                 price_of_sale = valid_price,
                                 book_order = order) 
                sale.save()
                order.save() 
                result['success_message'] = SUCCESS_SELLING_ORDER 
                          
            response = json.dumps(result)
            return HttpResponse(response, mimetype="text/javascript")    
        
        else:
            return HttpResponseRedirect('/vendas/')
Exemplo n.º 25
0
def sell_shelf_book(request):   
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else: 
        result = {}
        result['validation_message'] = []
        result['success_message'] = ""
        result['error_message'] = ""
            
        if request.method == 'GET' and 'book_id' in request.GET and 'book_price' in request.GET:   

            if request.GET['book_id'] == "":
                result['validation_message'].append(ERROR_REQUIRED_BOOK_ID)
            
            if request.GET['book_price'] == "":
                result['validation_message'].append(ERROR_REQUIRED_BOOK_PRICE)
            else:
                valid_price = validate_price(request.GET['book_price']) 
                if valid_price == None:
                    result['validation_message'].append(ERROR_INVALID_BOOK_PRICE)

            if is_valid_book(request.GET['book_id']) == True:   
                book = BookstoreBook.objects.get(id=int(request.GET['book_id'])) 
                if book.available_quantity == 0 and len(result['validation_message']) == 0:
                    result['error_message'] = ERROR_UNAVAILABLE_BOOK
            else:
                book = None
                if len(result['validation_message']) == 0:
                    result['error_message'] = ERROR_INVALID_BOOK

            if len(result['validation_message']) == 0 and result['error_message'] == "":   
                book.sell_book()
                sale = ShelfSale(date_of_sale = date.today(),
                                 price_of_sale = valid_price,
                                 book = book) 
                sale.save()
                book.save() 
                result['success_message'] = SUCCESS_SELLING_BOOK
                          
            response = json.dumps(result)
            return HttpResponse(response, mimetype="text/javascript")    
        
        else:
            return HttpResponseRedirect('/vendas/')
Exemplo n.º 26
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_author = RegisterAuthorForm()
        form_publisher = RegisterPublisherForm()
        form_book = RegisterBookForm()
        return render_to_response(
            'books/books_collection.html', {
                'form_book': form_book,
                'form_author': form_author,
                'form_publisher': form_publisher,
                'is_manager': validate_manager_session(request),
                'is_seller': validate_seller_session(request)
            },
            context_instance=RequestContext(request))
Exemplo n.º 27
0
def index(request):   
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_borrow = BorrowBookForm()
        form_receive = ReceiveBookForm()
        form_library_book = RegisterLibraryBookForm()

        return render_to_response('library/manage_library.html', 
                                  {'form_library_book': form_library_book,
                                   'form_borrow': form_borrow,
                                   'form_receive': form_receive,
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request)
                                   }, 
                                  context_instance=RequestContext(request)) 
Exemplo n.º 28
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_author = RegisterAuthorForm() 
        form_publisher = RegisterPublisherForm() 
        form_book = RegisterBookForm() 
        return render_to_response('books/books_collection.html', 
                                  {
                                   'form_book':form_book,
                                   'form_author': form_author,
                                   'form_publisher':form_publisher,
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request)
                                   }, 
                                  context_instance=RequestContext(request)) 
Exemplo n.º 29
0
def index(request):    
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_purchase_item = NewPurchaseItemForm()
        form_new_purchase_order = NewPurchaseOrderForm()
        form_purchase_order = PurchaseOrderForm()
        
        return render_to_response('bookstore/purchase_order.html', 
                                  {'form_purchase_item': form_purchase_item,
                                   'form_new_purchase_order': form_new_purchase_order,
                                   'form_purchase_order': form_purchase_order,
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request)
                                   },
                                  context_instance=RequestContext(request))
Exemplo n.º 30
0
def show_book_informations(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    elif request.method == 'GET' and 'book_id' in request.GET:   
        str_id = request.GET['book_id'] 
        
        book_list = []
        if(str_id != ""):                     
            book_id = int(str_id)            
            bookstore_book = BookstoreBook.objects.get(id=book_id)
            book = BookstoreBookGridFormat(bookstore_book)            
            book_list.append(book)
               
        response = serializers.serialize("json", book_list)     
        return HttpResponse(response, mimetype="text/javascript")
    else:
        return HttpResponseRedirect('/gerenciarbiblioteca/')    
Exemplo n.º 31
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/') #tela de login
    
    id = request.session['user_id']
    
    user = None
    
    if User.objects.filter(id=id).exists() == True:
        user = User.objects.get(id=id)     
            
    favorite_books = user.favorite_books.all()
               
    return render_to_response('user_profiles/profile.html', 
                              {'user': user,
                               'favorite_books': favorite_books,
                               'is_manager': validate_manager_session(request),
                               'is_seller': validate_seller_session(request)}, 
                               context_instance=RequestContext(request))
Exemplo n.º 32
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_borrow = BorrowBookForm()
        form_receive = ReceiveBookForm()
        form_library_book = RegisterLibraryBookForm()

        return render_to_response(
            'library/manage_library.html', {
                'form_library_book': form_library_book,
                'form_borrow': form_borrow,
                'form_receive': form_receive,
                'is_manager': validate_manager_session(request),
                'is_seller': validate_seller_session(request)
            },
            context_instance=RequestContext(request))
Exemplo n.º 33
0
def index(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_manager_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:
        form_purchase_item = NewPurchaseItemForm()
        form_new_purchase_order = NewPurchaseOrderForm()
        form_purchase_order = PurchaseOrderForm()

        return render_to_response(
            'bookstore/purchase_order.html', {
                'form_purchase_item': form_purchase_item,
                'form_new_purchase_order': form_new_purchase_order,
                'form_purchase_order': form_purchase_order,
                'is_manager': validate_manager_session(request),
                'is_seller': validate_seller_session(request)
            },
            context_instance=RequestContext(request))
Exemplo n.º 34
0
def show_book_informations(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    elif request.method == 'GET' and 'book_id' in request.GET:
        str_id = request.GET['book_id']

        book_list = []
        if (str_id != ""):
            book_id = int(str_id)
            bookstore_book = BookstoreBook.objects.get(id=book_id)
            book = BookstoreBookGridFormat(bookstore_book)
            book_list.append(book)

        response = serializers.serialize("json", book_list)
        return HttpResponse(response, mimetype="text/javascript")
    else:
        return HttpResponseRedirect('/gerenciarbiblioteca/')
Exemplo n.º 35
0
def edit(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/')  #tela de login

    if request.method == 'POST':  # Formulário enviado
        form = EditAccountForm(request.POST, request.FILES)
        result = ""

        if form.is_valid():
            checked_form = form.cleaned_data

            id = request.session['user_id']

            if User.objects.filter(id=id).exists() == True:
                user = User.objects.get(id=id)

            if checked_form['login'].strip() != "":
                user.login = checked_form['login'].strip().lower()
            if checked_form['password'] != "":
                user.set_encrypted_password(checked_form['password'])

            if checked_form['login'].strip(
            ) == "" and checked_form['password'] == "":
                result = WARNING_EDIT_ACCOUNT
            else:
                user.save()
                result = SUCCESS_EDIT_ACCOUNT

            form = EditAccountForm()

        return render_to_response(
            'user_profiles/edit_account.html', {
                'form': form,
                'result': result,
                'is_manager': validate_manager_session(request),
                'is_seller': validate_seller_session(request)
            },
            context_instance=RequestContext(request))

    return HttpResponseRedirect('/perfil/')  #se o método nao for POST
Exemplo n.º 36
0
def edit(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') #tela de login

    id = request.session['user_id']

    user = None    
    if User.objects.filter(id=id).exists() == True:
        user = User.objects.get(id=id)
    
    result = ""
           
    if request.method == 'POST': # Formulário enviado    
        form = EditProfileForm(request.POST, request.FILES)
        
        if form.is_valid():
            checked_form = form.cleaned_data
            
            data = {}
            data['first_name'] = checked_form['first_name']
            data['last_name'] = checked_form['last_name']
            data['photo'] = checked_form['photo']
            data['institution'] = checked_form['institution']
            data['gender'] = checked_form['gender']
            data['birthday'] = checked_form['birthday']

            user.set_profile_data(data)          
            user.save()
            result = SUCCESS_EDIT_PROFILE
            
    else: #método GET          
        form = EditProfileForm(instance=user)      
    
    return render_to_response('user_profiles/edit_profile.html', 
                              {'form': form,
                               'result': result, 
                               'is_manager': validate_manager_session(request),
                               'is_seller': validate_seller_session(request)}, 
                              context_instance=RequestContext(request))
Exemplo n.º 37
0
def edit(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') #tela de login
    
    if request.method == 'POST': # Formulário enviado
        form = EditAccountForm(request.POST, request.FILES)
        result = "" 
        
        if form.is_valid():
            checked_form = form.cleaned_data
            
            id = request.session['user_id']
        
            if User.objects.filter(id=id).exists() == True:
                user = User.objects.get(id=id)     
            
            if checked_form['login'].strip() != "":
                user.login = checked_form['login'].strip().lower()
            if checked_form['password'] != "":  
                user.set_encrypted_password(checked_form['password']) 
                      
            if checked_form['login'].strip() == "" and checked_form['password'] == "":
                result = WARNING_EDIT_ACCOUNT 
            else:
                user.save()            
                result = SUCCESS_EDIT_ACCOUNT    
        
            form = EditAccountForm()  

        return render_to_response('user_profiles/edit_account.html', 
                                  {'form': form,
                                   'result': result, 
                                   'is_manager': validate_manager_session(request),
                                   'is_seller': validate_seller_session(request)}, 
                                   context_instance=RequestContext(request))
            
    return HttpResponseRedirect('/perfil/') #se o método nao for POST        
Exemplo n.º 38
0
def search_user_orders(request):
    if validate_session(request) == False:
        return HttpResponseRedirect('/logout/') 
    elif validate_seller_session(request) == False:
        return HttpResponseRedirect('/perfil/')
    else:           
        if request.method == 'GET' and 'login' in request.GET and 'email' in request.GET:              
            user_login = request.GET['login'].strip()    
            user_email = request.GET['email'].strip()
            user = None
            available_orders = []
            
            kwargs = {}
            if(user_login != ""):
                kwargs['login'] = user_login
            if(user_email != ""):
                kwargs['email'] = user_email   
                
            if(kwargs != {}):
                if User.objects.filter(**kwargs).exists() == True:
                    user = User.objects.get(**kwargs)     
                               
            if user is not None:
                if BookOrder.objects.filter(
                                       user = user.id,
                                       situation = "D"
                                       ).exists() == True:
                    available_orders = BookOrder.objects.filter(user = user.id, situation = "D")   
                                                      
            user_orders = transform_to_grid_order_list(available_orders)    

            
            response = serializers.serialize("json",  user_orders)     
            return HttpResponse(response, mimetype="text/javascript")
        else:
            return HttpResponseRedirect('/vendas/')