コード例 #1
0
ファイル: helpers.py プロジェクト: ChrysalisTeam/pychronia
def game_file_url_tag(context, a="", b="", c="", d="", e="", f="", varname=None):
    """
    Here "varname" is the varuiable under which to store the result, if any.
    """
    assert not isinstance(context, basestring)
    rel_path = "".join((a, b, c, d, e, f))
    full_url = real_game_file_url(rel_path)
    if varname is not None:
        assert varname, "wrong game_file_url varname %s" % varname
        context[varname] = full_url
        return ""
    else:
        return full_url
コード例 #2
0
ファイル: helpers.py プロジェクト: akram-max/pychronia
def _try_generating_thumbnail_url(rel_path, alias=None):
    """
    Falls back to original fail url if thumbnail generation fails, or if no alias is provided.
    """
    if alias:
        try:
            thumb = get_game_thumbnailer(rel_path)[
                alias]  # we enforce the GAME_FILES storage here!
            return thumb.url
        except Exception as e:
            logging.warning("Error generating game_file_img %s (alias=%s): %r",
                            rel_path, alias, e)
            pass  # fallback to plain file

    return real_game_file_url(rel_path)  # original image
コード例 #3
0
ファイル: helpers.py プロジェクト: akram-max/pychronia
def game_file_url_tag(context,
                      a="",
                      b="",
                      c="",
                      d="",
                      e="",
                      f="",
                      varname=None):
    """
    Here "varname" is the varuiable under which to store the result, if any.
    """
    assert not isinstance(context, str)
    rel_path = "".join((a, b, c, d, e, f))
    full_url = real_game_file_url(rel_path)
    if varname is not None:
        assert varname, "wrong game_file_url varname %s" % varname
        context[varname] = full_url
        return ""
    else:
        return full_url
コード例 #4
0
ファイル: helpers.py プロジェクト: akram-max/pychronia
 def _replacer(match_obj):
     rel_path = match_obj.group("path")
     fullpath = real_game_file_url(rel_path)
     return fullpath
コード例 #5
0
ファイル: helpers.py プロジェクト: ChrysalisTeam/pychronia
 def _replacer(match_obj):
     rel_path = match_obj.group("path")
     fullpath = real_game_file_url(rel_path)
     return fullpath
コード例 #6
0
ファイル: helpers.py プロジェクト: ChrysalisTeam/pychronia
GAME_LOCAL_TZ = config.GAME_LOCAL_TZ # real timezone object


def _try_generating_thumbnail_url(rel_path, alias=None):
    """
    Falls back to original fail url if thumbnail generation fails, or if no alias is provided.
    """
    if alias:
        try:
            thumb = get_game_thumbnailer(rel_path)[alias] # we enforce the GAME_FILES storage here!
            return thumb.url
        except Exception, e:
            logging.warning("Error generating game_file_img %s (alias=%s): %r", rel_path, alias, e)
            pass # fallback to plain file

    return real_game_file_url(rel_path) # original image



@register.simple_tag(takes_context=False)
def first_non_empty(*args):
    for arg in args:
        if arg:
            return arg
    return ""


@register.simple_tag(takes_context=False)
def random_id():
    """Tag to generate random ids in HTML tags, just to please javascript utilities."""
    return "uuid-" + str(random.randint(1000000, 1000000000))