Esempio n. 1
0
    def request(self, *args, **kw):
        """Return an :class:`ActionRequest <lino.core.requests.ActionRequest>`
        on this actor.

        """
        kw.update(actor=self)
        return ActionRequest(*args, **kw)
Esempio n. 2
0
 def get_status(self,**kw):
     kw = ActionRequest.get_status(self,**kw)
     bp = kw['base_params']
     if self.quick_search:
         bp[constants.URL_PARAM_FILTER] = self.quick_search
         
     if self.known_values:
         for k,v in self.known_values.items():
             if self.actor.known_values.get(k,None) != v:
                 bp[k] = v
     if self.master_instance is not None:
         if self.master is None:
             bp[constants.URL_PARAM_MASTER_PK] = self.master_instance
         else:
             bp[constants.URL_PARAM_MASTER_PK] = self.master_instance.pk
             if ContentType._meta.installed:
                 mt = ContentType.objects.get_for_model(self.master_instance.__class__).pk
                 bp[constants.URL_PARAM_MASTER_TYPE] = mt
     return kw
Esempio n. 3
0
                     if filterOption == 'contains':
                         kw[f.field.name + "__icontains"] = filterValue
                     elif filterOption == 'doesnotcontain':
                         exclude[f.field.name + "__icontains"] = filterValue
                     else:
                         print "unknown filterOption %r" % filterOption
     if len(exclude):
         kw.update(exclude=exclude)
         
 if settings.SITE.use_gridfilters:
     filter = rqdata.get(constants.URL_PARAM_GRIDFILTER,None)
     if filter is not None:
         filter = json.loads(filter)
         kw['gridfilters'] = [constants.dict2kw(flt) for flt in filter]
         
 kw = ActionRequest.parse_req(self,request,rqdata,**kw)
 #~ raise Exception("20120121 %s.parse_req(%s)" % (self,kw))
 
 #~ kw.update(self.report.known_values)
 #~ for fieldname, default in self.report.known_values.items():
     #~ v = request.REQUEST.get(fieldname,None)
     #~ if v is not None:
         #~ kw[fieldname] = v
         
 quick_search = rqdata.get(constants.URL_PARAM_FILTER,None)
 if quick_search:
     kw.update(quick_search=quick_search)
     
 sort = rqdata.get(constants.URL_PARAM_SORT,None)
 if sort:
     #~ self.sort_column = sort
Esempio n. 4
0
    def setup(self,
            quick_search=None,
            order_by=None,
            offset=None,limit=None,
            master=None,
            title=None,
            master_instance=None,
            master_id=None,
            #~ layout=None,
            filter=None,
            #~ create_rows=None,
            gridfilters=None,
            exclude=None,
            extra=None,
            **kw):
            
        #~ if self.actor.__name__ == 'PrintExpensesByBudget':
            #~ assert master_instance is not None
            
        self.quick_search = quick_search
        self.order_by = order_by
        
            
        #~ logger.info("20120519 %s.setup()",self)
        self.filter = filter
        self.gridfilters = gridfilters
        self.exclude = exclude or self.actor.exclude
        self.extra = extra

        if master is None:
            master = self.actor.master
            # master might still be None
        self.master = master
        
        if title is not None:
            self.title = title
            
        if master_id is not None:
            assert master_instance is None
            master_instance = self.master.objects.get(pk=master_id)
            
        #~ if master is not None:
            #~ if not isinstance(master_instance,master):
                #~ raise Exception("%r is not a %r" % (master_instance,master))
            
        self.master_instance = master_instance
        
        #~ AbstractTableRequest.setup(self,**kw)
        
        """
        Table.page_length is not a default value for ReportRequest.limit
        For example CSVReportRequest wants all rows.
        """
        self.page_length = self.actor.page_length
        
        #~ logger.info("20120121 %s.setup() done",self)
        
        #~ if self.actor.__name__ == 'PrintExpensesByBudget':
            #~ print '20130327 1 tables.py', kw.get('master_instance')
            
        ActionRequest.setup(self,**kw)
        
        #~ if self.actor.__name__ == 'PrintExpensesByBudget':
            #~ print '20130327 2 tables.py', self, self.master_instance
        
        """
        20120519 : outbox.MyOutbox had no phantom record when called from menu.
        When called by permalink it had. Because get_create_kw was called before 
        Actor.setup_request() which sets the master_instance.
        """
        self.actor.setup_request(self)
        
        self.create_kw = self.actor.get_create_kw(self.master_instance)
        
        if offset is not None:
            self.offset = offset
            
        if limit is not None:
            self.limit = limit
