Пример #1
0
    def get(self, request, *args, **kwargs):
        obj = get_object_or_404(Master, pk=kwargs.get('pk', None))
        form = MasterForm(initial=obj)
        default_region = Region.objects.get(pk=6)  # Region VI
        default_province = Province.objects.get(pk=22)  # Capiz
        default_city = City.objects.get(pk=381)  # Roxas City
        regions = Region.objects.all()
        provinces = Province.objects.filter(region=default_region)
        cities = City.objects.filter(province=default_province)

        context = {
            "page_title": f"Update Building: {obj}",
            "menu_section": "admin_dashboards",
            "menu_subsection": "admin_dashboards",
            "menu_action": "update",
            "obj": obj,
            "form": form,
            "regions": regions,
            "provinces": provinces,
            "cities": cities,
            "default_region": default_region,
            "default_province": default_province,
            "default_city": default_city,
        }

        return render(request, "building/form.html", context)
Пример #2
0
    def get(self, request, *args, **kwargs):
        obj = get_object_or_404(Master, pk = kwargs.get('pk', None))
        form = MasterForm(instance=obj)

        context = {
            "page_title": f"Update Building: {obj}",
            "menu_section": "admin_dashboards",
            "menu_subsection": "admin_dashboards",
            "menu_action": "update",
            "obj": obj,
            "form": form
        }

        return render(request, "building/form.html", context)
Пример #3
0
    def post(self, request, *args, **kwargs):
        obj = get_object_or_404(Master, pk = kwargs.get('pk', None))
        form = MasterForm(instance=obj, data=request.POST)

        if form.is_valid():
            data = form.save()
            messages.success(
                request,
                f'{data} saved!',
                extra_tags='success'
            )

            return HttpResponseRedirect(
                reverse(
                    'admin_dashboard_building_detail',
                    kwargs={
                        'pk': data.pk
                    }
                )
            )
        else:
            context = {
                "page_title": f"Update Building: {obj}",
                "menu_section": "admin_dashboards",
                "menu_subsection": "admin_dashboards",
                "menu_action": "update",
                "obj": obj,
                "form": form
            }

            messages.error(
                request,
                'There were errors processing your request:',
                extra_tags='danger'
            )
            return render(request, "building/form.html", context)
Пример #4
0
    def post(self, request, *args, **kwargs):
        form = MasterForm(data=request.POST)

        if form.is_valid():
            data = form.save(commit=False)
            data.created_by = request.user
            data.save()
            messages.success(
                request,
                f'{data} saved!',
                extra_tags='success'
            )

            return HttpResponseRedirect(
                reverse(
                    'admin_dashboard_building_detail',
                    kwargs={
                        'pk': data.pk
                    }
                )
            )
        else:
            context = {
                "page_title": "Create new Building",
                "menu_section": "admin_dashboards",
                "menu_subsection": "admin_dashboards",
                "menu_action": "create",
                "form": form
            }

            messages.error(
                request,
                'There were errors processing your request:',
                extra_tags='danger'
            )
            return render(request, "building/form.html", context)
Пример #5
0
    def post(self, request, *args, **kwargs):
        form = MasterForm(data=request.POST)

        building_formdata = {
            'name': request.POST.get('name', ''),
            'address': request.POST.get('address', ''),
            'latitude': request.POST.get('latitude', ''),
            'longitude': request.POST.get('longitude', ''),
            'date_of_construction': request.POST.get('date_of_construction',
                                                     ''),
            'floor_number': request.POST.get('floor_number', ''),
            'height': request.POST.get('height', ''),
            'floor_area': request.POST.get('floor_area', ''),
            'total_floor_area': request.POST.get('total_floor_area', ''),
            'beams': request.POST.get('beams', ''),
            'columns': request.POST.get('columns', ''),
            'flooring': request.POST.get('flooring', ''),
            'exterior_walls': request.POST.get('exterior_walls', ''),
            'corridor_walls': request.POST.get('corridor_walls', ''),
            'room_partitions': request.POST.get('room_partitions', ''),
            'main_stair': request.POST.get('main_stair', ''),
            'window': request.POST.get('window', ''),
            'ceiling': request.POST.get('ceiling', ''),
            'main_door': request.POST.get('main_door', ''),
            'trusses': request.POST.get('trusses', ''),
            'roof': request.POST.get('roof', ''),
            'entry_road_width': request.POST.get('entry_road_width', ''),
            'region': request.POST.get('region', ''),
            'province': request.POST.get('province', ''),
            'city': request.POST.get('city', ''),
        }

        if form.is_valid():
            name = form.cleaned_data['name']
            address = form.cleaned_data['address']
            latitude = form.cleaned_data['latitude']
            longitude = form.cleaned_data['longitude']
            date_of_construction = form.cleaned_data['date_of_construction']
            floor_number = form.cleaned_data['floor_number']
            height = form.cleaned_data['height']
            floor_area = form.cleaned_data['floor_area']
            total_floor_area = form.cleaned_data['total_floor_area']
            beams = form.cleaned_data['beams']
            columns = form.cleaned_data['columns']
            flooring = form.cleaned_data['flooring']
            exterior_walls = form.cleaned_data['exterior_walls']
            corridor_walls = form.cleaned_data['corridor_walls']
            room_partitions = form.cleaned_data['room_partitions']
            main_stair = form.cleaned_data['main_stair']
            window = form.cleaned_data['window']
            ceiling = form.cleaned_data['ceiling']
            main_door = form.cleaned_data['main_door']
            trusses = form.cleaned_data['trusses']
            roof = form.cleaned_data['roof']
            entry_road_width = form.cleaned_data['entry_road_width']
            region = form.cleaned_data['region']
            province = form.cleaned_data['province']
            city = form.cleaned_data['city']

            building, building_message = Master.objects.create(
                name=name,
                address=address,
                latitude=latitude,
                longitude=longitude,
                date_of_construction=date_of_construction,
                floor_number=floor_number,
                height=height,
                floor_area=floor_area,
                total_floor_area=total_floor_area,
                beams=beams,
                columns=columns,
                flooring=flooring,
                exterior_walls=exterior_walls,
                corridor_walls=corridor_walls,
                room_partitions=room_partitions,
                main_stair=main_stair,
                window=window,
                ceiling=ceiling,
                main_door=main_door,
                trusses=trusses,
                roof=roof,
                entry_road_width=entry_road_width,
                region=region,
                province=province,
                city=city)

            if building:
                messages.success(request,
                                 'Building created!',
                                 extra_tags='success')
                return HttpResponseRedirect(
                    reverse('admin_dashboard_business_create_by_building',
                            kwargs={'pk': building.pk}))
            else:
                messages.error(request, building_message, extra_tags='danger')
                request.session['building_formdata'] = building_formdata
        else:
            messages.error(request, form.errors, extra_tags='danger')
            request.session['building_formdata'] = building_formdata

        return HttpResponseRedirect(reverse('admin_dashboard_building_create'))
