• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utils.update_perms_and_save函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tendenci.apps.perms.utils.update_perms_and_save函数的典型用法代码示例。如果您正苦于以下问题:Python update_perms_and_save函数的具体用法?Python update_perms_and_save怎么用?Python update_perms_and_save使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了update_perms_and_save函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: save_model

 def save_model(self, request, object, form, change):
     """
     update the permissions backend
     """
     print('enter save_model')
     instance = form.save(commit=False)
     update_perms_and_save(request, form, instance)  # Returns perms
     return instance
开发者ID:tendenci,项目名称:tendenci,代码行数:8,代码来源:admin.py


示例2: save_model

    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
开发者ID:ZHW123,项目名称:tendenci,代码行数:30,代码来源:admin.py


示例3: add

def add(request, form_class=LocationForm, template_name="locations/add.html"):
    if has_perm(request.user,'locations.add_location'):
        if request.method == "POST":
            form = form_class(request.POST, request.FILES, user=request.user)
            if form.is_valid():
                location = form.save(commit=False)

                # update all permissions and save the model
                location = update_perms_and_save(request, form, location)

                if 'photo_upload' in form.cleaned_data:
                    photo = form.cleaned_data['photo_upload']
                    if photo:
                        location.save(photo=photo)
                msg_string = 'Successfully added %s' % location
                messages.add_message(request, messages.SUCCESS, _(msg_string))

                return HttpResponseRedirect(reverse('location', args=[location.slug]))
        else:
            form = form_class(user=request.user)

        return render_to_resp(request=request, template_name=template_name,
            context={'form':form})
    else:
        raise Http403
开发者ID:tendenci,项目名称:tendenci,代码行数:25,代码来源:views.py


示例4: add

def add(request, form_class=FormForm, template_name="forms/add.html"):
    if not has_perm(request.user,'forms.add_form'):
        raise Http403

    PricingFormSet = inlineformset_factory(Form, Pricing, form=PricingForm, extra=2, can_delete=False)

    formset = PricingFormSet()
    if request.method == "POST":
        form = form_class(request.POST, user=request.user)
        if form.is_valid():
            form_instance = form.save(commit=False)
            # save form and associated pricings
            form_instance = update_perms_and_save(request, form, form_instance)
            formset = PricingFormSet(request.POST, instance=form_instance)
            if formset.is_valid():
                # update_perms_and_save does not appear to consider ManyToManyFields
                for method in form.cleaned_data['payment_methods']:
                    form_instance.payment_methods.add(method)

                formset.save()

                messages.add_message(request, messages.SUCCESS, _('Successfully added %(f)s' % {'f':form_instance}))
                return HttpResponseRedirect(reverse('form_field_update', args=[form_instance.pk]))
    else:
        form = form_class(user=request.user)

    return render_to_resp(request=request, template_name=template_name, context={
        'form':form,
        'formset': formset,
    })
开发者ID:tendenci,项目名称:tendenci,代码行数:30,代码来源:views.py


示例5: photoset_add

def photoset_add(request, form_class=PhotoSetAddForm, template_name="photos/photo-set/add.html"):
    """ Add a photo set """
    # if no permission; permission exception
    if not has_perm(request.user,'photos.add_photoset'):
        raise Http403

    if request.method == "POST":
        if request.POST["action"] == "add":

            form = form_class(request.POST, user=request.user)
            if form.is_valid():
                photo_set = form.save(commit=False)

                photo_set.author = request.user

                # update all permissions and save the model
                photo_set = update_perms_and_save(request, form, photo_set)
                checklist_update('add-album')

                messages.add_message(request, messages.SUCCESS, _('Successfully added photo set!'))
                return HttpResponseRedirect(reverse('photos_batch_add', kwargs={'photoset_id':photo_set.id}))
    else:
        form = form_class(user=request.user)

    return render_to_response(template_name, {
        "photoset_form": form,
    }, context_instance=RequestContext(request))
开发者ID:goetzk,项目名称:tendenci,代码行数:27,代码来源:views.py


示例6: edit

