Example #1
0
    def item_create(self, par, user):
        if not ModelPermit(self.ITEM, user).can_add():
            raise PermissionDenied, 'can not create %s' % model_to_name(
                self.ITEM)

        par = par or None
        work = self.ITEM.objects.create(par_id=par)
        return to_dict(work)
Example #2
0
    def dir_create(self, user, par=None):
        if not ModelPermit(self.DIR, user).can_add():
            raise PermissionDenied, 'not permit create %s' % model_to_name(
                self.DIR)

        if not par:
            i = self.DIR.objects.create()
        else:
            i = self.DIR.objects.create(par_id=par)
        return to_dict(i)
Example #3
0
 def item_del(self, rows, user):
     """ 删除 dir 和 item """
     for row in rows:
         inst = from_dict(row)
         if ModelPermit(inst, user).can_del():
             inst.delete()
         else:
             raise PermissionDenied, 'can not delete %s' % model_to_name(
                 inst)
     return {'status': 'success'}
Example #4
0
    def item_create(self, user, par=None):
        if not ModelPermit(self.model, user).can_add():
            raise PermissionDenied, 'not permit create %s' % model_to_name(
                self.model)

        par = from_dict(par, model=self.model)
        if not par or not par.pk:
            i = self.model.objects.create()
        else:
            i = self.model.objects.create(par=par)
        return to_dict(i)
Example #5
0
 def items_paste(self, rows, par, user):
     """粘贴 dir 和 item """
     if par:
         par_inst = self.DIR.objects.get(pk=par)
     else:
         par_inst = None
     for row in rows:
         inst = from_dict(row)
         if 'par' in ModelPermit(inst, user).changeable_fields():
             inst.par = par_inst
             inst.save()
         else:
             raise PermissionDenied, 'can not modify par of %s' % model_to_name(
                 inst)
     return {'status': 'success'}
Example #6
0
    def dir_data(self, par, user):
        par_permit = ModelPermit(self.DIR, user)
        if not par_permit.readable_fields():
            raise PermissionDenied, 'can not read %s' % model_to_name(self.DIR)
        DIR = self.DIR

        if self.ITEM:
            item_perm = ModelPermit(self.ITEM, user)
            if not item_perm.readable_fields():
                raise PermissionDenied, 'can not read %s' % model_to_name(
                    self.ITEM)

            ITEM = self.ITEM

        if par:
            query = DIR.objects.filter(par_id=par)
        else:
            query = DIR.objects.filter(par=None)
        rows = [to_dict(idx) for idx in query]

        parents = []
        if par:
            this_dir = DIR.objects.get(id=par)
            parents.append(this_dir)
            while this_dir.par:
                parents.append(this_dir.par)
                this_dir = this_dir.par
        parents.reverse()
        parents = [to_dict(idx) for idx in parents]
        items = []  # 如果有item_model,才会去查询item项
        if self.ITEM:
            if par:
                items = [
                    to_dict(item, include=item_perm.readable_fields())
                    for item in ITEM.objects.filter(par_id=par)
                ]
            else:
                items = [
                    to_dict(item, include=item_perm.readable_fields())
                    for item in ITEM.objects.filter(par=None)
                ]
        return {'dirs': rows, 'parents': parents, 'items': items}