def theme_view(request,template_name="kinger/revision/axis_theme_view.html"): """ 主题详情页""" tile_id = request.GET.get('tid') ty = request.GET.get('ty') if ty == 'theme': themes = Tile.objects.filter(new_category_id__gt=2400,new_category_id__lte=2412)[:1] tile_id = themes[0].id if themes.count() else 0 cid = request.GET.get('cid') if tile_id: tile = get_object_or_404(Tile, pk=tile_id) else: try: tiles_all = Tile.objects.filter(new_category__id__startswith='24').exclude(new_category__id=2400) if cid: tiles_all = tiles_all.filter(new_category__id=cid) tile = tiles_all[0] except: data = {'status':False,'msg':"暂无主题内容"} return HttpResponse(json.dumps(data)) user = request.user tile.view_count += 1 tile.save() helpers.add_daily_record_visitor(user,tile) set_user_access(user) channel = request.GET.get("channel") type = request.GET.get("ty","") month = request.GET.get("month","") tpage = int(request.GET.get("tpage",1)) tiles = Tile.objects.filter(new_category_id__gt=2400,new_category_id__lte=2412) month_tiles = tiles.filter(new_category=tile.new_category)[0:3] month_tiles_pks = [m.id for m in month_tiles] year_tiles = tiles.order_by('-n_comments')[0:4] today = tile.start_time today_tiles = Tile.objects.get_tiles_date(date=today, tiles=tiles).order_by("-microsecond") try: next_day = Tile.objects.get_tiles_date_grater(date=today, tiles=tiles.filter(microsecond__gt=tile.microsecond,id__in=month_tiles_pks)).exclude(id=tile.id).order_by("microsecond") next_day = next_day[0] except: next_day = None try: yesterday = Tile.objects.get_tiles_date_less(date=today, tiles=tiles.filter(microsecond__lt=tile.microsecond,id__in=month_tiles_pks)).exclude(id=tile.id).order_by("-microsecond") yesterday = yesterday[0] except: yesterday = None is_last_page = True if tile.n_comments > 0: comments = Comment.objects.for_model(tile).select_related('user')\ .order_by("-submit_date").filter(is_public=True).filter(is_removed=False) if comments.count() > 5: comments = comments[0:5] is_last_page = False else: comments = None ctx = {} emo_config = helpers.emo_config() tile_all = [t for t in tiles] tile_order = tile_all.index(tile) # if tpage == (tile_order / 10) + 1: # order = (tile_order + 1) % 10 # else: # order = None if tpage == 1: tpage = (tile_order / 10) + 1 start = (tpage - 1) * 10 end = tpage * 10 is_last_tpage = True if end >= len(tile_all) else False tiles = tile_all[start:end] is_ajax = True if request.method == 'POST' else False ctx.update({"tile": tile, "cur_tile": tile, "today_tiles": today_tiles, "ty":type, "comments": comments,"year_tiles":year_tiles,\ "yesterday": yesterday, "next_day": next_day,"month": month,"channel": channel,"tpage":tpage,'month_tiles':month_tiles,\ "tiles": tiles,"emo_config":emo_config,'is_last_tpage':is_last_tpage,"is_last_page":is_last_page,'is_ajax':is_ajax}) if is_ajax: data = render(request, template_name,ctx) con=data.content return ajax_ok('成功',con) else: template_name = "kinger/revision/axis_theme_view_page.html" return render(request, template_name,ctx)
def tile_view(request, tile_id, template_name="kinger/revision/axis_tile_view.html"): """ 瓦片详情页, 会显示与该瓦片相关的今日记录, 根据分类过滤""" user = request.user if not user.is_authenticated(): data = json.dumps({'status':"error"}) return HttpResponse(data) tile = get_object_or_404(Tile, pk=tile_id) tile.view_count += 1 tile.save() helpers.add_daily_record_visitor(user,tile) set_user_access(user) channel = request.GET.get("channel") type = request.GET.get("ty","") month = request.GET.get("month","") tpage = int(request.GET.get("tpage",1)) if channel == "edu": tiles = Tile.objects.get_tiles_edu(user) elif channel == "life": tiles = Tile.objects.get_tiles_life(user) else: tiles = Tile.objects.get_tiles_baby(user).exclude(new_category_id=9) # 禁止访问其它用户的记录 if tile.creator != user: try: tiles.get(pk=tile_id) except ObjectDoesNotExist: if not tile.is_public: return render(request, "403.html") tiles = tiles.exclude(new_category_id__in=range(1130,1138)).order_by("-microsecond") recommends = Tile.objects.get_tiles_edu(user).order_by("-microsecond")[0:100] recommend_tiles = [recommends[i] for i in random.sample(range(100),4)] today = tile.start_time today_tiles = Tile.objects.get_tiles_date(date=today, tiles=tiles) daily_category = get_daily_category() if daily_category: today_tiles = today_tiles.exclude(new_category__parent=daily_category) today_tiles = today_tiles.order_by("-microsecond") try: next_day = Tile.objects.get_tiles_date_grater(date=today, tiles=tiles.filter(microsecond__gt=tile.microsecond)).exclude(id=tile.id).order_by("microsecond") next_day = next_day.exclude(new_category__parent=daily_category)[0] if daily_category else next_day[0] except: next_day = None try: yesterday = Tile.objects.get_tiles_date_less(date=today, tiles=tiles.filter(microsecond__lt=tile.microsecond)).exclude(id=tile.id).order_by("-microsecond") yesterday = yesterday.exclude(new_category__parent=daily_category)[0] if daily_category else yesterday[0] except: yesterday = None is_last_page = True if tile.n_comments > 0: comments = Comment.objects.for_model(tile).select_related('user')\ .order_by("-submit_date").filter(is_public=True).filter(is_removed=False) if comments.count() > 5: comments = comments[0:5] is_last_page = False else: comments = None ctx = {} emo_config = helpers.emo_config() tile_all = [t for t in tiles] try: tile_order = tile_all.index(tile) except: tile_order = 0 print tile_order,'ttttttttttttttttttt' # if tpage == (tile_order / 10) + 1: # order = (tile_order + 1) % 10 # else: order = (tile_order) % 10 print order,'oooooooooooooooooooooooooo' if tpage == 1: tpage = (tile_order / 10) + 1 start = (tpage - 1) * 10 end = tpage * 10 is_last_tpage = True if end >= len(tile_all) else False tiles = tile_all[start:end] is_ajax = True if request.method == 'POST' else False ctx.update({"tile": tile, "cur_tile": tile, "today_tiles": today_tiles, "ty":type, "comments": comments,\ "yesterday": yesterday, "next_day": next_day,"month": month,"channel": channel,"tpage":tpage,\ "tiles": tiles,"emo_config":emo_config,"order":order,'is_last_tpage':is_last_tpage,\ "is_last_page":is_last_page,"recommend_tiles":recommend_tiles,'is_ajax':is_ajax}) if is_ajax: data = render(request, template_name,ctx) con=data.content return ajax_ok('成功',con) else: template_name = "kinger/revision/tile_view.html" return render(request, template_name,ctx)