Commit 311e5668 authored by lixiaofang's avatar lixiaofang

real_time

parent e44fb45a
......@@ -2,9 +2,11 @@ import datetime
from django.db import models
import logging
import traceback
from django.conf import settings
from trans2es.models.topic import Reply
from .tag import Tag
from .topic import Topic, TopicBillBoard
from .user_extra import UserExtra
class PictorialFollow(models.Model):
......@@ -171,6 +173,62 @@ class Pictorial(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return []
def get_latest_real_reply_time(self):
try:
reply_query_results = Reply.objects.using(settings.SLAVE_DB_NAME).filter(pictorial_id=self.id, is_deleted=0,
is_online=1).values("user_id",
"create_time")
datetime_list = list()
if reply_query_results.count() > 0:
for reply in reply_query_results:
UserExtra_results = UserExtra.objects.using(settings.SLAVE_DB_NAME).filter(user_id=reply['user_id']).values('is_shadow')
if UserExtra_results.count() > 0:
if not UserExtra_results[0]['is_shadow']:
datetime_list.append(reply['create_time'])
else:
datetime_list.append(reply['create_time'])
if len(datetime_list) > 0:
dt = max(datetime_list)
return datetime.datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
else:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
except:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
def get_latest_real_topic_time(self):
try:
topic_id_list = list(
PictorialTopics.objects.filter(pictorial_id=self.id, is_online=True, is_deleted=False).values_list(
"topic_id", flat=True))
logging.info("get topic_id_list:%s" % topic_id_list)
topic_info = Topic.objects.filter(id__in=topic_id_list).values("user_id", "create_time")
logging.info("get topic_info:%s" % topic_info)
datetime_list = list()
if topic_info.count() > 0:
for topic in topic_info:
UserExtra_results = UserExtra.objects.using(settings.SLAVE_DB_NAME).filter(
user_id=topic['user_id']).values('is_shadow')
if UserExtra_results.count() > 0:
if not UserExtra_results[0]['is_shadow']:
datetime_list.append(topic['create_time'])
else:
datetime_list.append(topic['create_time'])
logging.info("get datetime_list:%s" % datetime_list)
if len(datetime_list) > 0:
dt = max(datetime_list)
logging.info("get max datetime_list:%s" % dt)
return datetime.datetime(dt.year, dt.month, dt.day, dt.hour, dt.minute, dt.second,
tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
else:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
except:
return datetime.datetime(1980, 1, 1, 0, 0, 0, tzinfo=datetime.timezone(datetime.timedelta(hours=8)))
class PictorialTag(models.Model):
"""画报关注标签"""
......
......@@ -420,4 +420,5 @@ class Reply(models.Model):
create_time = models.DateTimeField(verbose_name=u'创建时间')
is_deleted = models.BooleanField(verbose_name=u'是否删除')
is_online = models.BooleanField(verbose_name=u'是否上线')
pictorial_id = models.IntegerField(verbose_name=u"榜单ID")
......@@ -70,6 +70,10 @@ class PictorialTransfer(object):
res["is_cover"] = instance.get_is_cover(res["topic_id_list"])
res["topic_vote_number"] = instance.get_topic_vote_number()
res["activity_join"] = instance.get_activity_join()
res["latest_real_reply_time"] = instance.get_latest_real_reply_time()
res["latest_real_topic_time"] = instance.get_latest_real_topic_time()
logging.info("get data:%s" % res)
return res
except:
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment