Пример #1
0
    def save_model(self, request, object, form, change):
        instance = form.save(commit=False)
        instance = update_perms_and_save(request, form, instance)

        if 'meta_title' in form.cleaned_data:
            if instance.meta:
                meta = instance.meta
            else:
                meta = MetaTags()
            
            meta.title = form.cleaned_data['meta_title']
            meta.description = form.cleaned_data['meta_description']
            meta.keywords = form.cleaned_data['meta_keywords']
            meta.canonical_url = form.cleaned_data['meta_canonical_url']
            meta.save()
            instance.meta = meta
        instance.save()

        # notifications
        if not request.user.profile.is_superuser:
            # send notification to administrators
            recipients = get_notice_recipients('module', 'pages', 'pagerecipients')
            notice_type = 'page_added'
            if change: notice_type = 'page_edited'
            if recipients:
                if notification:
                    extra_context = {
                        'object': instance,
                        'request': request,
                    }
                    notification.send_emails(recipients, notice_type, extra_context)

        return instance
Пример #2
0
    def save_model(self, request, object, form, change):
        instance = form.save(commit=False)
        instance = update_perms_and_save(request, form, instance)

        if instance.meta:
            meta = instance.meta
        else:
            meta = MetaTags()

        meta.title = form.cleaned_data["meta_title"]
        meta.description = form.cleaned_data["meta_description"]
        meta.keywords = form.cleaned_data["meta_keywords"]
        meta.canonical_url = form.cleaned_data["meta_canonical_url"]
        meta.save()
        instance.meta = meta
        instance.save()

        # notifications
        if not request.user.profile.is_superuser:
            # send notification to administrators
            recipients = get_notice_recipients("module", "pages", "pagerecipients")
            notice_type = "page_added"
            if change:
                notice_type = "page_edited"
            if recipients:
                if notification:
                    extra_context = {"object": instance, "request": request}
                    notification.send_emails(recipients, notice_type, extra_context)

        return instance