コード例 #1
0
def update_question_view_times(request, question):
    last_seen_in_question = request.session.get('last_seen_in_question', {})

    last_seen = last_seen_in_question.get(question.id, None)

    if (not last_seen) or (last_seen < question.last_activity_at):
        QuestionViewAction(question, request.user, ip=request.META['REMOTE_ADDR']).save()
        last_seen_in_question[question.id] = datetime.datetime.now()
        request.session['last_seen_in_question'] = last_seen_in_question
コード例 #2
0
ファイル: readers.py プロジェクト: yangjiandong/zhimaq
def update_question_view_times(request, question):
    if not 'last_seen_in_question' in request.session:
        request.session['last_seen_in_question'] = {}

    last_seen = request.session['last_seen_in_question'].get(question.id, None)

    if (not last_seen) or last_seen < question.last_activity_at:
        QuestionViewAction(question, request.user, ip=request.META['REMOTE_ADDR']).save()
        request.session['last_seen_in_question'][question.id] = datetime.datetime.now()

    request.session['last_seen_in_question'][question.id] = datetime.datetime.now()
コード例 #3
0
ファイル: readers.py プロジェクト: perryhau/iCQA
def update_question_view_times(request, question):
    last_seen_in_question = request.session.get('last_seen_in_question', {})

    last_seen = last_seen_in_question.get(question.id, None)
    
    #TODO: remove temp fix
    if question.last_activity_at is None:
        question.update_last_activity(question.author, save=True, time=question.added_at)

    if (not last_seen) or (last_seen < question.last_activity_at):
        QuestionViewAction(question, request.user, ip=request.META['REMOTE_ADDR']).save()
        last_seen_in_question[question.id] = datetime.datetime.now()
        request.session['last_seen_in_question'] = last_seen_in_question
コード例 #4
0
ファイル: readers.py プロジェクト: yyaadet/osqa-cn
def update_question_view_times(request, question):
    last_seen_in_question = request.session.get('last_seen_in_question', {})

    last_seen = last_seen_in_question.get(question.id, None)

    if (not last_seen) or (last_seen < question.last_activity_at):
        try:
            QuestionViewAction(question,
                               request.user,
                               ip=request.META['REMOTE_ADDR']).save()
        except Exception, e:
            import traceback
            logging.error(
                "Caught exception %s in update_question_view_times :\n %s" %
                (str(e), traceback.format_exc()))
        last_seen_in_question[question.id] = datetime.datetime.now()
        request.session['last_seen_in_question'] = last_seen_in_question
コード例 #5
0
    if not action.viewuser.is_authenticated():
        return

    try:
        subscription = QuestionSubscription.objects.get(question=action.node,
                                                        user=action.viewuser)
        subscription.last_view = datetime.datetime.now()
        subscription.save()
    except:
        if action.viewuser.subscription_settings.questions_viewed:
            subscription = QuestionSubscription(question=action.node,
                                                user=action.viewuser)
            subscription.save()


QuestionViewAction.hook(question_viewed)

#todo: translate this
#record_answer_event_re = re.compile("You have received (a|\d+) .*new response.*")
#def record_answer_event(instance, created, **kwargs):
#    if created:
#        q_author = instance.question.author
#        found_match = False
#        #print 'going through %d messages' % q_author.message_set.all().count()
#        for m in q_author.message_set.all():
##            #print m.message
# #           match = record_answer_event_re.search(m.message)
#            if match:
#                found_match = True
#                try:
#                    cnt = int(match.group(1))
コード例 #6
0
ファイル: subscriptions.py プロジェクト: viikasgarg/osqa
UserJoinsAction.hook(member_joined)

def question_viewed(action, new):
    if not action.viewuser.is_authenticated():
        return

    try:
        subscription = QuestionSubscription.objects.get(question=action.node, user=action.viewuser)
        subscription.last_view = datetime.datetime.now()
        subscription.save()
    except:
        if action.viewuser.subscription_settings.questions_viewed:
            subscription = QuestionSubscription(question=action.node, user=action.viewuser)
            subscription.save()

QuestionViewAction.hook(question_viewed)


#todo: translate this
#record_answer_event_re = re.compile("You have received (a|\d+) .*new response.*")
#def record_answer_event(instance, created, **kwargs):
#    if created:
#        q_author = instance.question.author
#        found_match = False
#        #print 'going through %d messages' % q_author.message_set.all().count()
#        for m in q_author.message_set.all():
##            #print m.message
# #           match = record_answer_event_re.search(m.message)
#            if match:
#                found_match = True
#                try: