Example #1
0
def sign_up(request):
    """Sing_up function is the function for allow a user on sign up"""
    context = {}
    if request.method == 'POST':
        form = UserCreationForm(request.POST, error_class=ParagraphErrorList)
        # Check input if she valid or not
        if form.is_valid():
            if request.POST.get('gcu'):
                user = form.save()
                login(request,
                      user,
                      backend='django.contrib.auth.backends.ModelBackend')
                request.session['member_id'] = user.id
                return redirect('dashboard')
            else:
                context['error'] = 'Veuillez accepter les ' \
                                   'conditions générales d\'utilisation'
                context['form'] = form
                context['form_announce'] = AnnounceForm()
                return render(request,
                              'user/sign_up.html',
                              context,
                              status=401)
        else:
            context['form'] = form
            context['form_announce'] = AnnounceForm()
            return render(request, 'user/sign_up.html', context, status=401)
    else:
        # GET method. Create a new form to be used in the template.
        form = UserCreationForm()
    context['form_announce'] = AnnounceForm()
    context['form'] = form
    return render(request, 'user/sign_up.html', context)
Example #2
0
def rent_validation_done(request):
    """Rent_validation is there to confirm the rental by email
    and save the booking"""
    context = {}
    user = User.objects.get(id=request.session['member_id'])

    if len(list_info_rent) == 0:
        context['error_rent_validation'] = \
            "Veuillez nous excuser une erreur c'est produite. \n " \
            "Nous vous conseillons de réessayer ultérieurement."
        context['form_announce'] = AnnounceForm()
        return render(request, 'search/rent_now.html', context)
    else:
        email_validation_customer(request, user)
        email_validation_trader(request, list_info_rent[3], list_info_rent[4])

        new_rental = MyRental(user=user,
                              rental_city=list_info_rent[0],
                              rental_country=list_info_rent[1],
                              email_user_rental=user.email,
                              code=list_info_rent[2])
        new_rental.save()

        new_booking = Booking(user=user,
                              code=list_info_rent[2],
                              date_min=list_info_rent[5],
                              date_max=list_info_rent[6])
        update_announce = Announces.objects.get(code=list_info_rent[2])
        update_announce.booking = "Votre bien est actuellement loué."

        update_announce.save()
        new_booking.save()
        context['form_announce'] = AnnounceForm()
Example #3
0
def handler_ad(request):
    """Handler_ad is the method for manage of
    the rentals"""
    context = {}
    if request.user.is_authenticated:
        announces_user = \
            Announces.objects.filter(user_id=request.session['member_id'])
        rental_all = MyRental.objects.all()
        for info in announces_user:
            for rent in rental_all:
                if info.code == rent.code:
                    user = User.objects.filter(pk=rent.user_id)
                    context['user_booking'] = user
        context['informations_announces'] = announces_user

        paginator = Paginator(announces_user, 6)
        page = request.GET.get('page', 1)
        nb_page = paginator.get_page(page)
        context['nb_page'] = nb_page
        context['informations_announces'] = paginator.page(page)
        context['form_announce'] = AnnounceForm()
        return render(request, 'user/handler_ad.html', context)
    else:
        context['error_handler'] = "Vous devez être connecté " \
                                   "pour accéder à cette page."
    context['form_ad'] = New_AdForm()
    context['form_announce'] = AnnounceForm()
    return render(request, 'user/handler_ad.html', context)
