Example #1
0
def block_group_items(group_pk):
    group = BlockGroup.objects.get(pk=group_pk)
    ls = []
    for x in group.blocks.all():
        dc = {'bounding': poly2dict(x.bounding)}
        ls.append(to_dict(x, filt_attr=dc))
    return ls
Example #2
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 #3
0
    def dir_data(self, root, par, user):
        """
        @root: 自定义
        @par: to_dict 对象
        
        return :{'parent':[],'items':[]}
        
        items 是 to_dict对象,为每个对象添加_type 属性,定义前段使用的显示
        """
        if '_class' not in root.keys():
            root = from_dict(root, model=self.model)
        else:
            root = from_dict(root)

        parents = []
        if not par.get('pk', None):
            items = [to_dict(x) for x in self.model.objects.filter(par=None)]
            par = root
        else:
            par = from_dict(par)
            items = [to_dict(x) for x in self.model.objects.filter(par=par)]

        crt_par = par
        while True:
            parents.append(crt_par)
            if root.pk == crt_par.pk:
                break
            crt_par = crt_par.par
            if not crt_par or not crt_par.pk or crt_par == root:
                break

        find = False
        for par in parents:
            if str(par.pk) == root.pk:
                find = True
            elif par.pk is None and root.pk is None:
                find = True

        if not find:
            parents.append(root)
        parents.reverse()

        return {
            'parents': [to_dict(x) for x in parents],
            'items': items,
        }
Example #4
0
 def get_row(self):
     # display = self._adapt_polygon_obj(self.instance.display)
     bounding = poly2dict(self.instance.bounding) #  self._adapt_polygon_obj(self.instance.bounding)
     dc={
         # 'display':display,
         'bounding':bounding
     }
     return to_dict(self.instance,filt_attr=dc)
Example #5
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 #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}
Example #7
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 #8
0
 def dict_row(self, inst):
     block_list=[]
     for block in inst.blocks.all():
         bounding = poly2dict(block.bounding)
         block_list.append(to_dict(block,filt_attr={'bounding':bounding}))
     old_selected= inst.dispatched.blocks #[x.pk for x in inst.dispatched.blocks.all()]
     dc={
         'blocks':block_list,
         'old_selected':old_selected,
         'last':inst.dispatched.last,
         'last_time':localstr( inst.dispatched.last_time)
     }
     return dc
Example #9
0
def print_page(request):
    regions = []
    for region in BlockGroup.objects.all():
        dc = {'belong': region.name, 'msg': []}

        if region.dispatched:
            dc['last_time'] = localstr(region.dispatched.last_time)
            try:
                lit_region = BlockPolygon.objects.get(
                    pk=region.dispatched.last)
                dc.update(to_dict(lit_region, exclude=['bounding']))
                # dc['belong'] = region.name
            except BlockPolygon.DoesNotExist:
                print('pk = %s not exist.' % region.dispatched.last)
                dc['msg'].append('派发区域可能被删除了,请确认后,重新生成派发区域!')

        regions.append(dc)

    return render(request,
                  'geoinfo/print_page.html',
                  context={'regions': regions})
Example #10
0
def get_rs_list():
    ls = [to_dict(x) for x in UiResource.objects.all()]
    return ls