def api_list_focusnews(numbers): # 查询焦点新闻列表,只显示最新的几条 result = dict() if not numbers: numbers = 5 else: numbers = int(numbers) news = News.objects.filter( is_home_image_show=TRUE_INT, del_flag=FALSE_INT).order_by('-public_time')[:numbers] news_list = list() for each_news in news: news_dict = { "public_time": each_news.public_time.strftime('%Y-%m-%d') if each_news.public_time else "", "image_url": get_image_url(each_news.image.url) if each_news.image else "", "id": each_news.id, "title": each_news.title, "content": each_news.content, "publisher": each_news.publisher.name, } news_list.append(news_dict) result['news_list'] = news_list result['count'] = len(news_list) return dict(c=SUCCESS[0], m=SUCCESS[1], d=result)
def struct_work(work, pov): from utils.file_fun import get_file_url from utils.file_fun import get_image_url from applications.common.services import area_name result = collections.OrderedDict() result['id'] = str(work.id) result['name'] = work.name result['rar_url'] = get_file_url( work.rar_file.url) if work.rar_file else '' result['img_url'] = get_image_url( work.img_file.url) if work.img_file else '' result['no'] = work.no result['sub_activity'] = work.sub_activity result['phase'] = work.phase result['project'] = work.project result['subject'] = work.subject result['status'] = str(work.status) result['authors'] = work.authors result['star'] = str(work.like) result['pv'] = str(work.pv) result['final_rank'] = work.ranks.name if work.ranks else '' result['final_score'] = str(work.final_score) result['preview_status'] = str(work.preview_status) result['area_is_direct'] = str(work.area.manage_direct) result['area_id'] = str(work.area.id) result['area_name_full'] = area_name(work.area.id, pov=pov) result['area_name_simple'] = area_name(work.area.id, full=False, pov=pov) result['is_public'] = str(work.is_public) if work.is_public else '0' return result
def __download_video(self): video_file = FileObj.objects.filter(del_flag=FALSE_INT, id=self.obj.src_file.id).first() if not video_file: raise Exception(u"找不到相应的文件!") video_file_url = get_image_url(video_file.url, abs=True) self.local_file_path = download_file(video_file_url)
def list_news(user, area_id, verbose): news = News.objects.filter(del_flag=DEL_FLAG_NO) if area_id: news = news.filter(area_id=area_id) # 默认列出已发布的新闻 if not verbose or "1" == verbose: news = news.filter(status=FLAG_YES) else: news = news.filter(status=FLAG_NO) news_info = news.order_by('-is_top', "-status", "-public_time", "-id").\ values("id", "title", 'news_type_id', 'is_top', 'status', 'public_time', "del_flag", "image__url", "is_home_image_show", "read") news_info = list(news_info) news_len = len(news_info) for index, item in enumerate(news_info): item["public_time"] = item["public_time"].strftime( '%Y-%m-%d') if item["public_time"] else "" item["image_url"] = get_image_url( item["image__url"]) if item["image__url"] else "" item.pop("image__url") item["is_home_image_show"] = item["is_home_image_show"] if item[ "is_home_image_show"] else "0" if item["news_type_id"]: item["news_type_name"] = get_newstypename_byid( area_id, item["news_type_id"]) if 0 == index: item["previous"] = "" item["previous_title"] = '' if news_len > index + 1: item["next"] = str(news_info[index + 1]["id"]) item["next_title"] = news_info[index + 1]["title"] else: item["next"] = "" item["next_title"] = '' elif news_len - 1 == index: item["previous"] = str(news_info[index - 1]["id"]) item["previous_title"] = news_info[index - 1]["title"] item["next"] = "" item["next_title"] = '' else: item["previous"] = str(news_info[index - 1]["id"]) item["previous_title"] = news_info[index - 1]["title"] item["next"] = str(news_info[index + 1]["id"]) item["next_title"] = news_info[index + 1]["title"] dict_resp = dict(c=SUCCESS[0], m=SUCCESS[1], d=news_info) return dict_resp
def detail_news(user, news_id, area_id=None): if not news_id: raise Exception(u"新闻ID不能为空") check_result = check_user_permission_news(user) if SUCCESS[0] == check_result["c"]: news_info = News.objects.filter(id=news_id, del_flag=DEL_FLAG_NO).\ values("id", "area_id", "title", 'content', 'news_type_id', 'is_top', 'publisher_id', 'status', 'public_time', 'image__url', 'is_home_image_show', 'read') else: news_info = News.objects.filter(id=news_id, del_flag=DEL_FLAG_NO, status=FLAG_YES).\ values("id", "area_id", "title", 'content', 'news_type_id', 'is_top', 'publisher_id', 'status', 'public_time', 'image__url', 'is_home_image_show', 'read') if not news_info: dict_resp = dict(c=ERR_NODATA_FOUND[0], m=ERR_NODATA_FOUND[1], d=[]) else: list_result = list_news(user, area_id=area_id, verbose=None) list_info = list_result["d"] news_info = list(news_info)[0] if news_info["public_time"]: news_info["public_time"] = news_info["public_time"].strftime( '%Y-%m-%d') if news_info["public_time"] else "" if news_info["news_type_id"]: news_info["news_type_name"] = get_newstypename_byid( news_info["area_id"], news_info["news_type_id"]) news_info["image_url"] = get_image_url( news_info["image__url"]) if news_info["image__url"] else "" news_info.pop("image__url") news_info["is_home_image_show"] = news_info[ "is_home_image_show"] if news_info["is_home_image_show"] else "0" for item in list_info: if item["id"] == news_info["id"]: news_info["previous"] = item["previous"] news_info["previous_title"] = item["previous_title"] news_info["next"] = item["next"] news_info["next_title"] = item["next_title"] news_info["read"] = item["read"] dict_resp = dict(c=SUCCESS[0], m=SUCCESS[1], d=[news_info]) # 阅读量加1 cur_news = News.objects.get(id=news_id) cur_news.read = cur_news.read + 1 if cur_news.read else 1 cur_news.save() return dict_resp
def display_expert(user, area_id): area = Area.objects.filter(del_flag=FLAG_NO, id=area_id).first() if not area: return dict(c=ERR_REQUEST_PARAMETER_ERROR[0], m=ERR_REQUEST_PARAMETER_ERROR[1]) expert_infos = Expert.objects.filter(del_flag=FLAG_NO, area=area, is_show_homepage=FLAG_YES).\ values("id", "account_id", "area_id", "account__username", "name", "sex", "area__area_name", "area__area_level", "area__area_code", 'institution', 'is_show_homepage', "account__image__url") expert_infos = list(expert_infos) data = [] for item in expert_infos: dict_tmp = { "id": item["id"], "name": item['name'], "sex": item['sex'], "username": item['account__username'], 'account_id': item['account_id'], "area_name": item['area__area_name'], "area_id": item["area_id"], "area_level": item['area__area_level'], "area_code": item["area__area_code"], "institution": item['institution'], "is_show_homepage": item['is_show_homepage'], "image_url": get_image_url(item["account__image__url"]) if item['account__image__url'] else "" } data.append(dict_tmp) return dict(c=SUCCESS[0], m=SUCCESS[1], d=data)
def list_expert_user(user, cur_user_id, name, area_id, manage_direct, is_show_store=None): name = name.strip() if name else "" expert_list = Expert.objects.filter(del_flag=FLAG_NO) if is_show_store: expert_list = expert_list.filter(is_show_store=is_show_store) else: expert_list = expert_list.filter(is_show_store=1) if name: # expert_list = expert_list.filter(name__contains=name) expert_list = expert_list.filter( Q(name__contains=name) | Q(account__mobile__contains=name) | Q(account__username__contains=name)) if area_id: expert_list = expert_list.filter(area_id=area_id) if manage_direct: expert_list = expert_list.filter(area__manage_direct=FLAG_YES) expert_infos = expert_list.values( "id", "account_id", "area_id", "account__username", "name", "sex", "area__area_name", "area__area_level", "area__area_code", 'institution', 'is_show_homepage', "account__image__url", "area__manage_direct", "is_show_store", 'position').order_by("-update_time") expert_infos = list(expert_infos) data = [] for item in expert_infos: area_name = item["area__area_name"] if item["area__manage_direct"]: if item["area__area_level"] == LEVEL_PROVINCE: area_name = u"省直属" elif item["area__area_level"] == LEVEL_CITY: area_name = u"市直属" elif item["area__area_level"] == LEVEL_NATION: area_name = u"国直属" else: pass dict_tmp = { "id": item["id"], "name": item['name'], "sex": item['sex'], "username": item['account__username'], 'account_id': item['account_id'], "area_name": area_name, "area_id": item["area_id"], "area_level": item['area__area_level'], "area_code": item["area__area_code"], "institution": item['institution'], "is_show_homepage": item['is_show_homepage'], "image_url": get_image_url(item["account__image__url"]) if item['account__image__url'] else "", "is_show_store": item['is_show_store'], "position": item['position'], } data.append(dict_tmp) return dict(c=SUCCESS[0], m=SUCCESS[1], d=data)