Example #4
0
def new_ad(request):
    """New ad is the method for save the
    new advertissements of the users"""
    context = {}
    nb_1 = randrange(0, 101, 2)
    nb_2 = randrange(0, 101, 2)

    if request.method == 'POST':
        r_title = request.POST.get('title')
        r_address = request.POST.get('address')
        r_description = request.POST.get('description')
        r_city = request.POST.get('city')
        r_country = request.POST.get('country')
        r_price_day = request.POST.get('price_day')
        r_price_weeks = request.POST.get('price_weeks')
        r_email = request.POST.get('email')
        r_pics_1 = request.FILES['pics_1']
        r_pics_2 = request.FILES['pics_2']
        r_pics_3 = request.FILES['pics_3']
        math_1 = nb_1 * nb_2
        math_2 = math_1 * nb_1
        code = math_2
        if code > 0:
            pass
        else:
            nb_3 = randrange(0, 101, 2)
            code = math_2 + nb_3 - 1
        if r_price_day.isdigit() and r_price_weeks.isdigit():
            new_ad = Announces(title=r_title,
                               address=r_address,
                               description=r_description,
                               city=r_city,
                               country=r_country,
                               price_day=r_price_day,
                               price_weeks=r_price_weeks,
                               email=r_email,
                               pics_1=r_pics_1,
                               pics_2=r_pics_2,
                               pics_3=r_pics_3,
                               code=code,
                               user_id=request.session['member_id'])
            new_ad.save()

            context['form_ad'] = New_AdForm()
            context['form_announce'] = AnnounceForm()
            return HttpResponseRedirect('dashboard.html')
        else:
            context['error_price'] = 'Veuillez indiquer un montant valide'
            context['form_ad'] = New_AdForm()
            context['form_announce'] = AnnounceForm()
            return render(request, 'search/new_ad.html', context)

    context['form_ad'] = New_AdForm()
    context['form_announce'] = AnnounceForm()
    return render(request, 'search/new_ad.html', context)
Example #5
0
def disconnect(request):
    """Disconnect is the method for disconnect a user"""
    context = {}
    # Check if user is connect
    if not request.user.is_authenticated:
        context['form_announce'] = AnnounceForm()
        return render(request, 'search/index.html', context)
    else:
        # If user is connect, user is disconnect and redirect to home page
        auth_logout(request)
        context['form_announce'] = AnnounceForm()
        return redirect('index')
Example #6
0
def add_email_paypal(request):
    """This method is to add an email paypal for a user """
    context = {}
    if request.method == "POST":
        email_paypal = request.POST.get('email')
        user = User.objects.get(pk=request.session['member_id'])
        user.email_paypal = email_paypal
        user.save()
        context['form_announce'] = AnnounceForm()
        return HttpResponseRedirect('dashboard.html')
    context['form_ad'] = New_AdForm()
    context['form_announce'] = AnnounceForm()
    return render(request, 'user/add_email_paypal.html', context)
Example #7
0
def change_price(request):
    """Change price is the method for get
    the cancel infos of the property"""
    context = {}
    code = request.GET.get('announce')
    code_change = request.GET.get('change')
    if request.user.is_authenticated:
        if 'change' in request.GET:
            announce = Announces.objects.filter(code=code_change)
            price_day = request.POST.get('price_day')
            price_weeks = request.POST.get('price_weeks')
            if price_day.isdigit() and price_weeks.isdigit():
                return change_price_validation(request, announce, price_day,
                                               price_weeks)
            else:
                context['error_cancel'] = 'Veuillez entrer des chiffres ' \
                                          'et/ou des nombres.'
        elif 'announce' in request.GET:
            pass
        else:
            context['error_cancel'] = 'Un problème est survenu ' \
                                      'veuillez réessayer ultérieurement.'

    else:
        context['error_cancel'] = 'Vous devez être connecté ' \
                                  'pour accéder à cette page'
    context['code'] = code
    context['form_ad'] = New_AdForm()
    context['form_announce'] = AnnounceForm()
    return render(request, 'user/change_price.html', context)
