Esempio n. 1
0
def group_detail(request, slug):
    group = get_object_or_404(Group, slug=slug)
    
    if not group.can_view(request.user):
        raise Http404()
        
    maps = GroupMap.maps_for_group(group)
    layers = GroupLayer.layers_for_group(group)
    
    if request.method == "POST":
        if group.user_is_member(request.user):
            group.leave(request.user)
            if group.access != "private":
                action.send(request.user, verb="left", target=group)
        else:
            group.join(request.user)
            if group.access != "private":
                action.send(request.user, verb="joined", target=group)
                
        return redirect("group_detail", group.slug)
        
    ctx = {
        "object": group,
        "maps": maps,
        "layers": layers,
        "members": group.member_queryset(),
        "is_member": group.user_is_member(request.user),
        "is_manager": group.user_is_role(request.user, "manager"),
    }
    ctx = RequestContext(request, ctx)
    return render_to_response("groups/group_detail.html", ctx)
Esempio n. 2
0
def group_add_maps(request, slug):
    group = get_object_or_404(Group, slug=slug)
    
    ctx = {}
    if request.method == "POST":
        form = GroupMapForm(request.POST)
        
        if form.is_valid():
            ctx["maps_added"] = []
            for m in form.cleaned_data["maps"]:
                GroupMap.objects.get_or_create(map=m, group=group)
                if group.access != "private":
                    action.send(request.user, verb="added map", action_object=m, target=group)
                ctx["maps_added"].append(m.title)
    else:
        form = GroupMapForm()
    
    current_maps = GroupMap.maps_for_group(group)
    
    form.fields["maps"].queryset = Map.objects.filter(
            owner=request.user
            ).exclude(
            id__in=[mi for mi in current_maps.values_list('id', flat=True)]
    )
    
    
    ctx["form"] = form
    ctx.update({
        "object": group,
        "members": group.member_queryset(),
        "is_member": group.user_is_member(request.user),
        "is_manager": group.user_is_role(request.user, "manager"),
        "current_maps": current_maps,
    })
    ctx = RequestContext(request, ctx)
    return render_to_response("groups/group_add_maps.html", ctx)