예제 #1
0
 def getBatchForm(self, objects, request):
     """Create batch based on objects no sorting for filter applied.
     """
     batchSize = request.get('batchSize',self.defaultBatchSize)
     if batchSize in ['', '0']:
         batchSize = 0
     else:
         batchSize = int(batchSize)
     start = int(request.get('start',0))
     resetStart = int(request.get('resetStart',0))
     lastindex = request.get('lastindex',0)
     navbutton = request.get('navbutton',None)
     if navbutton == "first" or resetStart:
         start = 0
     elif navbutton == "last":
         start=lastindex
     elif navbutton == "next":
         start = start + batchSize
         if start > lastindex: start = lastindex
     elif navbutton == "prev":
         start = start - batchSize
     elif request.has_key("nextstart"):
         start = request.nextstart
     if 0 < start > len(objects): start = 0
     request.start = start
     objects = ZTUtils.Batch(objects, batchSize or len(objects),
                 start=request.start, orphan=0)
     return objects
예제 #2
0
 def getBatch(self, tableName, objects, **keys):
     """Filter, sort and batch objects and pass return set.
     """
     if log.isEnabledFor(logging.DEBUG):
         import os
         fmt = 'getBatch pid={0}, tableName={1}, {2} objects'
         pid = os.getpid()
         log.debug(fmt.format(pid, tableName, len(objects)))
     if not objects:
         objects = []
     tableState = self.setupTableState(tableName, **keys)
     if tableState.onlyMonitored and objects:
         objects = [o for o in objects if getattr(o, 'isMonitored', o.monitored)()]
     if tableState.filter and objects:
         objects = self.filterObjects(objects, tableState.filter,
                                     tableState.filterFields)
     # objects is frequently a generator.  Need a list in order to sort
     if not isinstance(objects, list):
         objects = list(objects)
     if tableState.sortedHeader:
         objects = self.sortObjects(objects, tableState)
     tableState.totalobjs = len(objects)
     tableState.buildPageNavigation(objects)
     if not hasattr(self.REQUEST, 'doExport'):
         objects = ZTUtils.Batch(objects,
                     tableState.batchSize or len(objects),
                     start=tableState.start, orphan=0)
     return objects
예제 #3
0
    def delete_items(self, sources, fields=None):
        if self.request.environ['REQUEST_METHOD'] != 'POST':
            # Only non-javascript clients should see this.
            # Send them to a form they can POST from.
            # We can't just call & return the form; octopus hijacks the output.
            url = '%s/delete-form/?%s' % (self.context.absolute_url(),
                                          ZTUtils.make_query(sources=sources))
            self.request.response.redirect(url)
            return None
            
        item_type = self.request.form.get("item_type")

        if item_type == 'pages' and PROJ_HOME in sources:
            sources.remove("project-home")

        ids = [x.split("/")[-1] for x in sources]
        brains = self.catalog(id=ids, path=self.project_path)

        deletions, survivors = self._delete(brains, sources)
        # for now we'll only return the deleted obj ids. later we may return the survivors too.
        commands = {}
        for obj_id in deletions:
            commands[obj_id] = {
                'action': 'delete'
                }
        return commands
예제 #4
0
 def getCSVQuery(self):
     info = self.context.restrictedTraverse(
         '@@sort_info').getSortInfo()
     kw = {'Content-Type': 'text/csv'}
     if info['selected']:
         kw[info['selected']['id']] = True
     return ZTUtils.make_query(info['form'], kw)
예제 #5
0
    def jsfactory(self):
        context_url = self.context.absolute_url()
        if not context_url.endswith('/'):
            context_url += '/'

        query, show = build_query(self.context, self.request)
        query_string = ZTUtils.make_query(query)
        #return ''
        return u"""
        function() {
                return new OpenLayers.Layer.Vector("%s", {
                    protocol: new OpenLayers.Protocol.HTTP({
                      url: "%s@@geometry_search.kml?%s",
                      format: new OpenLayers.Format.KML({
                        extractStyles: true,
                        extractAttributes: true})
                      }),
                    strategies: [new OpenLayers.Strategy.Fixed()],
                    visibility: true,
                    projection: cgmap.createDefaultOptions().displayProjection
                  });
                } """ % (self.context.Title().replace("'", "&apos;"),
                        context_url, query_string)