Ejemplo n.º 1
0
def add_question(request):
    question = {}
    if request.method == 'POST':
        questiontext = bleach.clean(request.POST.get('questiontext'), strip=True)
        str_tags = request.POST.get('hidTags')
        question = Questions(text=questiontext, user=request.user)
        question.tags = Tag.handle_if_tags('tags', str_tags)
        question.created_at = datetime.now()
        DBSession.add(question)
        tracker = Trackers(tracker=request.user, question=question, is_bookmark=False)
        DBSession.add(tracker)
        DBSession.flush()  # make sure there's no DB Errors before sending out the emails
        scheduler.add_job(send_emails_immediate_question,
                          next_run_time=now(scheduler.timezone).replace(seconds=+30).datetime,
                          kwargs={'question_id': question.id, 'attr_name': 'question_notification',
                                  'nice_type': 'New Question Asked', 'type': 'Question'})

    return {'question': question, 'now': now(request.registry.settings.get('scheduler.timezone'))}
Ejemplo n.º 2
0
def list(request):
    query = request.params.get('query')
    type = request.matchdict.get('type', 'all')
    to_id = request.matchdict.get('to_id')
    if type in ('tracking', 'bookmarked'):
        results, total = list_trackings(0, 100, query, request)
    elif type == 'answers':
        results, total = list_answers(0, 100, query, request)
    elif type == 'all':
        results, total = list_questions(0, 100, query, request)
    else:
        results, total = list_questions(0, 100, query, request)
    return {'result': results, 'total': total, 'type': type,
            'now': now(request.registry.settings.get('scheduler.timezone'))}
Ejemplo n.º 3
0
def add_answer(request):
    editor_tags = ['ul', 'li', 'ol', 'strong', 'em', 'p', 'hr', 'span', 'del', 'a', 'br']
    answer_text = bleach.clean(request.POST.get('answer', ''), editor_tags, {
        "*": ["style"],
        "img": ["src", "width", "height"],
    }, styles=['text-align'])
    qid = request.POST.get('qid', -1)
    question = DBSession.query(Questions).filter(Questions.id == qid).first()
    had_answers = len(question.answers)
    answer = Answers(user=request.user, question=question, text=answer_text)
    answer.created_at = datetime.now()  # TODO put as default (also for question)
    DBSession.add(answer)
    DBSession.flush()
    scheduler.add_job(send_emails_immediate_answer, next_run_time=now(scheduler.timezone).replace(seconds=+30).datetime,
                      kwargs={'answer_id': answer.id, 'attr_name': 'answer_notification',
                              'nice_type': 'New Answer', 'type': 'Answer'})
    return HTTPFound('/exchange/%s/show%s' % (qid, '?first_answer=1' if had_answers == 0 else '?answered=1'))
Ejemplo n.º 4
0
def now(format):
    return arrow_api.now().format(format)
Ejemplo n.º 5
0
def now(format):
    return arrow_api.now().format(format)
Ejemplo n.º 6
0
    def test_no_tz(self):

        assertDtEqual(api.now(), datetime.now(tz.tzlocal()))
Ejemplo n.º 7
0
    def test_tz_str(self):

        assertDtEqual(api.now("EST"), datetime.now(tz.gettz("EST")))
Ejemplo n.º 8
0
    def test_tz_str(self):

        assertDtEqual(api.now('EST'), datetime.now(tz.gettz('EST')))
Ejemplo n.º 9
0
    def test_now(self):

        expect(api._factory.now).args('tz').returns('now')

        assertEqual(api.now('tz'), 'now')
Ejemplo n.º 10
0
def show_question(request):
    id = request.matchdict.get('id')
    question = DBSession.query(Questions).get(id)
    return {'question': question,
            'now': now(request.registry.settings.get('scheduler.timezone'))}
Ejemplo n.º 11
0
    def test_tz_str(self):

        assertDtEqual(api.now('EST'), datetime.now(tz.gettz('EST')))
Ejemplo n.º 12
0
    def test_no_tz(self):

        assertDtEqual(api.now(), datetime.now(tz.tzlocal()))
Ejemplo n.º 13
0
    def test_now(self):

        self.expect(api._factory.now).args("tz").returns("now")

        self.assertEqual(api.now("tz"), "now")