Exemple #1
0
def tg_absolute_url(tgpath='/', params=None, **kw):
    """Return absolute URL (including schema and host to this server).

    Tries to account for 'Host' header and reverse proxying
    ('X-Forwarded-Host').

    The host name is determined this way:

    * If the config setting 'tg.url_domain' is set and non-null, use this value.
    * Else, if the 'base_url_filter.use_x_forwarded_host' config setting is
      True, use the value from the 'Host' or 'X-Forwarded-Host' request header.
    * Else, if config setting 'base_url_filter.on' is True and
      'base_url_filter.base_url' is non-null, use its value for the host AND
      scheme part of the URL.
    * As a last fallback, use the value of 'server.socket_host' and
      'server.socket_port' config settings (defaults to 'localhost:8080').

    The URL scheme ('http' or 'http') used is determined in the following way:

    * If 'base_url_filter.base_url' is used, use the scheme from this URL.
    * If there is a 'X-Use-SSL' request header, use 'https'.
    * Else, if the config setting 'tg.url_scheme' is set, use its value.
    * Else, use the value of 'cherrypy.request.scheme'.

    """
    get = config.get
    use_xfh = get('base_url_filter.use_x_forwarded_host', False)
    if request.headers.get('X-Use-SSL'):
        scheme = 'https'
    else:
        scheme = get('tg.url_scheme')
    if not scheme:
        scheme = request.scheme
    base_url = '%s://%s' % (scheme, get_server_name())
    if get('base_url_filter.on', False) and not use_xfh:
        base_url = get('base_url_filter.base_url').rstrip('/')
    return '%s%s' % (base_url, tg_url(tgpath, params, **kw))
Exemple #2
0
    def id(self, collection_id):  #pylint:disable-msg=C0103
        '''Return a page with information on a particular Collection

        :arg collection_id: Numeric id of the collection
        '''
        flash(
            _('This page is deprecated.  Use %(url)s instead.') % {
                'url':
                config.get('base_url_filter.base_url', 'http://localhost') +
                tg_url('/collection/name')
            })
        try:
            collection_id = int(collection_id)
        except ValueError:
            error = dict(status = False,
                    title = _('%(app)s -- Invalid Collection Id') %
                        {'app': self.app_title},
                    message =_('The collection_id you were linked to is not a' \
                            ' valid id.  If you received this error from a' \
                            ' link on the fedoraproject.org website, please' \
                            ' report it.'))
            if request.params.get('tg_format', 'html') != 'json':
                error['tg_template'] = 'pkgdb.templates.errors'
            return error

        ### FIXME: Want to return additional info:
        # date it was created (join log table: creation date)
        # The initial import doesn't have this information, though.
        try:
            #pylint:disable-msg=E1101
            collection_entry = Collection.query.options(
                    lazyload('listings2'), eagerload('status.locale'))\
                    .filter_by(id=collection_id).one()
        except InvalidRequestError:
            # Either the id doesn't exist or somehow it references more than
            # one value
            error = dict(
                status=False,
                title=_('%(app)s -- Invalid Collection Id') %
                {'app': self.app_title},
                message=_('The collection_id you were linked to, %(id)s,'
                          ' does not exist.  If you received this error from'
                          ' a link on the fedoraproject.org website, please'
                          ' report it.') % {'id': collection_id})
            if request.params.get('tg_format', 'html') != 'json':
                error['tg_template'] = 'pkgdb.templates.errors'
            return error

        # Why do we reformat the data returned from the database?
        # 1) We don't need all the information in the collection object
        # 2) We need statusname which is not in the specific table.
        collection = {
            'name': collection_entry.name,
            'version': collection_entry.version,
            'owner': collection_entry.owner,
            'summary': collection_entry.summary,
            'description': collection_entry.description,
            'statusname': collection_entry.status.locale['C'].statusname
        }

        # Retrieve the packagelist for this collection
        # pylint:disable-msg=E1101
        packages = Package.query.options(lazyload('listings2.people2'),
                lazyload('listings2.groups2')).join('listings2')\
                        .filter_by(collectionid=collection_id)\
                        .filter(Package.statuscode!=STATUS['Removed'])
        # pylint:enable-msg=E1101

        return dict(
            title='%s -- %s %s' %
            (self.app_title, collection['name'], collection['version']),
            collection=collection,
            packages=packages)
Exemple #3
0
def url(*args, **kw):
    if config.get('identity.provider') in ('sqlobjectcsrf', 'jsonfas2'):
        return csrf_url(*args, **kw)
    else:
        return tg_url(*args, **kw)
    def id(self, collection_id): #pylint:disable-msg=C0103
        '''Return a page with information on a particular Collection

        :arg collection_id: Numeric id of the collection
        '''
        flash(_('This page is deprecated.  Use %(url)s instead.') %
                {'url': config.get('base_url_filter.base_url',
                    'http://localhost') + tg_url('/collection/name')})
        try:
            collection_id = int(collection_id)
        except ValueError:
            error = dict(status = False,
                    title = _('%(app)s -- Invalid Collection Id') %
                        {'app': self.app_title},
                    message =_('The collection_id you were linked to is not a' \
                            ' valid id.  If you received this error from a' \
                            ' link on the fedoraproject.org website, please' \
                            ' report it.'))
            if request.params.get('tg_format', 'html') != 'json':
                error['tg_template'] = 'pkgdb.templates.errors'
            return error

        ### FIXME: Want to return additional info:
        # date it was created (join log table: creation date)
        # The initial import doesn't have this information, though.
        try:
            #pylint:disable-msg=E1101
            collection_entry = Collection.query.options(
                    lazyload('listings2'), eagerload('status.locale'))\
                    .filter_by(id=collection_id).one()
        except InvalidRequestError:
            # Either the id doesn't exist or somehow it references more than
            # one value
            error = dict(status = False,
                    title = _('%(app)s -- Invalid Collection Id') %
                            {'app': self.app_title},
                    message = _('The collection_id you were linked to, %(id)s,'
                            ' does not exist.  If you received this error from'
                            ' a link on the fedoraproject.org website, please'
                            ' report it.') % {'id': collection_id})
            if request.params.get('tg_format', 'html') != 'json':
                error['tg_template'] = 'pkgdb.templates.errors'
            return error

        # Why do we reformat the data returned from the database?
        # 1) We don't need all the information in the collection object
        # 2) We need statusname which is not in the specific table.
        collection = {'name': collection_entry.name,
                'version': collection_entry.version,
                'owner': collection_entry.owner,
                'summary': collection_entry.summary,
                'description': collection_entry.description,
                'statusname': collection_entry.status.locale['C'].statusname
                }

        # Retrieve the packagelist for this collection
        # pylint:disable-msg=E1101
        packages = Package.query.options(lazyload('listings2.people2'),
                lazyload('listings2.groups2')).join('listings2')\
                        .filter_by(collectionid=collection_id)\
                        .filter(Package.statuscode!=STATUS['Removed'])
        # pylint:enable-msg=E1101

        return dict(title='%s -- %s %s' % (self.app_title, collection['name'],
            collection['version']), collection=collection, packages=packages)
Exemple #5
0
def url(*args, **kw):
    if config.get('identity.provider') in ('sqlobjectcsrf', 'jsonfas2'):
        return csrf_url(*args, **kw)
    else:
        return tg_url(*args, **kw)