Exemplo n.º 1
0
    def full_document(self):
        """Get files texts and put it into document. Return document with
        files texts.
        """

        # NOTE: Get raw mapped entity object! By John Doe
        member = self.context.get_raw_member(self.request.matchdict['id'])

        if member is None:

            # NOTE: Tentar fechar a conexão de qualquer forma!
            # -> Na criação da conexão "coautocommit=True"!
            # By Questor
            try:
                if self.context.session.is_active:
                    self.context.session.close()
            except:
                pass

            raise HTTPNotFound()

        document = self.context.get_full_document(
            utils.json2object(member.document))
        self.context.session.close()

        # NOTE: Tentar fechar a conexão de qualquer forma!
        # -> Na criação da conexão "coautocommit=True"!
        # By Questor
        try:
            if self.context.session.is_active:
                self.context.session.close()
        except:
            pass

        return Response(utils.object2json(document),
                        content_type='application/json')
Exemplo n.º 2
0
    def render(data, system):
        request = system.get('request')
        if request is not None:
            response = request.response
            ct = response.content_type
            if ct == response.default_content_type:
                response.content_type = 'application/rss+xml'

        if 'updates' in data:
            key = 'updates'
        elif 'users' in data:
            key = 'users'
        elif 'comments' in data:
            key = 'comments'
        elif 'overrides' in data:
            key = 'overrides'
        else:
            raise HTTPNotFound("RSS not implemented for this service")

        feed = FeedGenerator()
        feed.title(key)
        feed.link(href=request.url, rel='self')
        feed.description(key)
        feed.language(u'en')

        def linker(route, param, key):
            def link_dict(obj):
                return dict(href=request.route_url(route, **{param: obj[key]}))

            return link_dict

        getters = {
            'updates': {
                'title': operator.itemgetter('title'),
                'link': linker('update', 'id', 'title'),
                'description': operator.itemgetter('notes'),
                'pubdate': lambda obj: utc.localize(obj['date_submitted']),
            },
            'users': {
                'title': operator.itemgetter('name'),
                'link': linker('user', 'name', 'name'),
                'description': operator.itemgetter('name'),
            },
            'comments': {
                'title': operator.itemgetter('text'),
                'link': linker('comment', 'id', 'id'),
                'description': operator.itemgetter('text'),
                'pubdate': lambda obj: utc.localize(obj['timestamp']),
            },
            'overrides': {
                'title': operator.itemgetter('nvr'),
                'link': linker('override', 'nvr', 'nvr'),
                'description': operator.itemgetter('notes'),
                'pubdate': lambda obj: utc.localize(obj['submission_date']),
            },
        }

        for value in data[key]:
            feed_item = feed.add_item()
            for name, getter in getters[key].items():
                # Because we have to use methods to fill feed entry attributes,
                # it's done by getting methods by name and calling them
                # on the same line
                getattr(feed_item, name)(getter(value))

        return feed.rss_str()
Exemplo n.º 3
0
 def not_found(self):
     """A view which is not found"""
     raise HTTPNotFound()
Exemplo n.º 4
0
 def render_to_404(self, value):
     # scrub value
     return HTTPNotFound(self.context)
Exemplo n.º 5
0
def notfound_view(request):
    """
    For when Pyramid is passed a url it can not route
    """
    return HTTPNotFound('The url could not be found.')
 def __init__(self, request: Request):
     raise HTTPNotFound("foo")
Exemplo n.º 7
0
 def delete(self):
     raise HTTPNotFound()
Exemplo n.º 8
0
 def put(self):
     raise HTTPNotFound()
Exemplo n.º 9
0
 def get(self):
     raise HTTPNotFound()
Exemplo n.º 10
0
 def post(self):
     raise HTTPNotFound()
