def ensure_gdpr_privacy_policy(shop, force_update=False): from shuup.simple_cms.models import Page, PageType gdpr_document = Page.objects.filter(shop=shop, page_type=PageType.REVISIONED).first() if force_update or not gdpr_document: now_date = now() company_name = (shop.public_name or shop.name) address = shop.contact_address full_address = "" if address: full_address = ", ".join([ item for item in [ company_name, address.street, address.city, address. region_code, address.postal_code, address.country.code ] if item ]) context = { "last_updated": format_datetime(now(), "LLLL dd, YYYY").capitalize(), "company_name": company_name, "full_address": full_address, "store_email": address.email if address else "" } content = loader.render_to_string( template_name="shuup/admin/gdpr/privacy_policy_page.jinja", context=context) created = False if not gdpr_document: with create_revision(): gdpr_document = Page.objects.create( shop=shop, page_type=PageType.REVISIONED, content=content, available_from=now_date, title=force_text(_("Privacy Policy")), url=force_text(_("privacy-policy"))) created = True # update only if it was created if created or force_update: current_language = get_language() for code, language in settings.LANGUAGES: if code == current_language: continue activate(code) content = loader.render_to_string( template_name="shuup/admin/gdpr/privacy_policy_page.jinja", context=context) gdpr_document.set_current_language(code) gdpr_document.title = force_text(_("Privacy Policy")) gdpr_document.url = force_text(_("privacy-policy")) gdpr_document.content = content gdpr_document.save() activate(current_language) return gdpr_document
def create_initial_privacy_policy_page(shop): from shuup.simple_cms.models import Page, PageType gdpr_document = Page.objects.filter( shop=shop, page_type=PageType.GDPR_CONSENT_DOCUMENT).first() if not gdpr_document: now_date = now() company_name = (shop.public_name or shop.name) address = shop.contact_address full_address = "" if address: full_address = ", ".join([ item for item in [ company_name, address.street, address.city, address. region_code, address.postal_code, address.country.code ] if item ]) context = { "last_updated": format_datetime(now(), "LLLL dd, YYYY").capitalize(), "company_name": company_name, "full_address": full_address, "store_email": address.email if address else "" } content = loader.render_to_string( template_name="shuup/admin/gdpr/privacy_policy_page.jinja", context=context) gdpr_document = Page.objects.create( shop=shop, page_type=PageType.GDPR_CONSENT_DOCUMENT, content=content, available_from=now_date, title=_("Privacy Policy"), url=_("privacy-policy")) return gdpr_document
def ensure_gdpr_privacy_policy(shop, force_update=False): from shuup.gdpr.models import GDPRSettings from shuup.simple_cms.models import Page gdpr_document = get_privacy_policy_page(shop) current_language = get_language() if force_update or not gdpr_document: now_date = now() company_name = shop.public_name or shop.name address = shop.contact_address full_address = "" if address: full_address = ", ".join([ item for item in [ company_name, address.street, address.city, address.region_code, address.postal_code, address.country.code, ] if item ]) context = { "last_updated": format_datetime(now(), "LLLL dd, YYYY").capitalize(), "company_name": company_name, "full_address": full_address, "store_email": address.email if address else "", } content = loader.render_to_string( template_name="shuup/admin/gdpr/privacy_policy_page.jinja", context=context) created = False if not gdpr_document: with create_revision(): gdpr_document = Page.objects.create( shop=shop, content=content, available_from=now_date, title=force_text(_("Privacy Policy")), url=settings.GDPR_PRIVACY_POLICY_PAGE_URLS.get( current_language, "privacy-policy"), ) created = True gdpr_settings = GDPRSettings.get_for_shop(shop) gdpr_settings.privacy_policy_page = gdpr_document gdpr_settings.save() # update only if it was created if created or force_update: for code, language in settings.LANGUAGES: if code == current_language: continue url = settings.GDPR_PRIVACY_POLICY_PAGE_URLS.get(code) if not url: continue activate(code) content = loader.render_to_string( template_name="shuup/admin/gdpr/privacy_policy_page.jinja", context=context) gdpr_document.set_current_language(code) gdpr_document.title = force_text(_("Privacy Policy")) gdpr_document.url = url gdpr_document.content = content gdpr_document.save() # return to old language activate(current_language) gdpr_document.set_current_language(current_language) return gdpr_document