Example #8
0
def connect(request):
    """The connect function is the function
    allow a user of the connect on the platform"""
    context = {}

    # Check if some reservation is to be deleted today
    auto_delete_booking(request)

    # Check if user is connect or not
    if not request.user.is_authenticated:
        if request.method == 'POST':
            form = ConnectForm(request.POST, error_class=ParagraphErrorList)
            # Check if input is good
            if form.is_valid():
                email = form.cleaned_data.get('email')
                password = form.cleaned_data.get('wordpass')
                return check_connect(request, email, password)

            else:
                context['errors'] = form.errors.items()
                return render(request,
                              'user/connect.html',
                              context,
                              status=401)
        else:
            form = ConnectForm()
        context['form'] = form
        context['form_announce'] = AnnounceForm()
        return render(request, 'user/connect.html', context)

    # If the user clicks on the login page and the user is logged in
    if request.user.is_authenticated:
        return HttpResponseRedirect('dashboard.html')
Example #9
0
def payment_done(request):
    """This is confirmation that the payment with Paypal
    is done"""
    context = {}
    rent_validation_done(request)
    context['form_announce'] = AnnounceForm()
    return render(request, 'payment/payment_done.html', context)
Example #10
0
def change_pics(request):
    """Change pics is the method for get
    the cancel infos of the property"""
    context = {}
    code = request.GET.get('announce')
    code_change = request.GET.get('change')
    if request.user.is_authenticated:
        if 'change' in request.GET:
            announce = Announces.objects.filter(code=code_change)
            pics_1 = request.FILES['pics_1']
            pics_2 = request.FILES['pics_2']
            pics_3 = request.FILES['pics_3']
            return change_pics_validation(request, announce, pics_1, pics_2,
                                          pics_3)
        elif 'announce' in request.GET:
            pass
        else:
            context['error_cancel'] = 'Un problème est survenu ' \
                                      'veuillez réessayer ultérieurement.'

    else:
        context['error_cancel'] = 'Vous devez être connecté ' \
                                  'pour accéder à cette page'
    context['code'] = code
    context['form_announce'] = AnnounceForm()
    return render(request, 'user/change_pics.html', context)
Example #11
0
def rent_now(request):
    """Rent_now is there to allow rental of the ad"""
    context = {}
    # Check if announce is present in the url
    announce_id = request.GET.get('announce')
    # Filter the id of the rental for be sure that is a good rental
    announce = Announces.objects.filter(code=announce_id)
    for info in announce:
        context['info_pk'] = info.pk
        context['info_code'] = info.code
        if not request.user.is_authenticated:
            context['error_rent_now'] = "Vous devez être connecté" \
                                        " pour accéder à cette page."
            context['form_announce'] = AnnounceForm()
            return render(request, 'search/rent_now.html', context)
        else:
            context['informations_announces'] = announce
            context['form_ad'] = Rent_Now()
            context['form_announce'] = AnnounceForm()
            return render(request, 'search/rent_now.html', context)
Example #12
0
def display_my_rented(request, rented_all):
    """Display_my_rented property is the method
    to display the user's rented property"""
    context = {}
    paginator = Paginator(rented_all, 6)
    page = request.GET.get('page', 1)
    nb_page = paginator.get_page(page)
    context['nb_page'] = nb_page
    context['announce_rented'] = rented_all
    context['announce_rented'] = paginator.page(page)
    context['form_announce'] = AnnounceForm()
    return render(request, 'user/my_rent.html', context)
Example #13
0
def delete_my_offer(request, announce):
    """Canceling my offer means canceling
    and remove from the database the fact that a
    the user can rent the property"""
    context = {}
    for info in announce:
        contact_owner(request, info)
        remove_announce = Announces.objects.get(code=info.code)
        remove_announce.delete()

    context['form_announce'] = AnnounceForm()
    return render(request, 'user/delete_validation.html', context)
Example #14
0
def change_price_validation(request, announce, price_day, price_weeks):
    """Change price validation confirm the new price"""
    context = {}
    for info in announce:
        contact_owner(request, info)
        announce_price = Announces.objects.get(code=info.code)
        announce_price.price_day = price_day
        announce_price.price_weeks = price_day
        announce_price.save()

    context['form_announce'] = AnnounceForm()
    return render(request, 'user/change_price_validation.html', context)
