예제 #1
0
def code_to_img(value):
    """
    [: :]格式的表情编码转换为<img>标签
    """
    value = value.replace("<","&lt")
    value = value.replace(">","&gt")
    match = re.findall(r'\[:(\d{3})\:]',value)
    if match:
        for i in range(len(match)):
            pic_num = str(int(match[i]))
            strinfo = re.compile(r'\[:('+match[i]+')\:]')
            url = settings.STATIC_URL +'kinger/img/emo/emo/'+ pic_num +'.png'
            b = strinfo.sub('<img src='+url+'>',value)
            value = b
    
    emo = re.findall(r'\[(.*?)\]',value)
    if emo:
        for e in emo:
            
            try:
                pic_url = helpers.emo_config().get(str(e))['url']
            except:
                pic_url = ''
            if pic_url:
                strinfo = re.compile(r'\[('+e+')\]')
                b = strinfo.sub('<img src='+pic_url+'>',value)
                value = b
    
    return value
예제 #2
0
def view(request, tile_id, template_name="kinger/tile_view.html"):
    """ 瓦片详情页, 会显示与该瓦片相关的今日记录, 根据分类过滤"""
    tile = get_object_or_404(Tile, pk=tile_id)
    user = request.user
    tile.view_count += 1
    tile.save()
    add_daily_record_visitor(user,tile)
#    add_tile_visitor(user,tile)
    set_user_access(user)
    
    channel = request.session.get("kinger_channel")
    channel = request.GET.get("channel")
    type = request.GET.get("ty","")
    month = request.GET.get("month","")

    if channel == "tips":
        tiles = Tile.objects.get_tiles_edu(user)
        tiles = Tile.objects.filter(category__is_tips=True)

    elif channel == "all":
        tiles = Tile.objects.get_tiles_all_login(user)

    else:
        tiles = Tile.objects.get_tiles_baby(user)        
        # 禁止访问其它用户的记录
        if tile.creator != user:
            try:
                tiles.get(pk=tile_id)
            except ObjectDoesNotExist:
                if not tile.is_public:
                    return render(request, "403.html")

    today = tile.pub_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(category__parent=daily_category)
    today_tiles = today_tiles.order_by("-start_time","-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("start_time","microsecond")
        next_day = next_day.exclude(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("-start_time","-microsecond")
        yesterday = yesterday.exclude(category__parent=daily_category)[0] if daily_category else yesterday[0]       
    except:
        yesterday = None
        
    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)
    else:
        comments = None
        
    ctx = {}
    # content_type = ContentType.objects.get_for_model(Tile)

    # 单击分页
    #tile_pk_list = [t.pk for t in today_tiles]
    #p = Paginator(today_tiles,15)

    # 有可能来自不同频道,而没有找到
    #try:
        #p_index = tile_pk_list.index(tile.pk)//15 + 1
    #except:
        #messages.error(request, '请转换到全部')
       # p_index = 1

    #today_tiles = p.page(p_index)
    emo_config = helpers.emo_config()

    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,"emo_config":emo_config})
    return render(request, template_name, ctx)
예제 #3
0
파일: axis.py 프로젝트: nuannuanwu/weixiao
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)
예제 #4
0
def get_emo_config(context):
    return helpers.emo_config()
예제 #5
0
파일: axis.py 프로젝트: nuannuanwu/weixiao
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)