Beispiel #1
0
    def get(self, request, *args, **kwargs):
        obj = get_object_or_404(Master, pk=kwargs.get('pk', None))
        buildings = Building.objects.all()
        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 Business: {obj}",
            "menu_section": "admin_dashboards",
            "menu_subsection": "admin_dashboards",
            "menu_action": "update",
            "obj": obj,
            "form": form,
            "buildings": buildings,
            "regions": regions,
            "provinces": provinces,
            "cities": cities,
            "default_region": default_region,
            "default_province": default_province,
            "default_city": default_city,
        }

        return render(request, "business/form.html", context)
Beispiel #2
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_business_detail',
                        kwargs={'pk': data.pk}))
        else:
            context = {
                "page_title": f"Update Business: {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, "business/form.html", context)
Beispiel #3
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_business_detail',
                        kwargs={'pk': data.pk}))
        else:
            context = {
                "page_title": "Create new Business",
                "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, "business/form.html", context)
Beispiel #4
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 Business: {obj}",
            "menu_section": "admin_dashboards",
            "menu_subsection": "admin_dashboards",
            "menu_action": "update",
            "obj": obj,
            "form": form
        }

        return render(request, "business/form.html", context)
Beispiel #5
0
    def post(self, request, *args, **kwargs):
        form = MasterForm(data=request.POST)

        business_formdata = {
            'name': request.POST.get('name', ''),
            'nature': request.POST.get('nature', ''),
            'owner_first_name': request.POST.get('owner_first_name', ''),
            'owner_middle_name': request.POST.get('owner_middle_name', ''),
            'owner_last_name': request.POST.get('owner_last_name', ''),
            'address': request.POST.get('address', ''),
            'landline': request.POST.get('landline', ''),
            'mobile_number': request.POST.get('mobile_number', ''),
            'email': request.POST.get('email', ''),
            'building': request.POST.get('building', ''),
            'region': request.POST.get('region', ''),
            'province': request.POST.get('province', ''),
            'city': request.POST.get('city', ''),
        }

        if form.is_valid():
            name = form.cleaned_data['name']
            nature = form.cleaned_data['nature']
            owner_first_name = form.cleaned_data['owner_first_name']
            owner_middle_name = form.cleaned_data['owner_middle_name']
            owner_last_name = form.cleaned_data['owner_last_name']
            address = form.cleaned_data['address']
            landline = form.cleaned_data['landline']
            mobile_number = form.cleaned_data['mobile_number']
            email = form.cleaned_data['email']
            building = form.cleaned_data['building']
            region = form.cleaned_data['region']
            province = form.cleaned_data['province']
            city = form.cleaned_data['city']

            business, building_message = Master.objects.create(
                name=name,
                nature=nature,
                owner_first_name=owner_first_name,
                owner_middle_name=owner_middle_name,
                owner_last_name=owner_last_name,
                address=address,
                landline=landline,
                mobile_number=mobile_number,
                email=email,
                building=building,
                region=region,
                province=province,
                city=city
            )

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

        return HttpResponseRedirect(reverse('admin_dashboard_business_create'))
Beispiel #6
0
    def post(self, request, *args, **kwargs):
        obj = get_object_or_404(Master, pk=kwargs.get('pk', None))
        form = MasterForm(request.POST, initial=obj)

        if form.is_valid():
            name = form.cleaned_data['name']
            nature = form.cleaned_data['nature']
            owner_first_name = form.cleaned_data['owner_first_name']
            owner_middle_name = form.cleaned_data['owner_middle_name']
            owner_last_name = form.cleaned_data['owner_last_name']
            address = form.cleaned_data['address']
            landline = form.cleaned_data['landline']
            mobile_number = form.cleaned_data['mobile_number']
            email = form.cleaned_data['email']
            building = form.cleaned_data['building']
            region = form.cleaned_data['region']
            province = form.cleaned_data['province']
            city = form.cleaned_data['city']

            Master.objects.filter(pk=obj.pk).update(
                name=name,
                nature=nature,
                owner_first_name=owner_first_name,
                owner_middle_name=owner_middle_name,
                owner_last_name=owner_last_name,
                address=address,
                landline=landline,
                mobile_number=mobile_number,
                email=email,
                building=building,
                region=region,
                province=province,
                city=city,
            )

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

            return HttpResponseRedirect(
                reverse(
                    'admin_dashboard_business_detail',
                    kwargs={
                        'pk': obj.pk
                    }
                )
            )
        else:
            context = {
                "page_title": f"Update Business: {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, "business/form.html", context)