def website_contact_view(request): alerts = [] if request.method == "POST": contact_form = forms.WebsiteContactsForm(request.POST, prefix='contacts') contact_seo_form = forms.SEOForm(request.POST, prefix='SEO') if utils.forms_save([ contact_form, contact_seo_form, ]): alerts.append('Данные сохранены успешно!') else: contacts: models.WebsiteContacts = models.WebsiteContacts.get_solo() if not contacts.seo: contacts.seo = models.SEO.objects.create() contacts.save() contact_form = forms.WebsiteContactsForm( instance=contacts, prefix='contacts', ) contact_seo_form = forms.SEOForm( instance=contacts.seo, prefix='SEO', ) context = { 'contact_form': contact_form, 'contact_seo_form': contact_seo_form, 'alerts': alerts, } return render(request, 'admin/website/contact.html', context)
def website_about_view(request): alerts = [] about_gallery_count = models.WebsiteAboutGallery.objects.count() WebsiteAboutGalleryFormset = modelformset_factory( model=models.WebsiteAboutGallery, form=forms.WebsiteAboutGalleryForm, max_num=about_gallery_count if about_gallery_count > 0 else 1, ) if request.method == 'POST': about_form = forms.WebsiteAboutForm( request.POST, request.FILES, prefix='about_form', ) about_gallery_formset = WebsiteAboutGalleryFormset( request.POST, request.FILES, prefix='about_gallery_form', ) about_seo_form = forms.SEOForm( request.POST, prefix='about_seo_form', ) if utils.forms_save([ about_form, about_seo_form, about_gallery_formset, ]): alerts.append('Данные сохранены успешно!') else: about: models.WebsiteAbout = models.WebsiteAbout.get_solo() if not about.seo: about.seo = models.SEO.objects.create() about.save() about_form = forms.WebsiteAboutForm( instance=about, prefix='about_form', ) about_gallery_formset = WebsiteAboutGalleryFormset( prefix='about_gallery_form', ) about_seo_form = forms.SEOForm( instance=about.seo, prefix='about_seo_form', ) context = { 'alerts': alerts, 'about_form': about_form, 'about_gallery_formset': about_gallery_formset, 'about_seo_form': about_seo_form, } return render(request, 'admin/website/about.html', context)
def website_tariffs_view(request): tariffs_count = models.WebsiteTariffBlocks.objects.count() TariffsBlockFormset = modelformset_factory( model=models.WebsiteTariffBlocks, form=forms.WebsiteTariffsBlocksForm, max_num=tariffs_count if tariffs_count > 0 else 1, ) alerts = [] if request.method == 'POST': tariffs_form = forms.WebsiteTariffsForm( request.POST, request.FILES, prefix='tariffs_form', ) tariffs_block_formset = TariffsBlockFormset( request.POST, request.FILES, prefix='tariffs_block_form', ) tariffs_seo_form = forms.SEOForm( request.POST, prefix='tariffs_seo_form', ) if utils.forms_save([ tariffs_form, tariffs_block_formset, tariffs_seo_form, ]): alerts.append('Данные сохранены успешно!') else: tariffs: models.WebsiteTariffs = models.WebsiteTariffs.get_solo() if not tariffs.seo: tariffs.seo = models.SEO.objects.create() tariffs.save() tariffs_form = forms.WebsiteTariffsForm( instance=tariffs, prefix='tariffs_form', ) tariffs_block_formset = TariffsBlockFormset( prefix='tariffs_block_form', ) tariffs_seo_form = forms.SEOForm( instance=tariffs.seo, prefix='tariffs_seo_form', ) context = { 'alerts': alerts, 'tariffs_form': tariffs_form, 'tariffs_block_formset': tariffs_block_formset, 'tariffs_seo_form': tariffs_seo_form, } return render(request, 'admin/website/tariffs.html', context)
def website_main_page_view(request): alerts = [] MainPageBlockFormset = modelformset_factory( model=models.WebsiteMainPageBlocks, form=forms.WebsiteMainPageBlocksForm, max_num=6, min_num=6) if request.method == 'POST': main_page_form = forms.WebsiteMainPageForm( request.POST, request.FILES, prefix='main_page_form', ) main_page_block_formset = MainPageBlockFormset( request.POST, request.FILES, prefix='main_page_block_form', ) main_page_seo_form = forms.SEOForm( request.POST, prefix='main_page_seo_form', ) if utils.forms_save([ main_page_form, main_page_seo_form, main_page_block_formset, ]): alerts.append('Данные сохранены успешно!') else: main_page: models.WebsiteMainPage = models.WebsiteMainPage.get_solo() if not main_page.seo: main_page.seo = models.SEO.objects.create() main_page.save() main_page_form = forms.WebsiteMainPageForm( instance=main_page, prefix='main_page_form', ) main_page_block_formset = MainPageBlockFormset( prefix='main_page_block_form', ) main_page_seo_form = forms.SEOForm( instance=main_page.seo, prefix='main_page_seo_form', ) context = { 'alerts': alerts, 'main_page_form': main_page_form, 'main_page_block_formset': main_page_block_formset, 'main_page_seo_form': main_page_seo_form, } return render(request, 'admin/website/main-page.html', context)
def tariffs_change_view(request, pk): alerts = [] # Форма тарифа # Формсет услуги if request.method == "POST": form = forms.RateForm(request.POST, prefix='tariffs') if utils.forms_save([ form, ]): alerts.append('Данные сохранены успешно!') else: form = forms.RateForm( instance=get_object_or_404(models.Rate, pk) if pk else None, prefix='tariffs', ) context = { 'form': form, 'alerts': alerts, } return render(request, 'admin/tariffs/change.html', context)