def user_profile(request, up): tn = 'vns/user_profile.html' topos_allowed = permissions.get_allowed_topologies(request.user) topos_owned = topos_allowed.filter(owner=up.user) topos_assigned = topos_allowed.filter(allowed_users=up.user) can_change = permissions.allowed_user_access_change(request.user, up.user) return direct_to_template(request, tn, {'up':up, 'can_change':can_change, 'topos_owned':topos_owned, 'topos_assigned':topos_assigned})
def topologies_list(request): # Get a QuerySet of the topologies we have access to topos = permissions.get_allowed_topologies(request.user) # Order the topologies by organization topos = topos.order_by('owner__userprofile__org__name', 'owner__username', 'template__name', 'id') orgs = {} # count the number of times each org/owner/template appears for t in topos: v, owners = orgs.get(t.owner.get_profile().org.name, (0,{})) orgs[t.owner.get_profile().org.name] = (v + 1, owners) v, templates = owners.get(t.owner.username, (0,{})) owners[t.owner.username] = (v + 1, templates) v = templates.get(t.template.name, 0) templates[t.template.name] = v + 1 # embed counts of how many of the next orgs/owners/templates are the same as # the first one in each streak of these (hierarchical); 0 if not first pon = pun = ptn = None for t in topos: on = t.owner.get_profile().org.name un = t.owner.username tn = t.template.name t.org_num = t.owner_num = t.template_num = 0 if on != pon: pun = None t.org_num, owners = orgs[on] if un != pun: ptn = None t.owner_num, templates = owners[un] if tn != ptn: t.template_num = templates[tn] pon = on pun = un ptn = tn return direct_to_template(request, 'vns/topologies.html', {'topos_list':topos})
def get_usable_topologies(self): """Returns the topologies which this user is permitted to use beyond those owned by the user.""" return permissions.get_allowed_topologies(self.user)