Example #1
0
def otomobils_search(request, id=0):
    sform1 = SearchForm1()
    sform2 = SearchForm2()
    setting = Setting.objects.get(pk=1)
    category = Category.objects.all()
    if request.method == 'POST' and id == 0:  # check post
        form = SearchForm1(request.POST)
        if form.is_valid():
            otomobils = Otomobil.objects.filter(
                category=form.cleaned_data['category'],
                location=form.cleaned_data['location'],
                gear=form.cleaned_data['gear'],
                fuel=form.cleaned_data['fuel'],
                status=True)

    if request.method == 'POST' and id == 1:
        arabalar = []
        form = SearchForm2(request.POST)
        if form.is_valid():
            otomobils = Otomobil.objects.filter(
                category=form.cleaned_data['category'],
                location=form.cleaned_data['location'],
                gear=form.cleaned_data['gear'],
                fuel=form.cleaned_data['fuel'],
                daily_km__lte=form.cleaned_data['daily_km'],
                price__lte=form.cleaned_data['price'],
                status=True)

            for otomobil in otomobils:
                baslangic = form.cleaned_data['baslangic']
                print(type(baslangic))
                bitis = form.cleaned_data['bitis']
                kiralar = Kira.objects.filter(otomobil=otomobil, status=True)
                kira_say = kiralar.__len__()
                a = 0
                for kira in kiralar:
                    if (baslangic < kira.rezdate and bitis < kira.rezdate) or (
                            baslangic > kira.rezdate
                            and baslangic > kira.returndate):
                        a = a + 1
                if a != kira_say:
                    arabalar.append(otomobil)

        otomobils = arabalar

    elif id == 1:
        otomobils = Otomobil.objects.filter(status=True)

    context = {
        'otomobils': otomobils,
        'category': category,
        'setting': setting,
        'sform1': sform1,
        'sform2': sform2,
    }
    return render(request, 'search.html', context)
Example #2
0
def contact(request):
    category = Category.objects.all()
    if request.method == 'POST':  # check post
        form = ContactForm(request.POST)
        if form.is_valid():
            data = ContactMessage()  # create relation with model
            data.name = form.cleaned_data['name']  # get form input data
            data.email = form.cleaned_data['email']
            data.subject = form.cleaned_data['subject']
            data.message = form.cleaned_data['message']
            data.ip = request.META.get('REMOTE_ADDR')
            data.save()  # save data to table
            messages.success(
                request,
                "Your message has ben sent. Thank you for your message.")
            return HttpResponseRedirect('/contact')

    form = ContactForm
    setting = Setting.objects.get(pk=1)
    sform1 = SearchForm1()
    context = {
        'setting': setting,
        'category': category,
        'form': form,
        'sform1': sform1
    }
    return render(request, 'contact.html', context)
Example #3
0
def user_password(request):
    if request.method == 'POST':
        form = PasswordChangeForm(request.user, request.POST)
        if form.is_valid():
            user = form.save()
            update_session_auth_hash(request, user)  # Important!
            messages.success(request,
                             'Your password was successfully updated!')
            return HttpResponseRedirect('/user')
        else:
            messages.error(
                request,
                'Please correct the error below.<br>' + str(form.errors))
            return HttpResponseRedirect('/user/password')
    else:
        category = Category.objects.all()
        form = PasswordChangeForm(request.user)
        setting = Setting.objects.get(pk=1)
        sform1 = SearchForm1()
        return render(
            request, 'user_password.html', {
                'form': form,
                'category': category,
                'setting': setting,
                'sform1': sform1
            })
