def code_to_img(value): """ [: :]格式的表情编码转换为<img>标签 """ 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 + "memory/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
def view(request, tile_id, template_name="memory/tile_view.html"): ctx = {} tile = get_object_or_404(Tile, pk=tile_id) q = request.GET.get("q",'') if not q: tiles = Tile.objects.filter(is_public=True) else: if q == 'all': friends = Friend.objects.all() userid_list = [f.user_id for f in friends] tiles = Tile.objects.filter(user_id__in=userid_list) else: tiles = Tile.objects.filter(user_id=q) try: last_tile = tiles.filter(microsecond__gt=tile.microsecond).order_by("start_time","microsecond")[0] except: last_tile = None try: next_tile = tiles.filter(microsecond__lt=tile.microsecond).order_by("-start_time","-microsecond")[0] except: next_tile = None comments = Comment.objects.for_model(tile).select_related('user')\ .order_by("-submit_date").filter(is_public=True).filter(is_removed=False) emo_config = helpers.emo_config() ctx.update({"tile": tile,"comments":comments,"emo_config":emo_config,"next_tile":next_tile,"last_tile":last_tile,"q":q}) return render(request, template_name, ctx)