Commit c3072b04 authored by 李小芳's avatar 李小芳

add

parent ead6de1e
......@@ -184,6 +184,29 @@ class Diary(models.Model):
logging.error("catch exception,err_msg:%s" % traceback.format_exc())
return ''
def get_keynote_sentence(user_id=None, id=None):
try:
result = Problems.objects.filter(user_id=user_id, topic_type__in=["0", "1", "2"], diary_id=id,
is_online=True).order_by('-last_modified').values_list(
"answer", flat=True)[:5]
content_list = []
for content in result:
ss = content.encode('utf-16', 'surrogatepass').decode('utf-16')
dr = re.compile(r"<[^>]+>", re.S)
str_re = dr.sub("", ss)
para = re.sub('([;。!?\?])([^”’])', r"\1\n\2", str_re) # 单字符断句符
para = re.sub('(\.{6})([^”’])', r"\1\n\2", para) # 英文省略号
para = re.sub('(\…{2})([^”’])', r"\1\n\2", para) # 中文省略号
para = re.sub('([;。!?\?][”’])([^,。!?\?])', r'\1\n\2', para)
para = para.rstrip() # 段尾如果有多余的\n就去掉它
for con in para.split("\n"): ##切分文章成一句一句的内容
r = '[’!"#$%&\'()*+,-./:;=?@[\\]^_`{|}~。?,]+'
cos = con.lstrip(r)
content_list.append(cos)
return content_list
except:
logging.error("catch exception,logins:%s" % traceback.format_exc())
return []
def get_new_diary_score(self):
try:
......
......@@ -68,6 +68,7 @@ def get_diary(instance):
'stick_priority': d.stick_priority,
"title": d.title,
"answer": d.get_diary_answer(),
"keynote_sentence": d.get_keynote_sentence(d.user_id, d.id) if int(float(d.content_level)) >= 3 else "",
"good_click":d.get_good_click,
"is_promote":d.get_cpc,
"is_low_quality":d.get_low_quality
......
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