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'))}
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'))}
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'))
def now(format): return arrow_api.now().format(format)
def test_no_tz(self): assertDtEqual(api.now(), datetime.now(tz.tzlocal()))
def test_tz_str(self): assertDtEqual(api.now("EST"), datetime.now(tz.gettz("EST")))
def test_tz_str(self): assertDtEqual(api.now('EST'), datetime.now(tz.gettz('EST')))
def test_now(self): expect(api._factory.now).args('tz').returns('now') assertEqual(api.now('tz'), 'now')
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'))}
def test_now(self): self.expect(api._factory.now).args("tz").returns("now") self.assertEqual(api.now("tz"), "now")