Example #4
0
def user_update(request):
    if request.method == 'POST':
        user_form = UserUpdateForm(
            request.POST, instance=request.user)  # request.user is user  data
        profile_form = ProfileUpdateForm(request.POST,
                                         request.FILES,
                                         instance=request.user.userprofile)
        if user_form.is_valid() and profile_form.is_valid():
            user_form.save()
            profile_form.save()
            messages.success(request, 'Your account has been updated!')
            return HttpResponseRedirect('/user')
    else:
        category = Category.objects.all()
        user_form = UserUpdateForm(instance=request.user)
        profile_form = ProfileUpdateForm(
            instance=request.user.userprofile
        )  # "userprofile" model -> OneToOneField relatinon with user
        setting = Setting.objects.get(pk=1)
        sform1 = SearchForm1()
        context = {
            'category': category,
            'setting': setting,
            'user_form': user_form,
            'profile_form': profile_form,
            'sform1': sform1,
        }
        return render(request, 'user_update.html', context)
Example #5
0
def signup_form(request):
    if request.method == 'POST':
        form = SignUpForm(request.POST)
        if form.is_valid():
            form.save()  # completed sign up
            username = form.cleaned_data.get('username')
            password = form.cleaned_data.get('password1')
            user = authenticate(username=username, password=password)
            login(request, user)
            # Create data in profile table for user
            current_user = request.user
            data = UserProfile()
            data.user_id = current_user.id
            data.image = "images/users/user.png"
            data.save()
            messages.success(request, 'Your account has been created!')
            return HttpResponseRedirect('/')
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect('/signup')

    form = SignUpForm()
    setting = Setting.objects.get(pk=1)
    category = Category.objects.all()
    sform1 = SearchForm1()
    context = {
        'setting': setting,
        'category': category,
        'form': form,
        'sform1': sform1
    }

    return render(request, 'signup.html', context)
Example #6
0
def user_update_otomobil(request, id):
    otomobil = Otomobil.objects.get(id=id)
    if request.method == 'POST':
        form = OtomobilForm(request.POST, request.FILES, instance=otomobil)
        if form.is_valid():
            form.save()
            messages.success(request, "Your Otomobil ise Updateded")
            return HttpResponseRedirect('/user/user_otomobils')
        else:
            messages.success(request,
                             "Otomobil Form Error : " + str(form.errors))
            return HttpResponseRedirect('/user/user_otomobils')

    form = OtomobilForm(instance=otomobil)
    category = Category.objects.all()
    current_user = request.user
    otomobils = Otomobil.objects.filter(user_id=current_user.id)
    setting = Setting.objects.get(pk=1)
    sform1 = SearchForm1()
    context = {
        'category': category,
        'setting': setting,
        'otomobils': otomobils,
        'form': form,
        'sform1': sform1,
    }
    return render(request, 'user_otomobil_update.html', context)
Example #7
0
def faq(request):
    faq = FAQ.objects.filter(status="True")
    setting = Setting.objects.get(pk=1)
    category = Category.objects.all()
    sform1 = SearchForm1()
    context = {
        'setting': setting,
        'category': category,
        'faq': faq,
        'sform1': sform1,
    }
    return render(request, 'f*g.html', context)
Example #8
0
def user_otomobils(request):
    category = Category.objects.all()
    current_user = request.user
    otomobils = Otomobil.objects.filter(user_id=current_user.id)
    setting = Setting.objects.get(pk=1)
    sform1 = SearchForm1()
    context = {
        'category': category,
        'setting': setting,
        'otomobils': otomobils,
        'sform1': sform1
    }
    return render(request, 'user_otomobils.html', context)
Example #9
0
def index(request):
    category = Category.objects.all()
    current_user = request.user  # Access User Session information
    profile = UserProfile.objects.get(user_id=current_user.id)
    setting = Setting.objects.get(pk=1)
    sform1 = SearchForm1()
    context = {
        'category': category,
        'profile': profile,
        'setting': setting,
        'sform1': sform1
    }
    return render(request, 'user_profile.html', context)
Example #10
0
def user_comments(request):
    category = Category.objects.all()
    current_user = request.user
    comments = Comment.objects.filter(user_id=current_user.id)
    setting = Setting.objects.get(pk=1)
    sform1 = SearchForm1()
    context = {
        'category': category,
        'comments': comments,
        'setting': setting,
        'sform1': sform1,
    }
    return render(request, 'user_comments.html', context)