def edit(request, id, form_class=LocationForm, template_name="locations/edit.html"):
    location = get_object_or_404(Location, pk=id)

    if has_perm(request.user,'locations.change_location',location):
        if request.method == "POST":
            form = form_class(request.POST, request.FILES, instance=location, user=request.user)
            if form.is_valid():
                location = form.save(commit=False)

                # update all permissions and save the model
                location = update_perms_and_save(request, form, location)

                if 'photo_upload' in form.cleaned_data:
                    photo = form.cleaned_data['photo_upload']
                    if photo:
                        location.save(photo=photo)
                msg_string = 'Successfully updated %s' % location
                messages.add_message(request, messages.SUCCESS, _(msg_string))

                return HttpResponseRedirect(reverse('location', args=[location.slug]))
        else:
            form = form_class(instance=location, user=request.user)

        return render_to_response(template_name, {'location': location, 'form':form},
            context_instance=RequestContext(request))
    else:
        raise Http403
开发者ID:BIGGANI,项目名称:tendenci,代码行数:27,代码来源:views.py


示例7: edit

def edit(request, id, form_class=DirectoryForm, template_name="directories/edit.html"):
    directory = get_object_or_404(Directory, pk=id)

    if not has_perm(request.user,'directories.change_directory', directory):
        raise Http403

    form = form_class(request.POST or None, request.FILES or None,
                      instance=directory,
                      user=request.user)

    del form.fields['payment_method']
    if not request.user.profile.is_superuser:
        del form.fields['pricing']
        del form.fields['list_type']

    if request.method == "POST":
        if form.is_valid():
            directory = form.save(commit=False)

            if directory.logo:
                try:
                    directory.logo.file.seek(0)
                except IOError:
                    directory.logo = None
            # update all permissions and save the model
            directory = update_perms_and_save(request, form, directory)
            msg_string = 'Successfully updated %s' % directory
            messages.add_message(request, messages.SUCCESS, _(msg_string))

            return HttpResponseRedirect(reverse('directory', args=[directory.slug]))


    return render_to_response(template_name, {'directory': directory, 'form':form},
        context_instance=RequestContext(request))
开发者ID:RMUCapstone-MIS590,项目名称:tendenci,代码行数:34,代码来源:views.py


示例8: mark_as_paid

def mark_as_paid(request, id, template_name="invoices/mark-as-paid.html"):
    """
    Makes a payment-record with a specified date/time
    payment method and payment amount.
    """
    invoice = get_object_or_404(Invoice, pk=id)

    if not has_perm(request.user, "payments.change_payment"):
        raise Http403

    if request.method == "POST":
        form = MarkAsPaidForm(request.POST)

        if form.is_valid():

            # make payment record
            payment = form.save(user=request.user, invoice=invoice, commit=False)

            payment = update_perms_and_save(request, form, payment)

            # update invoice; make accounting entries
            action_taken = invoice.make_payment(payment.creator, payment.amount)
            if action_taken:
                EventLog.objects.log(instance=invoice)
                messages.add_message(request, messages.SUCCESS, _("Payment successfully made"))

            return redirect(invoice)

    else:
        form = MarkAsPaidForm(initial={"amount": invoice.balance, "submit_dt": datetime.now()})

    return render_to_response(
        template_name, {"invoice": invoice, "form": form}, context_instance=RequestContext(request)
    )
开发者ID:ZHW123,项目名称:tendenci,代码行数:34,代码来源:views.py


示例9: edit

def edit(request, id=None, form_class=HelpFileForm, template_name="help_files/edit.html"):
    help_file = get_object_or_404(HelpFile, pk=id)
    if has_perm(request.user,'help_files.change_helpfile', help_file):
        if request.method == "POST":
            form = form_class(request.POST, instance=help_file, user=request.user)
            if form.is_valid():
                help_file = form.save(commit=False)

                # add all permissions and save the model
                help_file = update_perms_and_save(request, form, help_file)
                form.save_m2m()
                msg_string = 'Successfully edited %s' % help_file
                messages.add_message(request, messages.SUCCESS, _(msg_string))

                # send notification to administrator(s) and module recipient(s)
                recipients = get_notice_recipients('module', 'help_files', 'helpfilerecipients')
                # if recipients and notification:
