コード例 #1
0
ファイル: views.py プロジェクト: ningyifan/h
def _join(request, group):
    """Return the rendered "Join this group" page.

    This is the page that's shown when a user who is not a member of a group
    visits the group's URL.

    """
    hashid = hashids.encode(request, 'h.groups', number=group.id)
    join_url = request.route_url('group_read', hashid=hashid, slug=group.slug)
    template_data = {'group': group, 'join_url': join_url}
    return renderers.render_to_response(
        renderer_name='h:groups/templates/join.html.jinja2',
        value=template_data, request=request)
コード例 #2
0
def _join(request, group):
    """Return the rendered "Join this group" page.

    This is the page that's shown when a user who is not a member of a group
    visits the group's URL.

    """
    hashid = hashids.encode(request, 'h.groups', number=group.id)
    join_url = request.route_url('group_read', hashid=hashid, slug=group.slug)
    template_data = {'group': group, 'join_url': join_url}
    return renderers.render_to_response(
        renderer_name='h:groups/templates/join.html.jinja2',
        value=template_data,
        request=request)
コード例 #3
0
ファイル: session.py プロジェクト: ningyifan/h
def _current_groups(request):
    """Return a list of the groups the current user is a member of.

    This list is meant to be returned to the client in the "session" model.

    """
    groups = []
    userid = request.authenticated_userid
    if userid is None:
        return groups
    user = models.User.get_by_userid(request.domain, userid)
    if user is None:
        return groups
    for group in user.groups:
        hid = hashids.encode(request, 'h.groups', group.id)
        groups.append({
            'name': group.name,
            'url': request.route_url(
                'group_read', hashid=hid, slug=group.slug),
        })
    return groups
コード例 #4
0
def _current_groups(request):
    """Return a list of the groups the current user is a member of.

    This list is meant to be returned to the client in the "session" model.

    """
    groups = []
    userid = request.authenticated_userid
    if userid is None:
        return groups
    user = models.User.get_by_userid(request.domain, userid)
    if user is None:
        return groups
    for group in user.groups:
        hid = hashids.encode(request, 'h.groups', group.id)
        groups.append({
            'name':
            group.name,
            'url':
            request.route_url('group_read', hashid=hid, slug=group.slug),
        })
    return groups
コード例 #5
0
ファイル: logic.py プロジェクト: apurvajalit/h
def url_for_group(request, group):
    """Return the URL for the given group's page."""
    hashid = hashids.encode(request, "h.groups", number=group.id)
    return request.route_url('group_read', hashid=hashid, slug=group.slug)
コード例 #6
0
ファイル: hashids_test.py プロジェクト: plainspace/h
def test_hashids_encode():
    assert hashids.encode("foo", 1) == "1V91V4"
    assert hashids.encode("bar", 1) == "E8Rz8D"
    assert hashids.encode("foo", 123) == "Lgq4nK"
    assert hashids.encode("foo", 1, 2, 3) == "zvuvt2"
コード例 #7
0
ファイル: models.py プロジェクト: dezynetechnologies/h
 def hashid(self):
     """A mildly obfuscated identifier for this group"""
     return hashids.encode('h.groups', self.id)
コード例 #8
0
def url_for_group(request, group):
    """Return the URL for the given group's page."""
    hashid = hashids.encode(request, "h.groups", number=group.id)
    return request.route_url('group_read', hashid=hashid, slug=group.slug)