Beispiel #1
0
Datei: qa.py Projekt: todun/ksweb
    def post(self,
             title,
             workspace,
             question,
             tooltip,
             link,
             answer_type,
             precondition=None,
             answers=None,
             **kw):
        if not self._are_answers_valid(answer_type, answers):
            response.status_code = 412
            return dict(
                errors={'answers': _('Please add at least one more answer')})

        user = request.identity['user']

        qa = Qa(_owner=user._id,
                _workspace=ObjectId(workspace),
                _parent_precondition=to_object_id(precondition),
                title=title,
                question=question,
                tooltip=tooltip,
                link=link,
                type=answer_type,
                answers=answers,
                auto_generated=False,
                public=True,
                visible=True)
        DBSession.flush(qa)
        qa.generate_output_from()

        return dict(errors=None, _id=ObjectId(qa._id))
Beispiel #2
0
 def answers(self):
     questions = sorted(self.qa_values.items(),
                        key=lambda i: i[1].order_number)
     return [
         dict(question=Qa.by_id(q).question, answer=a.qa_response)
         for q, a in questions
     ]
Beispiel #3
0
Datei: qa.py Projekt: todun/ksweb
 def valid_options(self, workspace):
     questions = Qa.available_for_user(request.identity['user']._id,
                                       workspace)
     return dict(questions=[{
         '_id': qa._id,
         'title': qa.title
     } for qa in questions])
Beispiel #4
0
    def test_upsert_document_already_in(self):
        qa = Qa(_owner=ObjectId(self._get_user('*****@*****.**')._id),
                _workspace=ObjectId(self.ws._id),
                _parent_precondition=None,
                title='title',
                question='question',
                tooltip='tooltip',
                link='link',
                type='text',
                answers=['answers'],
                public=True,
                visible=True)
        model.DBSession.flush_all()

        inserted = upsert_document(
            cls=model.Qa,
            _owner=ObjectId(self._get_user('*****@*****.**')._id),
            _workspace=ObjectId(self.ws._id),
            _parent_precondition=None,
            title='title',
            question='question',
            tooltip='tooltip',
            link='link',
            type='text',
            answers=['answers'],
            public=True,
            visible=True)
        assert inserted is qa, (inserted, qa)
        qas = model.Qa.query.find().all()
        assert len(qas) == 3, qas
Beispiel #5
0
def sidebar(section=None, workspace=None, **kw):
    unread_qas = Qa.unread_count(workspace)
    unread_outputs = Output.unread_count(workspace)
    unread_filters = Precondition.unread_count(workspace)
    unread_documents = Document.unread_count(workspace)
    return render_template(dict(workspace=workspace,
                                unread_qas=unread_qas,
                                unread_outputs=unread_outputs,
                                unread_filters=unread_filters,
                                unread_documents=unread_documents),
                           template_name='ksweb.templates.partials.sidebar')
Beispiel #6
0
Datei: qa.py Projekt: todun/ksweb
    def put(self,
            _id,
            title,
            workspace,
            question,
            tooltip,
            link,
            answer_type,
            precondition=None,
            answers=None,
            **kw):
        if not self._are_answers_valid(answer_type, answers):
            response.status_code = 412
            return dict(
                errors={'answers': _('Please add at least one more answer')})

        check = self.get_related_entities(_id)

        if check.get("entities"):
            entity = dict(_id=_id,
                          _workspace=workspace,
                          title=title,
                          entity='qa',
                          question=question,
                          tooltip=tooltip,
                          link=link,
                          auto_generated=False,
                          type=answer_type,
                          _parent_precondition=precondition,
                          answers=answers)

            session.data_serializer = 'pickle'
            session[
                'entity'] = entity  # overwrite always same key for avoiding conflicts
            session.save()

            return dict(redirect_url=tg.url('/resolve',
                                            params=dict(workspace=workspace)))

        qa = Qa.upsert({'_id': ObjectId(_id)},
                       dict(_workspace=ObjectId(workspace),
                            _parent_precondition=to_object_id(precondition),
                            title=title,
                            question=question,
                            auto_generated=False,
                            tooltip=tooltip,
                            link=link,
                            type=answer_type,
                            answers=answers))
        DBSession.flush(qa)
        qa.generate_output_from()
        return dict(errors=None)
Beispiel #7
0
 def do_get_dependencies(self):
     qa = Qa(question=u'Bounshch',
             title='Super QA',
             type=Qa.TYPES.TEXT,
             answers=[])
     _filter = Precondition(
         title=u'marengous',
         condition=[qa._id, ""],
         type=Precondition.TYPES.SIMPLE,
     )
     return {
         'precondition': _filter,
         'html': "Hi @{%s}" % qa.hash,
     }
Beispiel #8
0
Datei: qa.py Projekt: todun/ksweb
 def get_all(self, workspace, **kw):
     return dict(page='qa-index',
                 fields={
                     'columns_name':
                     [_('Label'),
                      _('Question'),
                      _('Filter'),
                      _('Id')],
                     'fields_name':
                     'title question parent_precondition hash'.split()
                 },
                 entities=Qa.available_for_user(
                     request.identity['user']._id, workspace),
                 actions=False,
                 workspace=workspace)
Beispiel #9
0
Datei: qa.py Projekt: todun/ksweb
 def get_one(self, id, **kw):
     id = hash_to_id(id, Qa)
     return dict(qa=Qa.by_id(id))
Beispiel #10
0
Datei: qa.py Projekt: todun/ksweb
 def mark_as_read(self, workspace):
     Qa.mark_as_read(request.identity['user']._id, workspace)