#                     notification.send_emails(recipients,'help_file_added', {
#                         'object': help_file,
#                         'request': request,
#                     })

                return HttpResponseRedirect(reverse('help_file.details', args=[help_file.slug]))
        else:
            form = form_class(instance=help_file, user=request.user)

        return render_to_response(template_name, {'help_file': help_file, 'form':form},
            context_instance=RequestContext(request))
    else:
        raise Http403
开发者ID:goetzk,项目名称:tendenci,代码行数:30,代码来源:views.py


示例10: edit

def edit(request, id, form_class=ArticleForm,
         category_form_class=CategoryForm,
         template_name="articles/edit.html"):
    article = get_object_or_404(Article, pk=id)
    content_type = get_object_or_404(ContentType, app_label='articles',
                                     model='article')

    if has_perm(request.user, 'articles.change_article', article):
        if request.method == "POST":
            form = form_class(request.POST, request.FILES or None, instance=article, user=request.user)
            categoryform = category_form_class(content_type,
                                           request.POST,)

            if form.is_valid() and categoryform.is_valid():
                article = form.save()
                article.update_category_subcategory(
                                    categoryform.cleaned_data['category'],
                                    categoryform.cleaned_data['sub_category']
                                    )

                # update all permissions and save the model
                update_perms_and_save(request, form, article)
                msg_string = 'Successfully updated %s' % str(article)
                messages.add_message(request, messages.SUCCESS, _(msg_string))

                return HttpResponseRedirect(reverse('article', args=[article.slug]))
        else:
            form = form_class(instance=article, user=request.user)
            category = Category.objects.get_for_object(article, 'category')
            sub_category = Category.objects.get_for_object(article, 'sub_category')

            initial_category_form_data = {
                'app_label': 'articles',
                'model': 'article',
                'pk': article.pk,
                'category': getattr(category, 'name', '0'),
                'sub_category': getattr(sub_category, 'name', '0')
            }
            categoryform = category_form_class(content_type,
                                           initial=initial_category_form_data,)

        return render_to_resp(request=request, template_name=template_name,
            context={'article': article,
                     'form': form,
                     'categoryform': categoryform,})
    else:
        raise Http403
开发者ID:tendenci,项目名称:tendenci,代码行数:47,代码来源:views.py


示例11: add

def add(request, form_class=FileForm,template_name="files/add.html"):
    # check permission
    if not has_perm(request.user, 'files.add_file'):
        raise Http403

    if request.method == "POST":
        form = form_class(request.POST, request.FILES, user=request.user)
        if form.is_valid():
            file = form.save(commit=False)

            # set up the user information
            file.creator = request.user
            file.creator_username = request.user.username
            file.owner = request.user
            file.owner_username = request.user.username
            file.save()

            # update all permissions and save the model
            file = update_perms_and_save(request, form, file)

            #setup categories
            category = Category.objects.get_for_object(file, 'category')
            sub_category = Category.objects.get_for_object(file, 'sub_category')

            ## update the category of the file
            category_removed = False
            category = file.file_cat.name if file.file_cat else u''
            if category:
                Category.objects.update(file, category, 'category')
            else:  # remove
                category_removed = True
                Category.objects.remove(file, 'category')
                Category.objects.remove(file, 'sub_category')

            if not category_removed:
                # update the sub category of the article
                sub_category = file.file_sub_cat.name if file.file_sub_cat else u''
                if sub_category:
                    Category.objects.update(file, sub_category, 'sub_category')
                else:  # remove
                    Category.objects.remove(file, 'sub_category')

            #Save relationships
            file.save()

            # assign creator permissions
            ObjectPermission.objects.assign(file.creator, file)

            return HttpResponseRedirect(reverse('file.search'))
    else:
        form = form_class(user=request.user)
        if 'group' in form.fields:
            form.fields['group'].initial = Group.objects.get_initial_group_id()

    return render_to_response(
        template_name, {
            'form': form,
        }, context_instance=RequestContext(request))
开发者ID:BIGGANI,项目名称:tendenci,代码行数:58,代码来源:views.py