Пример #6
0
    def post(self, request, *args, **kwargs):
        obj = get_object_or_404(Master, pk=kwargs.get('pk', None))
        form = MasterForm(initial=obj, data=request.POST)
        default_region = Region.objects.get(pk=6)  # Region VI
        default_province = Province.objects.get(pk=22)  # Capiz
        default_city = City.objects.get(pk=381)  # Roxas City
        regions = Region.objects.all()
        provinces = Province.objects.filter(region=default_region)
        cities = City.objects.filter(province=default_province)

        if form.is_valid():
            name = form.cleaned_data['name']
            address = form.cleaned_data['address']
            latitude = form.cleaned_data['latitude']
            longitude = form.cleaned_data['longitude']
            date_of_construction = form.cleaned_data['date_of_construction']
            floor_number = form.cleaned_data['floor_number']
            height = form.cleaned_data['height']
            floor_area = form.cleaned_data['floor_area']
            total_floor_area = form.cleaned_data['total_floor_area']
            beams = form.cleaned_data['beams']
            columns = form.cleaned_data['columns']
            flooring = form.cleaned_data['flooring']
            exterior_walls = form.cleaned_data['exterior_walls']
            corridor_walls = form.cleaned_data['corridor_walls']
            room_partitions = form.cleaned_data['room_partitions']
            main_stair = form.cleaned_data['main_stair']
            window = form.cleaned_data['window']
            ceiling = form.cleaned_data['ceiling']
            main_door = form.cleaned_data['main_door']
            trusses = form.cleaned_data['trusses']
            roof = form.cleaned_data['roof']
            entry_road_width = form.cleaned_data['entry_road_width']
            region = form.cleaned_data['region']
            province = form.cleaned_data['province']
            city = form.cleaned_data['city']

            Master.objects.filter(pk=obj.pk).update(
                name=name,
                address=address,
                longitude=longitude,
                date_of_construction=date_of_construction,
                floor_number=floor_number,
                height=height,
                floor_area=floor_area,
                total_floor_area=total_floor_area,
                beams=beams,
                columns=columns,
                flooring=flooring,
                exterior_walls=exterior_walls,
                corridor_walls=corridor_walls,
                room_partitions=room_partitions,
                main_stair=main_stair,
                window=window,
                ceiling=ceiling,
                main_door=main_door,
                trusses=trusses,
                roof=roof,
                entry_road_width=entry_road_width,
                region=region,
                province=province,
                city=city,
            )

            messages.success(request, f'{obj} saved!', extra_tags='success')

            return HttpResponseRedirect(
                reverse('admin_dashboard_building_detail',
                        kwargs={'pk': obj.pk}))
        else:
            context = {
                "page_title": f"Update Building: {obj}",
                "menu_section": "admin_dashboards",
                "menu_subsection": "admin_dashboards",
                "menu_action": "update",
                "obj": obj,
                "form": form,
                "regions": regions,
                "provinces": provinces,
                "cities": cities,
                "default_region": default_region,
                "default_province": default_province,
                "default_city": default_city,
            }

            messages.error(request, form.errors, extra_tags='danger')
            return render(request, "building/form.html", context)