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)
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
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
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)
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"
def hashid(self): """A mildly obfuscated identifier for this group""" return hashids.encode('h.groups', self.id)