Beispiel #1
0
  def testRewriteColspec(self):
    self.assertEqual('', csv_helpers.RewriteColspec(''))

    self.assertEqual('a B c', csv_helpers.RewriteColspec('a B c'))

    self.assertEqual('a Summary AllLabels B Opened OpenedTimestamp c',
                     csv_helpers.RewriteColspec('a summary B opened c'))

    self.assertEqual('Closed ClosedTimestamp Modified ModifiedTimestamp',
                     csv_helpers.RewriteColspec('Closed Modified'))

    self.assertEqual('OwnerModified OwnerModifiedTimestamp',
                     csv_helpers.RewriteColspec('OwnerModified'))
Beispiel #2
0
    def GatherPageData(self, mr):
        if not mr.auth.user_id:
            raise permissions.PermissionException(
                'Anonymous users are not allowed to download issue list CSV')

        xsrf.ValidateToken(mr.token, mr.auth.user_id,
                           '/p/%s%s.do' % (mr.project_name, urls.ISSUE_LIST))

        # Sets headers to allow the response to be downloaded.
        self.content_type = 'text/csv; charset=UTF-8'
        download_filename = '%s-issues.csv' % mr.project_name
        self.response.headers.add(
            'Content-Disposition',
            'attachment; filename=%s' % download_filename)
        self.response.headers.add('X-Content-Type-Options', 'nosniff')

        # Rewrite the colspec to add some extra columns that make the CSV
        # file more complete.
        with mr.profiler.Phase('finishing config work'):
            config = self.services.config.GetProjectConfig(
                mr.cnxn, mr.project_id)

        mr.ComputeColSpec(config)
        mr.col_spec = csv_helpers.RewriteColspec(mr.col_spec)
        page_data = issuelist.IssueList.GatherPageData(self, mr)
        return csv_helpers.ReformatRowsForCSV(mr, page_data,
                                              urls.ISSUE_LIST_CSV)
Beispiel #3
0
    def GatherPageData(self, mr):
        if not mr.auth.user_id:
            raise permissions.PermissionException(
                'Anonymous users are not allowed to download hotlist CSV')

        owner_id = mr.hotlist.owner_ids[0]  # only one owner allowed
        users_by_id = framework_views.MakeAllUserViews(mr.cnxn,
                                                       self.services.user,
                                                       [owner_id])
        owner = users_by_id[owner_id]

        # Try to validate XSRF by either user email or user ID.
        try:
            xsrf.ValidateToken(
                mr.token, mr.auth.user_id,
                '/u/%s/hotlists/%s.do' % (owner.email, mr.hotlist.name))
        except xsrf.TokenIncorrect:
            xsrf.ValidateToken(
                mr.token, mr.auth.user_id,
                '/u/%s/hotlists/%s.do' % (owner.user_id, mr.hotlist.name))

        # Sets headers to allow the response to be downloaded.
        self.content_type = 'text/csv; charset=UTF-8'
        download_filename = 'hotlist_%d-issues.csv' % mr.hotlist_id
        self.response.headers.add(
            'Content-Disposition',
            'attachment; filename=%s' % download_filename)
        self.response.headers.add('X-Content-Type-Options', 'nosniff')

        mr.ComputeColSpec(mr.hotlist)
        mr.col_spec = csv_helpers.RewriteColspec(mr.col_spec)
        page_data = hotlistissues.HotlistIssues.GatherPageData(self, mr)
        return csv_helpers.ReformatRowsForCSV(mr, page_data,
                                              '%d/csv' % mr.hotlist_id)
    def GatherPageData(self, mr):
        if not mr.auth.user_id:
            raise permissions.PermissionException(
                'Anonymous users are not allowed to download hotlist CSV')

        # Sets headers to allow the response to be downloaded.
        self.content_type = 'text/csv; charset=UTF-8'
        download_filename = 'hotlist_%d-issues.csv' % mr.hotlist_id
        self.response.headers.add(
            'Content-Disposition',
            'attachment; filename=%s' % download_filename)
        self.response.headers.add('X-Content-Type-Options', 'nosniff')

        mr.ComputeColSpec(mr.hotlist)
        mr.col_spec = csv_helpers.RewriteColspec(mr.col_spec)
        page_data = hotlistissues.HotlistIssues.GatherPageData(self, mr)
        return csv_helpers.ReformatRowsForCSV(mr, page_data,
                                              '%d/csv' % mr.hotlist_id)