Esempio n. 5
0
    def parse_req(self, request, rqdata, **kw):
        #~ logger.info("20120723 %s.parse_req()",self.actor)
        #~ rh = self.ah
        master = kw.get('master', self.actor.master)
        if master is not None:
            """
            If `master` is `ContentType` or some abstract model, then
            """
            #~ if master is ContentType or master is models.Model:
            if master is ContentType or master._meta.abstract:
                mt = rqdata.get(constants.URL_PARAM_MASTER_TYPE)
                try:
                    master = kw['master'] = ContentType.objects.get(
                        pk=mt).model_class()
                except ContentType.DoesNotExist:
                    pass
                    # master is None

            if not 'master_instance' in kw:
                pk = rqdata.get(constants.URL_PARAM_MASTER_PK, None)
                #~ print '20100406a', self.actor,URL_PARAM_MASTER_PK,"=",pk
                #~ if pk in ('', '-99999'):
                if pk == '':
                    pk = None
                if pk is None:
                    kw['master_instance'] = None
                else:
                    try:
                        kw['master_instance'] = master.objects.get(pk=pk)
                    except ValueError:
                        raise Exception(
                            "Invalid primary key %r for %s",
                            pk, master.__name__)
                    except master.DoesNotExist:
                        # todo: ReportRequest should become a subclass of
                        # Dialog and this exception should call dlg.error()
                        raise Exception(
                            "%s : There's no %s with primary key %r" %
                            (self.actor, master.__name__, pk))
                # ~ print '20100212', self #, kw['master_instance']
        #~ print '20100406b', self.actor,kw

        if settings.SITE.use_filterRow:
            exclude = dict()
            for f in self.ah.store.fields:
                if f.field:
                    filterOption = rqdata.get(
                        'filter[%s_filterOption]' % f.field.name)
                    if filterOption == 'empty':
                        kw[f.field.name + "__isnull"] = True
                    elif filterOption == 'notempty':
                        kw[f.field.name + "__isnull"] = False
                    else:
                        filterValue = rqdata.get('filter[%s]' % f.field.name)
                        if filterValue:
                            if not filterOption:
                                filterOption = 'contains'
                            if filterOption == 'contains':
                                kw[f.field.name + "__icontains"] = filterValue
                            elif filterOption == 'doesnotcontain':
                                exclude[f.field.name +
                                        "__icontains"] = filterValue
                            else:
                                print "unknown filterOption %r" % filterOption
            if len(exclude):
                kw.update(exclude=exclude)

        if settings.SITE.use_gridfilters:
            filter = rqdata.get(constants.URL_PARAM_GRIDFILTER, None)
            if filter is not None:
                filter = json.loads(filter)
                kw['gridfilters'] = [constants.dict2kw(flt) for flt in filter]

        kw = ActionRequest.parse_req(self, request, rqdata, **kw)
        #~ raise Exception("20120121 %s.parse_req(%s)" % (self,kw))

        #~ kw.update(self.report.known_values)
        #~ for fieldname, default in self.report.known_values.items():
            #~ v = request.REQUEST.get(fieldname,None)
            #~ if v is not None:
                #~ kw[fieldname] = v

        quick_search = rqdata.get(constants.URL_PARAM_FILTER, None)
        if quick_search:
            kw.update(quick_search=quick_search)

        sort = rqdata.get(constants.URL_PARAM_SORT, None)
        if sort:
            #~ self.sort_column = sort
            sort_dir = rqdata.get(constants.URL_PARAM_SORTDIR, 'ASC')
            if sort_dir == 'DESC':
                sort = '-' + sort
                #~ self.sort_direction = 'DESC'
            kw.update(order_by=[sort])

        offset = rqdata.get(constants.URL_PARAM_START, None)
        if offset:
            kw.update(offset=int(offset))
        #~ limit = rqdata.get(constants.URL_PARAM_LIMIT,None)
        limit = rqdata.get(constants.URL_PARAM_LIMIT, self.actor.preview_limit)
        if limit:
            kw.update(limit=int(limit))

        return self.actor.parse_req(request, rqdata, **kw)