Exemplo n.º 11
0
    def render(data, system):
        request = system.get('request')
        if request is not None:
            response = request.response
            ct = response.content_type
            if ct == response.default_content_type:
                response.content_type = 'application/rss+xml'

        if 'updates' in data:
            key = 'updates'
        elif 'users' in data:
            key = 'users'
        elif 'comments' in data:
            key = 'comments'
        elif 'overrides' in data:
            key = 'overrides'
        else:
            raise HTTPNotFound("RSS not implemented for this service")

        feed = webhelpers.feedgenerator.Rss201rev2Feed(
            title=key,
            link=request.url,
            description=key,
            language=u"en",
        )

        def linker(route, param, key):
            return lambda obj: request.route_url(route, **{param: obj[key]})

        getters = {
            'updates': {
                'title': operator.itemgetter('title'),
                'link': linker('update', 'id', 'title'),
                'description': operator.itemgetter('notes'),
                'pubdate': operator.itemgetter('date_submitted'),
            },
            'users': {
                'title': operator.itemgetter('name'),
                'link': linker('user', 'name', 'name'),
                'description': operator.itemgetter('name'),
            },
            'comments': {
                'title': operator.itemgetter('text'),
                'link': linker('comment', 'id', 'id'),
                'description': operator.itemgetter('text'),
                'pubdate': operator.itemgetter('timestamp'),
            },
            'overrides': {
                'title': operator.itemgetter('nvr'),
                'link': linker('override', 'nvr', 'nvr'),
                'description': operator.itemgetter('notes'),
                'pubdate': operator.itemgetter('submission_date'),
            },
        }

        for value in data[key]:
            feed.add_item(**dict([
                (name, getter(value)) for name, getter in getters[key].items()
            ]))

        return feed.writeString('utf-8')
Exemplo n.º 12
0
    def delete_path(self, close_session=True):
        """Interprets the path, accesses, and delete objects keys. In detail, the 
        query path supported in the current implementation allows the navigation
        of data according to the tree structure characterizing application 
        objects. The path has the form:

        N1/N2/.../Nn

        where each `N` represents a level(Node) in the tree structure of an 
        object (possibly indicating the collection it belongs to). Specifically,
        every Node represents a collection, or an object identifier, or a field 
        name. 
        """

        # NOTE: Obtêm o registro do banco de dados! By John Doe
        member = self.context.get_raw_member(self.request.matchdict['id'])
        if member is None:
            if close_session:

                # NOTE: Tentar fechar a conexão de qualquer forma!
                # -> Na criação da conexão "coautocommit=True"!
                # By Questor
                try:
                    if self.context.session.is_active:
                        self.context.session.close()
                except:
                    pass

            raise HTTPNotFound()

        self._check_modified_date(member, path=self.request.matchdict['path'])

        # NOTE: Aqui define o caminho e a operação dentro de tuplas em um
        # array! By John Doe
        list_pattern = [{
            'path': self.request.matchdict['path'],
            'mode': 'delete'
        }]

        # NOTE: Define a operação x caminho e as funções executantes da tarefa via
        # delegate! By John Doe
        document = parse_list_pattern(self.get_base(), member.document,
                                      list_pattern)

        # NOTE: Build data! By John Doe
        data = validate_put_data(self, dict(value=document), member)

        # NOTE: Update member! By John Doe
        member = self.context.update_member(member, data)

        if close_session:

            # NOTE: Tentar fechar a conexão de qualquer forma!
            # -> Na criação da conexão "coautocommit=True"!
            # By Questor
            try:
                if self.context.session.is_active:
                    self.context.session.close()
            except:
                pass

        return Response('DELETED', content_type='text/plain')
