Exemple #1
0
    def edit(self, real_user, user, obj, key=None, value=None, **kwargs):

        self.real_user = real_user
        self.user = user
        self.object = obj
        self.params = kwargs

        # for the single field edit
        if key and value != None and key not in kwargs:
            kwargs[key] = value

        # There is no authorization check in here. This is effectively it.
        # If the user is not an admin, the admin fields are stripped out.
        editable_keys = set(real_user.is_admin() and
                            (self.fields + self.admin_fields) or self.fields)

        # is there anything we can edit?
        to_edit = [k for k in kwargs.keys() if k in editable_keys]
        if not to_edit:
            raise ClientException('Specify some parameters to edit, please.',
                                  code=INCOMPLETE)

        # we fill out the kwargs so we dont piss off the validator. hack. poo. Must have all
        # fields as the validator will too.
        for k in self.fields + self.admin_fields:
            if k not in kwargs or k not in editable_keys:
                kwargs[k] = None

        params = validate(self.validator, **kwargs)

        #this is for collecting errors.
        error = CompoundException('Editing issues!', code=FAIL)

        # only go through the keys that we got in the original call/request (to_edit)
        for k in to_edit:
            if k not in editable_keys: continue
            param = params[k]

            fn_name = 'edit_%s' % k
            if hasattr(self, fn_name):

                try:
                    results = getattr(self, fn_name)(real_user, user, obj, k,
                                                     param)
                except ClientException, e:
                    # if error from editing, we will package it up so as to
                    # return all errors at once
                    error.add(e)
            else:
                #this is an adroll exception cause it should bubble up to a WebApp email
                raise AppException('Cannot find %s edit function! :(' %
                                   fn_name,
                                   code=INCOMPLETE)
Exemple #2
0
    def edit(self, real_user, user, obj, key=None, value=None, **kwargs):

        self.real_user = real_user
        self.user = user
        self.object = obj
        self.params = kwargs

        # for the single field edit
        if key and value != None and key not in kwargs:
            kwargs[key] = value

        # There is no authorization check in here. This is effectively it.
        # If the user is not an admin, the admin fields are stripped out.
        editable_keys = set(real_user.is_admin() and (self.fields + self.admin_fields) or self.fields)

        # is there anything we can edit?
        to_edit = [k for k in kwargs.keys() if k in editable_keys]
        if not to_edit:
            raise ClientException("Specify some parameters to edit, please.", code=INCOMPLETE)

        # we fill out the kwargs so we dont piss off the validator. hack. poo. Must have all
        # fields as the validator will too.
        for k in self.fields + self.admin_fields:
            if k not in kwargs or k not in editable_keys:
                kwargs[k] = None

        params = validate(self.validator, **kwargs)

        # this is for collecting errors.
        error = CompoundException("Editing issues!", code=FAIL)

        # only go through the keys that we got in the original call/request (to_edit)
        for k in to_edit:
            if k not in editable_keys:
                continue
            param = params[k]

            fn_name = "edit_%s" % k
            if hasattr(self, fn_name):

                try:
                    results = getattr(self, fn_name)(real_user, user, obj, k, param)
                except ClientException, e:
                    # if error from editing, we will package it up so as to
                    # return all errors at once
                    error.add(e)
            else:
                # this is an adroll exception cause it should bubble up to a WebApp email
                raise AppException("Cannot find %s edit function! :(" % fn_name, code=INCOMPLETE)
Exemple #3
0
 def validate(self, validation_class, **kw):
     return validation.validate(validation_class, **kw)
Exemple #4
0
 def validate(self, validation_class, **kw):
     return validation.validate(validation_class, **kw)