Example #1
0
        def func(templateArguments):
            argList = list()
            instanceList = self.application.twitter_instances.getInstanceList()

            # todo remove this, this generates more instances for debugging.
            # if len(instanceList) > 0:
            #    count = 0
            #    while count < 7:
            #        instanceList.append(instanceList[0])
            #        count += 1
            # todo end of remove this.

            numInstances = len(instanceList)

            numInstancesPerPage = Configuration.NUM_LANDING_PAGE_INSTANCES_PER_PAGE

            if numInstances > 3 or numInstances < 1:
                numInstancesPerRow = Configuration.NUM_LANDING_PAGE_INSTANCES_PER_ROW
            else:
                numInstancesPerRow = numInstances

            thumbnailSpan = 12 / numInstancesPerRow
            pageNum = parseInteger(request.GET.page, 0, numInstances, 0)
            startIndex = numInstancesPerPage * pageNum
            endIndex = startIndex + numInstancesPerPage
            numPages = int(
                ceil(float(numInstances) / float(numInstancesPerPage)))

            for instance in instanceList[startIndex:endIndex]:
                assert isinstance(instance, TwitterInstance)
                argList.append((LocationsMapPage.link_info.getPageLink(
                    instance.instance_key), instance.getShortDescription(True),
                                instance.geographic_setup_string))

            # Split into rows.
            argList = splitList(argList, numInstancesPerRow)
            templateArguments.update({'instances': argList})

            # Pagination
            startSmallPageIndex = pageNum - 5
            endSmallPageIndex = 0
            if startSmallPageIndex < 0:
                endSmallPageIndex -= startSmallPageIndex
                startSmallPageIndex = 0

            endSmallPageIndex += (pageNum + 5)
            offEndBy = endSmallPageIndex - numPages
            if offEndBy > 0:
                startSmallPageIndex -= offEndBy
                if startSmallPageIndex < 0:
                    startSmallPageIndex = 0

                endSmallPageIndex = numPages

            pagination = list()
            for n in range(startSmallPageIndex, endSmallPageIndex):
                isCurrentPage = pageNum == n
                pagination.append(
                    (n + 1, LandingPage.getLandingPageLink(n), isCurrentPage))

            step = (numPages - endSmallPageIndex) / 5
            if step > 0:
                for n in range(endSmallPageIndex, numPages, step):
                    pagination.append(
                        (n + 1, LandingPage.getLandingPageLink(n), False))

            if pageNum < numPages - 1:
                templateArguments.update({
                    'pagination_next':
                    LandingPage.getLandingPageLink(pageNum + 1)
                })

            if pageNum > 0:
                templateArguments.update({
                    'pagination_previous':
                    LandingPage.getLandingPageLink(pageNum - 1)
                })

            maxInactiveTime = Configuration.MAX_INSTANCE_INACTIVE_TIME_MS
            maxTotalTime = Configuration.MAX_INSTANCE_TOTAL_AGE_MS

            templateArguments.update({
                'pagination':
                pagination,
                'thumbnail_span':
                thumbnailSpan,
                'build_instance_link':
                OAuthSignIn.link_info.getPageLink(),
                'maxInactiveTime':
                self.getHumanTime(maxInactiveTime),
                'maxTotalTime':
                self.getHumanTime(maxTotalTime)
            })

            return template('landing-page.tpl', templateArguments)
def formatCoordsForTwitter(coords):
    return splitList(joinListOfLists(coords),2)
Example #3
0
        def func(templateArguments):
            argList = list()
            instanceList = self.application.twitter_instances.getInstanceList()

            # todo remove this, this generates more instances for debugging.
           # if len(instanceList) > 0:
            #    count = 0
            #    while count < 7:
            #        instanceList.append(instanceList[0])
            #        count += 1
            # todo end of remove this.

            numInstances = len(instanceList)

            numInstancesPerPage = Configuration.NUM_LANDING_PAGE_INSTANCES_PER_PAGE

            if numInstances > 3 or numInstances < 1:
                numInstancesPerRow = Configuration.NUM_LANDING_PAGE_INSTANCES_PER_ROW
            else:
                numInstancesPerRow = numInstances

            thumbnailSpan = 12 / numInstancesPerRow
            pageNum = parseInteger(request.GET.page,0,numInstances,0)
            startIndex = numInstancesPerPage * pageNum
            endIndex = startIndex + numInstancesPerPage
            numPages = int(ceil(float(numInstances) / float(numInstancesPerPage)))

            for instance in instanceList[startIndex:endIndex]:
                assert isinstance(instance, TwitterInstance)
                argList.append((LocationsMapPage.link_info.getPageLink(instance.instance_key),
                                instance.getShortDescription(True),
                                instance.geographic_setup_string))

            # Split into rows.
            argList = splitList(argList, numInstancesPerRow)
            templateArguments.update({'instances' : argList})

            # Pagination
            startSmallPageIndex = pageNum - 5
            endSmallPageIndex = 0
            if startSmallPageIndex < 0:
                endSmallPageIndex -= startSmallPageIndex
                startSmallPageIndex = 0

            endSmallPageIndex += (pageNum + 5)
            offEndBy = endSmallPageIndex - numPages
            if offEndBy > 0:
                startSmallPageIndex -= offEndBy
                if startSmallPageIndex < 0:
                    startSmallPageIndex = 0

                endSmallPageIndex = numPages

            pagination = list()
            for n in range(startSmallPageIndex, endSmallPageIndex):
                isCurrentPage = pageNum == n
                pagination.append((n+1,LandingPage.getLandingPageLink(n),isCurrentPage))

            step = (numPages - endSmallPageIndex) / 5
            if step > 0:
                for n in range(endSmallPageIndex,numPages,step):
                    pagination.append((n+1,LandingPage.getLandingPageLink(n),False))

            if pageNum < numPages - 1:
                templateArguments.update({'pagination_next' : LandingPage.getLandingPageLink(pageNum + 1)})

            if pageNum > 0:
                templateArguments.update({'pagination_previous' : LandingPage.getLandingPageLink(pageNum - 1)})

            maxInactiveTime = Configuration.MAX_INSTANCE_INACTIVE_TIME_MS
            maxTotalTime = Configuration.MAX_INSTANCE_TOTAL_AGE_MS

            templateArguments.update({'pagination' : pagination,
                                      'thumbnail_span' : thumbnailSpan,
                                      'build_instance_link' : OAuthSignIn.link_info.getPageLink(),
                                      'maxInactiveTime' : self.getHumanTime(maxInactiveTime),
                                      'maxTotalTime' : self.getHumanTime(maxTotalTime)})

            return template('landing-page.tpl',templateArguments)
def formatCoordsForTwitter(coords):
    return splitList(joinListOfLists(coords),2)