Example #15
0
def change_pics_validation(request, announce, pics_1, pics_2, pics_3):
    """Change pics validation confirm the validation to pics"""
    context = {}
    for info in announce:
        contact_owner(request, info)
        print(pics_1, pics_2, pics_3)
        announce_pics = Announces.objects.get(code=info.code)
        announce_pics.pics_1 = pics_1
        announce_pics.pics_2 = pics_2
        announce_pics.pics_3 = pics_3
        announce_pics.save()

    context['form_announce'] = AnnounceForm()
    return render(request, 'user/change_pics_validation.html', context)
Example #16
0
def rented(request):
    """This method is used to send a message
    if the user has not rented property, or
    to continue displaying the process of
    the rented property"""
    context = {}
    rented_all = MyRental.objects.filter(user__id=request.user.id)
    # Check if user have already added of the rented
    if len(rented_all) != 0:
        return display_my_rented(request, rented_all)
    else:
        context['form_announce'] = AnnounceForm()
        context['not_rented'] = "Vous n'avez pas " \
                                "encore loué de bien."
        return render(request, 'user/my_rent.html', context)
Example #17
0
def rent_validation_2(request, announce, date_min, date_max):
    """This method allow of cut rent_validation a two parts
    She manage the process finish """
    context = {}
    date_min_good = date_min.replace("-", "/")
    date_max_good = date_max.replace("-", "/")
    d1 = (datetime.strptime(date_min_good, "%d/%m/%Y"))
    d2 = (datetime.strptime(date_max_good, "%d/%m/%Y"))
    time_booking = str(f"{d1.day - d2.day}")
    correct_time = time_booking.replace("-", "")
    for info in announce:
        context['form_announce'] = AnnounceForm()
        amount = info.price_day * int(correct_time)
        user = User.objects.get(pk=info.user_id)
        get_info_booking(request, announce, date_min, date_max)
        return payment_process(request, info, user.email_paypal, amount)
Example #18
0
def cancel_myrented(request, announce):
    """Cancel my rental is to effect the cancellation
    and to delete from the database the fact that a
    user is renting the property"""
    context = {}
    for info in announce:
        contact_owner(request, info)
        remove_myrent = MyRental.objects.get(code=info.code)
        remove_myrent.delete()
        remove_booking = Booking.objects.get(code=info.code)
        remove_booking.delete()
        update_announce = Announces.objects.get(code=info.code)
        update_announce.booking = ""
        update_announce.save()

    context['form_announce'] = AnnounceForm()
    return render(request, 'user/cancel_validation.html', context)
Example #19
0
def user_booking_info(request):
    """Here we get the user information to give it to the owner"""
    context = {}
    info_user = request.GET.get('user')
    search_user = MyRental.objects.filter(code=info_user)
    users_all = User.objects.all()
    if search_user:
        for info in search_user:
            for info_all in users_all:
                if info.user_id == info_all.pk:
                    context['first_name'] = info_all.first_name
                    context['last_name'] = info_all.last_name
                    context['email'] = info_all.email
                    context['phone'] = info_all.phone
    else:
        pass
    context['form_announce'] = AnnounceForm()
    return render(request, 'user/user_booking_info.html', context)
Example #20
0
def dashboard(request):
    """Dashboard is the handler of the user dashboard"""
    context = {}
    # Check if user is connect or not
    if not request.user.is_authenticated:
        return render(request, 'user/connect.html', context)
    else:
        # Find the user in all users
        user = request.user
        context['email'] = user.email
        context['email_paypal'] = user.email_paypal
        context['firstname'] = user.first_name
        context['lastname'] = user.last_name
        # Get all information the user
        context['phone'] = user.phone
        context['date_of_birth'] = user.date_of_birth
        context['postal_address'] = user.postal_address
        context['form_announce'] = AnnounceForm()
        return render(request, 'user/dashboard.html', context)
