def project_subfirma(request, pk):
    perm = general_methods.control_access_personel(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')

    try:
        tasinmaz = Gtasinmaz.objects.get(pk=pk)
        if request.POST.get('title'):
            birim = Gkurum.objects.get(pk=request.POST.get('title'))
            tasinmaz.kurum.add(birim)
            tasinmaz.save()
            log = str(tasinmaz.pk) + " tasinmaz kullanan birim eklendi" + str(
                birim.name)
            log = general_methods.logwrite(request, log)
        return JsonResponse({
            'status': 'Success',
            'messages': 'save successfully',
            'pk': birim.pk
        })

    except:
        return JsonResponse({'status': 'Fail', 'msg': 'Not a valid request'})
        messages.warning(request, 'Yeniden deneyiniz.')

    return redirect('sbs:tasinmaz-duzenle', pk=pk)
def delete_birim_tasinmaz(request, tasinmaz, kurum):
    perm = general_methods.control_access_personel(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')
    if request.method == 'POST' and request.is_ajax():
        tasinmaz = Gtasinmaz.objects.get(pk=tasinmaz)
        kurum = Gkurum.objects.get(pk=kurum)
        tasinmaz.kurum.remove(kurum)
        tasinmaz.save()
        try:
            # tasinmaz = Gtasinmaz.objects.get(pk=tasinmaz)
            # kurum=Gkurum.objects.get(pk=kurum)
            # tasinmaz.kurum.remove(kurum)
            # tasinmaz.save()
            print()
            return JsonResponse({
                'status': 'Success',
                'messages': 'save successfully'
            })
        except:
            return JsonResponse({
                'status': 'Fail',
                'msg': 'Object does not exist'
            })

    else:
        return JsonResponse({'status': 'Fail', 'msg': 'Not a valid request'})
def tasinmaz_nitelikEkle(request, pk):
    perm = general_methods.control_access_personel(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')

    try:
        if request.POST.get('tasinmaz'):
            tasimaz = Gtasinmaz.objects.get(pk=request.POST.get('tasinmaz'))
            nitelik = Gbolge.objects.get(pk=request.POST.get('nitelik'))
            teskilat = Gteskilat.objects.get(pk=pk)

            tasimaz.teskilat = teskilat
            tasimaz.nitelik = nitelik
            tasimaz.save()

            # tasinmaz.kurum.add(birim)
            # tasinmaz.save()
            # log = str(tasinmaz.pk) + " tasinmaz kullanan birim eklendi" + str(birim.name)
            # log = general_methods.logwrite(request, log)
        return JsonResponse({
            'status': 'Success',
            'messages': 'save successfully',
            'pk': tasimaz.pk
        })

    except:
        return JsonResponse({'status': 'Fail', 'msg': 'Not a valid request'})
        messages.warning(request, 'Yeniden deneyiniz.')

    return redirect('sbs:tasinmaz-duzenle', pk=pk)
def edit_teskilat(request, pk):
    perm = general_methods.control_access_personel(request)
    if not perm:
        logout(request)
        return redirect('accounts:login')
    teskilat = Gteskilat.objects.get(pk=pk)
    test = False
    if teskilat.mahaltype.shortname == 'YOK':
        test = True
    teskilat_form = GteskilatForm(request.POST or None, instance=teskilat)
    nitelik = Gbolge.objects.all()
    tasinmazlar = Gtasinmaz.objects.filter(
        tasinmazinTuru=Gtasinmaz.adaletYapisi)
    testasinmaz = Gtasinmaz.objects.filter(teskilat=teskilat)

    teskilat_form.fields['bam'].queryset = Gteskilat.objects.filter(
        mahaltype__shortname='BAM')
    teskilat_form.fields['bim'].queryset = Gteskilat.objects.filter(
        mahaltype__shortname='BİM')
    teskilat_form.fields['acm'].queryset = Gteskilat.objects.filter(
        mahaltype__shortname='ACM')
    teskilat_form.fields['ascm'].queryset = Gteskilat.objects.filter(
        mahaltype__shortname='ASCM')
    teskilat_form.fields['ida'].queryset = Gteskilat.objects.filter(
        mahaltype__shortname='İDA')
    teskilat_form.fields['ivm'].queryset = Gteskilat.objects.filter(
        mahaltype__shortname='İVD')
    if request.method == 'POST':
        if teskilat_form.is_valid():

            # for item in teskilat.mahaltype.all():
            #     teskilat.mahaltype.remove(item)
            #     teskilat.save()

            teskilat_form.save()
            # if request.POST.getlist('ages'):
            #     for item in request.POST.getlist('ages'):
            #         teskilat.mahaltype.add(Gbolge.objects.get(pk=item))
            #         teskilat.save()
            log = str(teskilat.city) + " teşkilat yapısı güncellendi."
            log = general_methods.logwrite(request, log)
            messages.success(request, 'Teşkilat Yapısı güncellendi.')
        else:
            print('alanlari kontrol ediniz ')
            messages.warning(request, 'Alanları kontrol ediniz.')
    return render(
        request, 'teskilat/teskilatGuncelle.html', {
            'project_form': teskilat_form,
            'nitelik': nitelik,
            'tasinmazlar': tasinmazlar,
            'testasinmaz': testasinmaz,
            'test': test,
        })
Beispiel #5
0
def notification(request):
    perm = general_methods.control_access_personel(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')

    notification = Notification.objects.filter(
        users=request.user).order_by('-creationDate').distinct()
    return render(request, 'notification/notification.html', {
        'notification': notification,
    })
def add_offer_to_project(request, pk):
    perm = general_methods.control_access_personel(request)

    print('geldim')

    if not perm:
        logout(request)
        return redirect('accounts:login')

    message = request.POST.get('message')
    project = Gtasinmaz.objects.get(pk=pk)
    username = request.user.first_name + " " + request.user.last_name
    person = getProfileImage(request)
    imageUrl = MEDIA_URL + "profile/logo.png"
    date = datetime.now()
    dates = date.strftime('%d/%m/%Y %H:%M')

    log = str(
        project.pk) + " tasinmazina  yeni bir görüs ekledi time=" + str(dates)
    log = general_methods.logwrite(request, log)

    project.offers.create(message=message, added_by=request.user)

    # for item in project.employees.all().exclude(employee__user=request.user):
    #     notification = Notification(notification=project.name +" Projesine yeni bir görüs eklendi.",
    #                                 users=item.employee.user,
    #                                 entityId=project.pk,
    #                                 tableName="proje"
    #                                 )
    #     notification.save()
    #
    #
    #

    try:
        print()

        return JsonResponse({
            'status': 'Success',
            'username': username,
            'image': imageUrl,
            'dates': dates
        })
    except:
        return JsonResponse({'status': 'Fail', 'msg': 'Not a valid request'})

    return redirect('sbs:proje-duzenle', pk=pk)
def edit_kurum(request, pk):
    perm = general_methods.control_access_personel(request)
    if not perm:
        logout(request)
        return redirect('accounts:login')
    kurum = Gkurum.objects.get(pk=pk)
    kurum_form = KurumForm(request.POST or None, instance=kurum)
    kurum = Gkurum.objects.all()
    if request.method == 'POST':
        if kurum_form.is_valid():
            kurum_form.save()
            return redirect('sbs:kurum-add', )

    return render(request, 'kurum/KurumGuncelle.html', {
        'kurum': kurum,
        'kurum_form': kurum_form
    })
def tasinmaz_list(request):
    perm = general_methods.control_access_personel(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')

    projects = Gtasinmaz.objects.none()
    tasinmaz_form = GtasinmazSearchForm()
    teskilat_form = GteskilatSearchForm()
    if request.method == 'POST':

        city = request.POST.get('city')
        town = request.POST.get('town')
        sirano = request.POST.get('sirano')
        tkgmno = request.POST.get('tkgmno')
        tahsis_durumu = request.POST.get('tahsisDurumu')
        tasinmazinTuru = request.POST.get('tasinmazinTuru')
        if not (sirano or tkgmno or tasinmazinTuru or tahsis_durumu or city
                or town):
            projects = Gtasinmaz.objects.all()
        else:
            query = Q()
            if sirano:
                query &= Q(sirano=sirano)
            if tkgmno:
                query &= Q(tkgmno=tkgmno)
            if tasinmazinTuru:
                query &= Q(tasinmazinTuru=tasinmazinTuru)
            if tahsis_durumu:
                query &= Q(tahsisDurumu=tahsis_durumu)
            if city:
                query &= Q(tapu__city_id=int(city))
            if town:
                query &= Q(tapu__town_id=int(town))

            if request.user.groups.filter(name__in=['Yonetim', 'Admin']):
                projects = Gtasinmaz.objects.filter(query).distinct()

    return render(
        request, 'tasinmaz/tasinmazlar.html', {
            'projects': projects,
            'teskilat_form': teskilat_form,
            'tasinmaz_form': tasinmaz_form
        })
def updateRefereeProfile(request):
    perm = general_methods.control_access_personel(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')

    user = request.user
    referee_user = Employee.objects.get(user=user)
    person = Person.objects.get(pk=referee_user.person.pk)
    communication = Communication.objects.get(pk=referee_user.communication.pk)
    user_form = DisabledUserForm(request.POST or None, instance=user)
    person_form = DisabledPersonForm(request.POST or None, request.FILES or None, instance=person)
    communication_form = DisabledCommunicationForm(request.POST or None, instance=communication)
    password_form = SetPasswordForm(request.user, request.POST)

    if request.method == 'POST':
        person_form = DisabledPersonForm(request.POST, request.FILES)
        try:
            if request.FILES['profileImage']:
                print('deger var ')
                person.profileImage = request.FILES['profileImage']
                person.save()
                messages.success(request, 'Resim güncellendi.')

        except:
            print('hata' )


        if password_form.is_valid():
            user.set_password(password_form.cleaned_data['new_password2'])
            user.save()
            update_session_auth_hash(request, user)
            messages.success(request, 'Şifre Başarıyla Güncellenmiştir.')
            return redirect('sbs:teknik-profil-guncelle')

        else:
            return redirect('sbs:teknik-profil-guncelle')

    return render(request, 'personel/Personel-Profil-güncelle.html',
                  {'user_form': user_form, 'communication_form': communication_form,
                   'person_form': person_form, 'password_form': password_form})
def add_kurum(request):
    perm = general_methods.control_access_personel(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')

    if request.method == 'POST':
        kurum_form = KurumForm(request.POST or None)
        if kurum_form.is_valid():
            kurum = kurum_form.save(commit=False)
            kurum.save()
        else:
            messages.warning(request, 'Alanları Kontrol Ediniz')
    kurum = Gkurum.objects.all()
    kurum_form = KurumForm()

    return render(request, 'kurum/kurumEkle.html', {
        'kurum_form': kurum_form,
        'kurum': kurum
    })
def nitelik(request):
    perm = general_methods.control_access_personel(request)
    if not perm:
        logout(request)
        return redirect('accounts:login')

    try:
        if request.method == 'POST':
            teskilat = Gteskilat.objects.get(pk=int(request.POST.get('cmd')))
            beka = []

            for item in teskilat.mahaltype.exclude(name__icontains='mulakat'):
                data = {
                    'pk': item.pk,
                    'name': item.name,
                }
                beka.append(data)
            return JsonResponse({'data': beka, 'msg': 'Valid is  request'})

    except:
        return JsonResponse({'status': 'Fail', 'msg': 'Not a valid request'})
def delete_ofters_from_project(request, project_pk, employee_pk):
    perm = general_methods.control_access_personel(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')
    if request.method == 'POST' and request.is_ajax():
        try:
            athlete = Gtasinmaz.objects.get(pk=project_pk)
            athlete.offers.remove(employee_pk)
            return JsonResponse({
                'status': 'Success',
                'messages': 'save successfully'
            })
        except:
            return JsonResponse({
                'status': 'Fail',
                'msg': 'Object does not exist'
            })

    else:
        return JsonResponse({'status': 'Fail', 'msg': 'Not a valid request'})
def edit_tasinmaz(request, pk):
    perm = general_methods.control_access_personel(request)

    if not perm:
        logout(request)
        return redirect('accounts:login')
    tasinmaz = Gtasinmaz.objects.get(pk=pk)
    gkurum = Gkurum.objects.all()
    evraklist = []
    tasinmazImage = []
    dokuman_form = GtasinmazDokumanForm(request.POST, request.FILES or None)
    if tasinmaz.documents.all():
        evraklist = []
        for item in tasinmaz.documents.all():
            uzanti = item.file.name.split(".")[len(item.file.name.split(".")) -
                                               1]
            if uzanti == "jpg" or uzanti == "png" or uzanti == "jpeg":
                beka = {'file': item.file, 'title': item.title}
                evraklist.append(beka)
                print(item.file)
    if GdokumanBirim.objects.filter(name='Taşınmaz Görseli'):

        for item in tasinmaz.documents.filter(title__name='Taşınmaz Görseli'):
            uzanti = item.file.name.split(".")[len(item.file.name.split(".")) -
                                               1]
            if uzanti == "jpg" or uzanti == "png" or uzanti == "jpeg":
                beka = {'file': item.file, 'title': item.title}
                tasinmazImage.append(beka)
                print(item.file)

    if tasinmaz.tapu == None:
        tapu = GTapu()
        tapu.save()
        tasinmaz.tapu = tapu
        tasinmaz.save()
    print(tasinmaz.tasinmazinTuru)

    if tasinmaz.tasinmazinTuru == tasinmaz.adaletYapisi:
        project_form = GtasinmazAdliyeForm(request.POST or None,
                                           instance=tasinmaz)
        tapu = GTapu.objects.get(pk=tasinmaz.tapu.pk)
        tapu_form = TapuForm(request.POST or None, instance=tapu)
        if not (tasinmaz.tahsis):
            tahsis = Gtahsis()
            tahsis.save()
            tasinmaz.tahsis = tahsis
            tasinmaz.save()

        if not (tasinmaz.kira):
            kira = Gkira()
            kira.save()
            tasinmaz.kira = kira
            tasinmaz.save()
        kiralik = Gkira.objects.get(pk=tasinmaz.kira.pk)
        tahsis = Gtahsis.objects.get(pk=tasinmaz.tahsis.pk)
        kiralik_form = GkiraForm(request.POST or None, instance=kiralik)
        tahsis_form = GtahsisForm(request.POST or None, instance=tahsis)

        if request.method == 'POST':
            if project_form.is_valid() and tapu_form.is_valid():
                projectSave = project_form.save(commit=False)
                projectSave.save()
                tapu_form.save()
                log = str(tasinmaz.pk) + "tasinmaz  güncelledi"
                log = general_methods.logwrite(request, log)

            else:
                print('alanlari kontrol ediniz adalet')
                messages.warning(request, 'Alanlari kontrol ediniz')
            # kaydetme testi yapılacak
            if kiralik_form.is_valid():
                kiralik_form.save()
                print('kiralik save')

            if tahsis_form.is_valid():
                tahsis_form.save()
                print('tahsis save ')

            if request.FILES.getlist('file') and request.POST.get('title'):

                for item in request.FILES.getlist('file'):
                    dokuman = GtasinmazDocument(
                        title=GdokumanBirim.objects.get(
                            pk=int(request.POST.get('title'))),
                        file=item)
                    dokuman.save()
                    tasinmaz.documents.add(dokuman)
                    tasinmaz.save()
                    print('dokuman save')

            if request.FILES.get('tasinmazimage'):
                if GdokumanBirim.objects.filter(name='Taşınmaz Görseli'):
                    dokuman = GtasinmazDocument(
                        title=GdokumanBirim.objects.get(
                            name='Taşınmaz Görseli'),
                        file=request.FILES.get('tasinmazimage'))
                    dokuman.save()
                    tasinmaz.documents.add(dokuman)
                    tasinmaz.save()
                else:
                    birim = GdokumanBirim(name='Taşınmaz Görseli')
                    birim.save()
                    dokuman = GtasinmazDocument(
                        title=birim, file=request.FILES.get('tasinmazimage'))
                    dokuman.save()
                    tasinmaz.documents.add(dokuman)
                    tasinmaz.save()

            return redirect('sbs:tasinmaz-duzenle', pk=projectSave.pk)

        if tasinmaz.tapu.city:
            if tasinmaz.tapu.town:
                tapu_form.fields['town'].queryset = Town.objects.filter(
                    cityId=tasinmaz.tapu.city.pk)
                tapu_form.fields['town'].initial = tasinmaz.tapu.town.name
            else:
                tapu_form.fields['town'].queryset = Town.objects.filter(
                    cityId=tasinmaz.tapu.city.pk)
        else:
            tapu_form.fields['town'].queryset = Town.objects.none()

        return render(
            request, 'tasinmaz/tasinmazAdliyeGuncelle.html', {
                'project_form': project_form,
                'project': tasinmaz,
                'tapu_form': tapu_form,
                'gkurum': gkurum,
                'tahsis_form': tahsis_form,
                'kiralik_form': kiralik_form,
                'dokuman_form': dokuman_form,
                'evraklist': evraklist,
                'tasinmazImage': tasinmazImage
            })

    elif tasinmaz.tasinmazinTuru == tasinmaz.tahisisliArsalar:
        project_form = GtasinmazArsaForm(request.POST or None,
                                         instance=tasinmaz)
        tapu_form = TapuForm(request.POST or None, instance=tasinmaz.tapu)

        if not (tasinmaz.tahsis):
            tahsis = Gtahsis()
            tahsis.save()
            tasinmaz.tahsis = tahsis
            tasinmaz.save()

        tah = Gtahsis.objects.get(pk=tasinmaz.tahsis.pk)

        tahsis_form = GtahsisForm(request.POST or None, instance=tah)

        if request.method == 'POST':

            if dokuman_form.is_valid():
                if request.FILES.get('file') and request.POST.get('title'):
                    dokuman = dokuman_form.save(commit=False)
                    dokuman.save()
                    tasinmaz.documents.add(dokuman)
                    tasinmaz.save()
                    print('dokuman save')

            if project_form.is_valid() and tapu_form.is_valid():
                projectSave = project_form.save(commit=False)
                projectSave.save()
                tapu_form.save()
                log = str(tasinmaz.pk) + "tasinmaz  güncelledi"
                log = general_methods.logwrite(request, log)
                print('log arsa ')
                return redirect('sbs:tasinmaz-duzenle', pk=projectSave.pk)
            else:
                print('alanlari kontrol ediniz arsa')
                messages.warning(request, 'Alanlari kontrol ediniz')
        if tasinmaz.tapu.city:
            if tasinmaz.tapu.town:
                tapu_form.fields['town'].queryset = Town.objects.filter(
                    cityId=tasinmaz.tapu.city.pk)
                tapu_form.fields['town'].initial = tasinmaz.tapu.town.name
            else:
                tapu_form.fields['town'].queryset = Town.objects.filter(
                    cityId=tasinmaz.tapu.city.pk)
        else:
            tapu_form.fields['town'].queryset = Town.objects.none()

        project_form.fields['tahsisDurumu'].queryset = None
        project_form.fields['tahsisDurumu'].initial = tasinmaz.TahsisliArsa

        return render(
            request, 'tasinmaz/tasinmaztahsisliArsaGuncelle.html', {
                'project_form': project_form,
                'tapu_form': tapu_form,
                'tahsis_form': tahsis_form,
                'gkurum': gkurum,
                'project': tasinmaz,
                'dokuman_form': dokuman_form,
            })
    elif tasinmaz.tasinmazinTuru == tasinmaz.lojmanlar:

        project_form = GtasinmazlojmanForm(request.POST or None,
                                           instance=tasinmaz)
        tapu_form = TapuForm(request.POST or None, instance=tasinmaz.tapu)
        if not (tasinmaz.tahsis):
            tahsis = Gtahsis()
            tahsis.save()
            tasinmaz.tahsis = tahsis
            tasinmaz.save()

        if not (tasinmaz.kira):
            kira = Gkira()
            kira.save()
            tasinmaz.kira = kira
            tasinmaz.save()
        kiralik_form = GkiraForm(request.POST or None, instance=tasinmaz.kira)
        tahsis_form = GtahsisForm(request.POST or None,
                                  instance=tasinmaz.tahsis)
        if request.method == 'POST':

            if dokuman_form.is_valid():
                if request.FILES.get('file') and request.POST.get('title'):
                    dokuman = dokuman_form.save(commit=False)
                    dokuman.save()
                    tasinmaz.documents.add(dokuman)
                    tasinmaz.save()
                    print('dokuman save')

            if kiralik_form.is_valid():
                kiralik_form.save()

            if tahsis_form.is_valid():
                tahsis_form.save()

            if project_form.is_valid() and tapu_form.is_valid():
                projectSave = project_form.save(commit=False)
                projectSave.save()
                tapu_form.save()
                log = str(tasinmaz.pk) + "tasinmaz  güncelledi"
                log = general_methods.logwrite(request, log)
                print('log lojman ')
                return redirect('sbs:tasinmaz-duzenle', pk=projectSave.pk)
            else:
                print('alanlari kontrol ediniz lojman')
                for item in project_form.errors:
                    print(item)
                messages.warning(request, 'Alanlari kontrol ediniz')

        if tasinmaz.tapu.city:
            if tasinmaz.tapu.town:
                tapu_form.fields['town'].queryset = Town.objects.filter(
                    cityId=tasinmaz.tapu.city.pk)
                tapu_form.fields['town'].initial = tasinmaz.tapu.town.name
            else:
                tapu_form.fields['town'].queryset = Town.objects.filter(
                    cityId=tasinmaz.tapu.city.pk)
        else:
            tapu_form.fields['town'].queryset = Town.objects.none()

        return render(
            request, 'tasinmaz/TasinmazLojmanGuncelle.html', {
                'project_form': project_form,
                'tapu_form': tapu_form,
                'tahsis_form': tahsis_form,
                'kiralik_form': kiralik_form,
                'gkurum': gkurum,
                'project': tasinmaz,
                'dokuman_form': dokuman_form,
            })

    elif tasinmaz.tasinmazinTuru == tasinmaz.cezaInfazKurumlari:
        project_form = GtasinmazcezainfazForm(request.POST or None,
                                              instance=tasinmaz)
        tapu_form = TapuForm(request.POST or None, instance=tasinmaz.tapu)
        if not (tasinmaz.tahsis):
            tahsis = Gtahsis()
            tahsis.save()
            tasinmaz.tahsis = tahsis
            tasinmaz.save()

        if not (tasinmaz.kira):
            kira = Gkira()
            kira.save()
            tasinmaz.kira = kira
            tasinmaz.save()
        kiralik_form = GkiraForm(request.POST or None, instance=tasinmaz.kira)
        tahsis_form = GtahsisForm(request.POST or None,
                                  instance=tasinmaz.tahsis)
        if request.method == 'POST':

            if dokuman_form.is_valid():
                if request.FILES.get('file') and request.POST.get('title'):
                    dokuman = dokuman_form.save(commit=False)
                    dokuman.save()
                    tasinmaz.documents.add(dokuman)
                    tasinmaz.save()
                    print('dokuman save')

            if kiralik_form.is_valid():
                kiralik_form.save()

            if tahsis_form.is_valid():
                tahsis_form.save()

            if project_form.is_valid() and tapu_form.is_valid():
                projectSave = project_form.save(commit=False)
                projectSave.save()
                tapu_form.save()
                log = str(tasinmaz.pk) + "tasinmaz  güncelledi"
                log = general_methods.logwrite(request, log)
                print('log ceza ')
                return redirect('sbs:tasinmaz-duzenle', pk=projectSave.pk)

            else:
                print('alanlari kontrol ediniz ceza')
                messages.warning(request, 'Alanlari kontrol ediniz')

        if tasinmaz.tapu.city:
            if tasinmaz.tapu.town:
                tapu_form.fields['town'].queryset = Town.objects.filter(
                    cityId=tasinmaz.tapu.city.pk)
                tapu_form.fields['town'].initial = tasinmaz.tapu.town.name
            else:
                tapu_form.fields['town'].queryset = Town.objects.filter(
                    cityId=tasinmaz.tapu.city.pk)
        else:
            tapu_form.fields['town'].queryset = Town.objects.none()

        return render(
            request, 'tasinmaz/tasinmazCezaInfazGuncellle.html', {
                'project_form': project_form,
                'tapu_form': tapu_form,
                'kiralik_form': kiralik_form,
                'tahsis_form': tahsis_form,
                'gkurum': gkurum,
                'project': tasinmaz,
                'dokuman_form': dokuman_form,
            })
    elif tasinmaz.tasinmazinTuru == tasinmaz.egitimMerkezi:
        project_form = GtasinmazEgitimForm(request.POST or None,
                                           instance=tasinmaz)
        tapu_form = TapuForm(request.POST or None, instance=tasinmaz.tapu)
        if not (tasinmaz.tahsis):
            tahsis = Gtahsis()
            tahsis.save()
            tasinmaz.tahsis = tahsis
            tasinmaz.save()

        if not (tasinmaz.kira):
            kira = Gkira()
            kira.save()
            tasinmaz.kira = kira
            tasinmaz.save()
        kiralik_form = GkiraForm(request.POST or None, instance=tasinmaz.kira)
        tahsis_form = GtahsisForm(request.POST or None,
                                  instance=tasinmaz.tahsis)
        # gkurum = Gkurum.objects.all()

        if kiralik_form.is_valid():
            kiralik_form.save()

        if tahsis_form.is_valid():
            tahsis_form.save()

        if dokuman_form.is_valid():
            if request.FILES.get('file') and request.POST.get('title'):
                dokuman = dokuman_form.save(commit=False)
                dokuman.save()
                tasinmaz.documents.add(dokuman)
                tasinmaz.save()
                print('dokuman save')
        if project_form.is_valid() and tapu_form.is_valid():
            projectSave = project_form.save(commit=False)
            projectSave.save()
            tapu_form.save()
            log = str(tasinmaz.pk) + "tasinmaz  güncelledi"
            log = general_methods.logwrite(request, log)
            print('log karma ')
            return redirect('sbs:tasinmaz-duzenle', pk=projectSave.pk)

        return render(
            request, 'tasinmaz/tasinmazEgitimGuncelle.html', {
                'project_form': project_form,
                'tapu_form': tapu_form,
                'gkurum': gkurum,
                'project': tasinmaz,
                'kiralik_form': kiralik_form,
                'tahsis_form': tahsis_form,
                'dokuman_form': dokuman_form,
            })
    else:
        project_form = GtasinmazForm(request.POST or None, instance=tasinmaz)
        tapu_form = TapuForm(request.POST or None, instance=tasinmaz.tapu)
        if not (tasinmaz.tahsis):
            tahsis = Gtahsis()
            tahsis.save()
            tasinmaz.tahsis = tahsis
            tasinmaz.save()

        if not (tasinmaz.kira):
            kira = Gkira()
            kira.save()
            tasinmaz.kira = kira
            tasinmaz.save()
        kiralik_form = GkiraForm(request.POST or None, instance=tasinmaz.kira)
        tahsis_form = GtahsisForm(request.POST or None,
                                  instance=tasinmaz.tahsis)
        # gkurum = Gkurum.objects.all()

        if kiralik_form.is_valid():
            kiralik_form.save()

        if tahsis_form.is_valid():
            tahsis_form.save()

        if dokuman_form.is_valid():
            if request.FILES.get('file') and request.POST.get('title'):
                dokuman = dokuman_form.save(commit=False)
                dokuman.save()
                tasinmaz.documents.add(dokuman)
                tasinmaz.save()
                print('dokuman save')
        if project_form.is_valid() and tapu_form.is_valid():
            projectSave = project_form.save(commit=False)
            projectSave.save()
            tapu_form.save()
            log = str(tasinmaz.pk) + "tasinmaz  güncelledi"
            log = general_methods.logwrite(request, log)
            print('log karma ')
            return redirect('sbs:tasinmaz-duzenle', pk=projectSave.pk)

        return render(
            request, 'tasinmaz/tasinmazGuncelle.html', {
                'project_form': project_form,
                'tapu_form': tapu_form,
                'gkurum': gkurum,
                'project': tasinmaz,
                'kiralik_form': kiralik_form,
                'tahsis_form': tahsis_form,
                'dokuman_form': dokuman_form,
            })