Exemplo n.º 1
0
    def entity(self, _id):
        entity = entity_from_hash(_id)
        if not entity:
            entity = entity_from_id(_id)
        if entity:
            redirect(entity.url)

        abort(404)
Exemplo n.º 2
0
 def _clone_and_modify_(self, obj_to_clone, to_edit):
     new_obj = self._clone_object()
     old_obj_id = ObjectId(obj_to_clone['_id'])
     for obj in to_edit:
         entity = entity_from_id(obj['_id'])
         if obj_to_clone['entity'] == 'output':
             entity.html = entity.html.replace(obj_to_clone['hash'], str(new_obj.hash))
         elif obj_to_clone['entity'] in ['precondition/simple', 'precondition/advanced']:
             if entity.entity == 'qa' and entity._parent_precondition == old_obj_id:
                 entity._parent_precondition = new_obj._id
             elif entity.entity == 'output' and entity._precondition == old_obj_id:
                 entity._precondition = new_obj._id
             elif entity.entity == 'precondition/advanced':
                 entity.condition = [new_obj._id if __ == old_obj_id else __ for __ in entity.condition]
         elif obj_to_clone['entity'] == 'qa':
             entity.condition = [new_obj._id if __ == old_obj_id else __ for __ in entity.condition]
Exemplo n.º 3
0
    def _original_edit(self):
        params = session.get('entity')
        params['_workspace'] = to_object_id(params.get('_workspace'))
        params['_precondition'] = to_object_id(params.get('_precondition'))
        entity = entity_from_id(params['_id'])
        if (type(entity) is model.Precondition):
            if entity.is_advanced:
                params['condition'] = [to_object_id(__) if __ not in model.Precondition.PRECONDITION_OPERATOR else __ for __ in params['condition'] ]
            else:
                params['condition'][0] = ObjectId(params['condition'][0])

        old_hash = entity['hash']
        params.pop('entity', None)
        for k, v in params.items():
            setattr(entity, k, v)
        DBSession.flush(entity)
        entity.update_dependencies(old_hash)
        return entity
Exemplo n.º 4
0
    def post(self, highlighted_text=u'', workspace=None, list_=[]):
        first_5_words = u' '.join(highlighted_text.split())
        title = u' '.join(first_5_words.split(" ")[:5])
        user = request.identity['user']
        output = Output(
            _owner=user._id,
            _workspace=workspace,
            title=title,
            public=True,
            visible=True,
            html=highlighted_text,
            auto_generated=True,
            status=Output.STATUS.UNREAD,
        )
        for o in list_:
            m = entity_from_id(_id=ObjectId(o[2:-1]))
            output.insert_content(m)

        return dict(_id=str(output._id), title=title)
Exemplo n.º 5
0
 def _clone_object(self):
     params = session.get('entity')
     entity = entity_from_id(params['_id'])
     params['title'] += _(' [CLONED]')
     new_obj = clone_obj(self.related_models[params['entity']], entity, params)
     return new_obj