Example #21
0
def check_connect(request, email, password):
    """Here, the system check if information
     the user is good or not
    If they are good, the system create
     a session for the user"""
    context = {}
    user_connected = authenticate(request, email=email, password=password)
    # Check if input is good or not
    if user_connected is not None:
        # create a session for user
        login(request, user=user_connected)
        request.session['member_id'] = user_connected.id
        time.sleep(4)
        return HttpResponseRedirect('dashboard.html')
    else:
        context['form'] = ConnectForm()
        context['form_announce'] = AnnounceForm()
        context['error_login'] = "******"
        return render(request, 'user/connect.html', context, status=401)
Example #22
0
def payment_process(request, info, email_paypal, amount):
    """This is procees to payment with Paypal"""
    paypal_dict = {
        "business": email_paypal,
        "amount": amount,
        "item_name": info.title,
        "invoice": info.email,
        "currency_code": "EUR",
        "notify_url": request.build_absolute_uri(reverse('paypal-ipn')),
        "return": request.build_absolute_uri(reverse('payment_done')),
        "cancel_return":
        request.build_absolute_uri(reverse('payment_canceled')),
        "custom": "premium_plan",
    }

    # Create the instance.
    form = PayPalPaymentsForm(initial=paypal_dict)
    context = {}
    context['form'] = form
    context['form_announce'] = AnnounceForm()
    return render(request, "payment/payment.html", context)
Example #23
0
def delete_rent_available(request):
    """Cancel and delete location is there to get
    cancellation information on the property"""
    context = {}
    code = request.GET.get('announce')
    code_cancel = request.GET.get('cancel')
    if request.user.is_authenticated:
        if 'cancel' in request.GET:
            announce = Announces.objects.filter(code=code_cancel)
            return delete_my_offer(request, announce)
        elif 'announce' in request.GET:
            pass
        else:
            context['error_cancel'] = 'Un problème est survenu ' \
                                      'veuillez réessayer ultérieurement.'
    else:
        context['error_cancel'] = 'Vous devez être connecté ' \
                                  'pour accéder à cette page'
    context['code'] = code
    context['form_announce'] = AnnounceForm()
    return render(request, 'user/delete_rent.html', context)
Example #24
0
def check_the_available_dates(request):
    """This method check if dates is available or not"""
    context = {}
    announce_id = request.GET.get('announce')
    booking = Booking.objects.filter(code=announce_id)
    all_dates_min = []
    all_dates_max = []

    # Create a loop to add the dates in two different lists
    a = 0
    while a != len(booking):
        for info in booking:
            if info.date_min not in all_dates_min:
                all_dates_min.append(info.date_min)
            if info.date_max not in all_dates_max:
                all_dates_max.append(info.date_max)
        a += 1

        context['form_announce'] = AnnounceForm()
        context['dates_min'] = all_dates_min
        context['dates_max'] = all_dates_max
        return render(request, 'user/check_dates.html', context)
Example #25
0
def cancel_rented(request):
    """Cancel rented is the method for get
    the cancel infos of the proprety"""
    context = {}
    code = request.GET.get('announce')
    code_cancel = request.GET.get('cancel')
    if request.user.is_authenticated:
        if 'cancel' in request.GET:
            announce = Announces.objects.filter(code=code_cancel)
            return cancel_myrented(request, announce)
        elif 'announce' in request.GET:
            pass
        else:
            context['error_cancel'] = 'Un problème est survenu ' \
                                      'veuillez réessayer ultérieurement.'

    else:
        context['error_cancel'] = 'Vous devez être connecté ' \
                                  'pour accéder à cette page'
    context['code'] = code
    context['form_announce'] = AnnounceForm()
    return render(request, 'user/cancel_rented.html', context)
Example #26
0
def payment_canceled(request):
    """This is confirmation that the payment with Paypal
    is canceled"""
    context = {}
    context['form_announce'] = AnnounceForm()
    return render(request, 'payment/payment_canceled.html', context)
Example #27
0
def gcu(request):
    context = {}
    context['form_announce'] = AnnounceForm()
    return render(request, 'user/gcu.html', context)