Example #11
0
def category_otomobils(request, id, slug):
    setting = Setting.objects.get(pk=1)
    catdata = Category.objects.get(pk=id)
    otomobils = Otomobil.objects.filter(category_id=id, status=True)
    category = Category.objects.all()
    sform1 = SearchForm1()
    context = {
        'otomobils': otomobils,
        'category': category,
        'catdata': catdata,
        'setting': setting,
        'sform1': sform1,
    }
    return render(request, 'category.html', context)
Example #12
0
def index(request):
    setting = Setting.objects.get(pk=1)
    otomobil_slider = Otomobil.objects.filter(
        status=True).order_by('-id')[:4]  # last 4
    category = Category.objects.filter(status=True).all()
    otomobil_picked = Otomobil.objects.all().order_by(
        '?')[:4]  # Random selected 4
    sform1 = SearchForm1()
    context = {
        'setting': setting,
        'sliderdata': otomobil_slider,
        'otomobils_picked': otomobil_picked,
        'category': category,
        'sform1': sform1
    }
    return render(request, "index.html", context)
    """aşağıdaki kısım direk bir içerik döndürmek için yukarıdaki kısım ise
Example #13
0
def otomobil_details(request, id, slug):
    setting = Setting.objects.get(pk=1)
    category = Category.objects.filter(status=True).all()
    otomobil = Otomobil.objects.get(pk=id)
    images = Images.objects.filter(otomobil=id).all()
    comments = Comment.objects.filter(otomobil=id, status=True).all()
    sform1 = SearchForm1()
    rezform = RezForm()
    context = {
        'setting': setting,
        'otomobil': otomobil,
        'comments': comments,
        'images': images,
        'category': category,
        'sform1': sform1,
        'rezform': rezform,
    }
    return render(request, 'otomobil_details.html', context)
Example #14
0
def user_otomobils_add(request):
    if request.method == 'POST':
        form = OtomobilForm(request.POST, request.FILES)

        if form.is_valid():
            current_user = request.user
            data = Otomobil()
            data.user_id = current_user.id
            data.title = form.cleaned_data['title']
            data.detail = form.cleaned_data['detail']
            data.category = form.cleaned_data['category']
            data.STATUS = 'False'

            data.location = form.cleaned_data['location']
            data.price = form.cleaned_data['price']
            data.day = form.cleaned_data['day']
            data.keywords = form.cleaned_data['keywords']
            data.description = form.cleaned_data['description']
            data.image = form.cleaned_data['image']
            data.slug = form.cleaned_data['slug']
            data.save()
            messages.success(request, "Your Otomobil is Added")
            return HttpResponseRedirect('/user/user_otomobils')
        else:
            messages.success(request,
                             "Otomobil Form Error : " + str(form.errors))
            return HttpResponseRedirect('/user/user_otomobils')

    form = OtomobilForm
    category = Category.objects.all()
    current_user = request.user
    otomobils = Otomobil.objects.filter(user_id=current_user.id)
    setting = Setting.objects.get(pk=1)
    sform1 = SearchForm1()
    context = {
        'category': category,
        'otomobils': otomobils,
        'setting': setting,
        'form': form,
        'sform1': sform1,
    }
    return render(request, 'user_otomobil_add.html', context)
Example #15
0
def login_form(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(request, username=username, password=password)
        if user is not None:
            login(request, user)
            # Redirect to a success page.
            return HttpResponseRedirect('/')
        else:
            messages.warning(
                request, "Login Error !! Username or Password is incorrect")
            return HttpResponseRedirect('/login')
    # Return an 'invalid login' error message.

    setting = Setting.objects.get(pk=1)
    category = Category.objects.all()
    sform1 = SearchForm1()
    context = {
        'setting': setting,
        'category': category,
        'sform1': sform1,
    }
    return render(request, 'signin.html', context)
Example #16
0
def referances(request):
    setting = Setting.objects.get(pk=1)
    category = Category.objects.all()
    sform1 = SearchForm1()
    context = {'setting': setting, 'category': category, 'sform1': sform1}
    return render(request, "referances.html", context)