示例12: save

    def save(self, *args, **kwargs):
        data = self.cleaned_data
        counter = 0

        files = data.get('files')
        tags = data.get('tags')
        group = data.get('group')
        file_cat = data.get('file_cat', None)
        file_sub_cat = data.get('file_sub_cat', None)
        is_public = data.get('allow_anonymous_view', False)

        for new_file in files:
            file = File(
                file=new_file,
                tags=tags,
                group=group,
                allow_anonymous_view=is_public,
                file_cat=file_cat,
                file_sub_cat=file_sub_cat)

            file.save()

            # update all permissions and save the model
            file = update_perms_and_save(self.request, self, file)

            #setup categories
            category = Category.objects.get_for_object(file, 'category')
            sub_category = Category.objects.get_for_object(file, 'sub_category')

            ## update the category of the file
            category_removed = False
            category = file.file_cat.name if file.file_cat else u''

            if category:
                Category.objects.update(file, category, 'category')
            else:  # remove
                category_removed = True
                Category.objects.remove(file, 'category')
                Category.objects.remove(file, 'sub_category')

            if not category_removed:
                # update the sub category of the file
                sub_category = file.file_sub_cat.name if file.file_sub_cat else u''
                if sub_category:
                    Category.objects.update(file, sub_category, 'sub_category')
                else:  # remove
                    Category.objects.remove(file, 'sub_category')

            #Save relationships
            file.save()
            counter += 1

        return counter
开发者ID:tendenci,项目名称:tendenci,代码行数:53,代码来源:forms.py


示例13: save

    def save(self, *args, **kwargs):
        request = kwargs.get('request')
        if request:
            del kwargs['request']
        report = super(ReportForm, self).save(*args, **kwargs)

        if request:
            update_perms_and_save(request, self, report)

        config_dict = {}
        if self.cleaned_data['type'] == "invoices":
            for k, v in self.cleaned_data.items():
                if "invoice" in k:
                    config_dict.update({k: v})

        config_json = json.dumps(config_dict, cls=DjangoJSONEncoder)
        report.config = config_json
        report.allow_anonymous_view = False
        report.save()

        return report
开发者ID:BIGGANI,项目名称:tendenci,代码行数:21,代码来源:forms.py


示例14: add

def add(request, form_class=ResumeForm, template_name="resumes/add.html"):
    can_add_active = has_perm(request.user, 'resumes.add_resume')
    
    if not any([request.user.profile.is_superuser,
               can_add_active,
               get_setting('module', 'resumes', 'usercanadd'),
               (request.user.profile.is_member and get_setting('module', 'resumes', 'userresumesrequiresmembership'))
               ]):
        raise Http403

    if request.method == "POST":
        form = form_class(request.POST or None, user=request.user)
        if form.is_valid():
            resume = form.save(commit=False)

            # set it to pending if the user does not have add permission
            if not can_add_active:
                resume.status_detail = 'pending'

            # set up the expiration time based on requested duration
            now = datetime.now()
            resume.expiration_dt = now + timedelta(days=resume.requested_duration)

            resume = update_perms_and_save(request, form, resume)
            # we need to save instance first since we need the id for the file path
            if request.FILES:
                resume.resume_file = request.FILES['resume_file']
                resume.resume_file.file.seek(0)
                resume.save()

            EventLog.objects.log(instance=resume)

            if request.user.is_authenticated():
                messages.add_message(request, messages.SUCCESS, _('Successfully added %(r)s' % {'r':resume}))

            # send notification to administrators
            recipients = get_notice_recipients('module', 'resumes', 'resumerecipients')
            if recipients:
                if notification:
                    extra_context = {
                        'object': resume,
                        'request': request,
                    }
                    notification.send_emails(recipients,'resume_added', extra_context)

            if not request.user.is_authenticated():
                return HttpResponseRedirect(reverse('resume.thank_you'))
            else:
                return HttpResponseRedirect(reverse('resume', args=[resume.slug]))
    else:
        form = form_class(user=request.user)
    return render_to_response(template_name, {'form':form},
        context_instance=RequestContext(request))
开发者ID:goetzk,项目名称:tendenci,代码行数:53,代码来源:views.py