Exemplo n.º 13
0
    def patch_path(self, member=None, close_session=True):
        """Interprets the path, accesses, and update objects. In detail, 
        the query path supported in the current implementation allows
        the navigation of data according to the tree structure
        characterizing application objects. The path has the form:

        N1/N2/.../Nn

        where each `N` represents a level(Node) in the tree structure
        of an object (possibly indicating the collection it belongs
        to). Specifically, every Node represents a collection, or an
        object identifier, or a field name.
        """

        # NOTE: Get raw mapped entity object! By John Doe
        if member is None:
            member = self.context.get_raw_member(self.request.matchdict['id'])
            if member is None:
                if close_session:

                    # NOTE: Tentar fechar a conexão de qualquer forma!
                    # -> Na criação da conexão "coautocommit=True"!
                    # By Questor
                    try:
                        if self.context.session.is_active:
                            self.context.session.close()
                    except:
                        pass

                raise HTTPNotFound()

        self._check_modified_date(member, path=self.request.matchdict['path'])

        if self.request.params.get('path') == '/':
            # NOTE: Patch path! By John Doe

            document = member.document
        elif isinstance(self.request.matchdict['path'], list):

            # NOTE: Force patch mode! By John Doe
            for path in self.request.matchdict['path']:
                if 'mode' not in path:
                    path['mode'] = 'patch'

            document = parse_list_pattern(self.get_base(), member.document,
                                          self.request.matchdict['path'])
        else:
            list_pattern = [{
                'path': self.request.matchdict['path'],
                'mode': 'patch',
                'args': [self.request.params['value']]
            }]
            document = parse_list_pattern(self.get_base(), member.document,
                                          list_pattern)

        if 'validate' in self.request.params:
            # NOTE: Validate data (check for flag)! By John Doe

            data = validate_patch_data(
                self,
                dict(value=document, validate=self.request.params['validate']),
                member)
        else:
            data = validate_patch_data(self, dict(value=document), member)

        esp_cmd = None
        try:
            esp_cmd = self.request.params["esp_cmd"]
        except Exception as e:
            pass

        # NOTE: Como o parâmetro "esp_cmd" é opcional ele não está
        # declarado na rota e não entra em "self.request.matchdict"!
        # By Questor
        if esp_cmd == "dont_idx":
            index = False
        else:
            index = True

        # NOTE: Update member! By John Doe
        member = self.context.update_member(member, data, index=index)

        # NOTE: Now commits and closes session here instead of in the
        # context - DCarv
        if close_session:

            # NOTE: Tentar fechar a conexão de qualquer forma!
            # -> Na criação da conexão "coautocommit=True"!
            # By Questor
            try:
                if self.context.session.is_active:
                    self.context.session.close()
            except:
                pass

        return Response('UPDATED', content_type='text/plain')
Exemplo n.º 14
0
    def set_path(self):
        """Interprets the path, accesses, and append objects. In detail, the query
        path supported in the current implementation allows the navigation of 
        data according to the tree structure characterizing application objects. 
        The path has the form:

        N1/N2/.../Nn

        where each `N` represents a level(Node) in the tree structure of an 
        object (possibly indicating the collection it belongs to). Specifically,
        every Node represents a collection, or an object identifier, or a field 
        name. The last Node (Nn) must return a list object, so we can append 
        the new object to it.
        """

        # NOTE: Get raw mapped entity object! By John Doe
        member = self.context.get_raw_member(self.request.matchdict['id'])

        if member is None:

            # NOTE: Tentar fechar a conexão de qualquer forma!
            # -> Na criação da conexão "coautocommit=True"!
            # By Questor
            try:
                if self.context.session.is_active:
                    self.context.session.close()
            except:
                pass

            raise HTTPNotFound()

        self._check_modified_date(member, path=self.request.matchdict['path'])

        # NOTE: Set path! By John Doe
        list_pattern = [{
            'path': self.request.matchdict['path'],
            'mode': 'insert',
            'args': [self.request.params['value']]
        }]
        document = parse_list_pattern(self.get_base(), member.document,
                                      list_pattern)

        # NOTE: Build data! By John Doe
        if 'validate' in self.request.params:
            data = validate_put_data(
                self,
                dict(value=document, validate=self.request.params['validate']),
                member)
        else:
            data = validate_put_data(self, dict(value=document), member)

        # NOTE: Update member! By John Doe
        member = self.context.update_member(member, data)

        # NOTE: Tentar fechar a conexão de qualquer forma!
        # -> Na criação da conexão "coautocommit=True"!
        # By Questor
        try:
            if self.context.session.is_active:
                self.context.session.close()
        except:
            pass

        return Response('OK', content_type='text/plain')