示例15: save_model

    def save_model(self, request, object, form, change):
        instance = form.save(request=request, commit=False)
        instance = update_perms_and_save(request, form, instance, log=False)

        log_defaults = {
            'instance': object,
            'action': "edit"
        }
        if not change:
            log_defaults['action'] = "add"

        EventLog.objects.log(**log_defaults)
        return instance
开发者ID:BIGGANI,项目名称:tendenci,代码行数:13,代码来源:admin.py


示例16: save_model

    def save_model(self, request, object, form, change):
        """
        Update the permissions backend and log the event
        """
        instance = form.save(commit=False)
        instance = update_perms_and_save(request, form, instance)
        log_defaults = {
            'instance': object,
            'action': "edit"
        }
        if not change:
            log_defaults['action'] = "add"

        EventLog.objects.log(**log_defaults)
        return instance
开发者ID:goetzk,项目名称:tendenci,代码行数:15,代码来源:admin.py


示例17: save_model

    def save_model(self, request, object, form, change):
        """
        Update the permissions backend and log the event
        """
        instance = form.save(commit=False)
        instance = update_perms_and_save(request, form, instance, log=False)
        log_defaults = {
            'instance': object,
            'action': "edit"
        }
        if not change:
            log_defaults['action'] = "add"

        # Handle a special case for bulk reordering via the list view.
        if form.changed_data != ['ordering']:
            EventLog.objects.log(**log_defaults)
        return instance
开发者ID:RMUCapstone-MIS590,项目名称:tendenci,代码行数:17,代码来源:admin.py


示例18: save_model

    def save_model(self, request, object, form, change):
        testimonial = form.save(commit=False)

        # save photo
        if 'photo_upload' in form.cleaned_data:
            photo = form.cleaned_data['photo_upload']
            if photo:
                testimonial.save(photo=photo)

        testimonial = update_perms_and_save(request, form, testimonial)

        log_defaults = {
            'instance': object,
            'action': "edit"
        }
        if not change:
            log_defaults['action'] = "add"
            EventLog.objects.log(**log_defaults)

        return object
开发者ID:tendenci,项目名称:tendenci-testimonials,代码行数:20,代码来源:admin.py


示例19: edit

def edit(request, id, form_class=FormForm, template_name="forms/edit.html"):
    form_instance = get_object_or_404(Form, pk=id)

    if not has_perm(request.user,'forms.change_form',form_instance):
        raise Http403

    PricingFormSet = inlineformset_factory(Form, Pricing, form=PricingForm, extra=2)
    RecurringPaymentFormSet = inlineformset_factory(Form, RecurringPayment, form=RecurringPaymentForm, extra=2)

    if request.method == "POST":
        form = form_class(request.POST, instance=form_instance, user=request.user)
        if form_instance.recurring_payment:
            formset = RecurringPaymentFormSet(request.POST, instance=form_instance)
        else:
            formset = PricingFormSet(request.POST, instance=form_instance)
        if form.is_valid() and formset.is_valid():
            form_instance = form.save(commit=False)
            form_instance = update_perms_and_save(request, form, form_instance)

            form.save_m2m()  # save payment methods
            formset.save()  # save price options

            # remove all pricings if no custom_payment form
            if not form.cleaned_data['custom_payment']:
                form_instance.pricing_set.all().delete()

            messages.add_message(request, messages.SUCCESS, _('Successfully edited %(f)s' % {'f': form_instance}))
            return HttpResponseRedirect(reverse('form_field_update', args=[form_instance.pk]))
    else:
        form = form_class(instance=form_instance, user=request.user)
        if form_instance.recurring_payment:
            formset = RecurringPaymentFormSet(instance=form_instance)
        else:
            formset = PricingFormSet(instance=form_instance)
    return render_to_resp(request=request, template_name=template_name,context={
        'form':form,
        'formset':formset,
        'form_instance':form_instance,
        })
开发者ID:tendenci,项目名称:tendenci,代码行数:39,代码来源:views.py



注:本文中的tendenci.apps.perms.utils.update_perms_and_save函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python site.register函数代码示例发布时间:2022-05-27
下一篇:
Python utils.has_view_perm函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap