Exemplo 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)
Exemplo n.º 2
0
def group_add_layers(request, slug):
    group = get_object_or_404(Group, slug=slug)
    
    ctx = {}
    if request.method == "POST":
        form = GroupLayerForm(request.POST)
        
        if form.is_valid():
            ctx["layers_added"] = []
            for l in form.cleaned_data["layers"]:
                GroupLayer.objects.get_or_create(layer=l, group=group)
                if group.access != "private":
                    action.send(request.user, verb="added layer", action_object=l, target=group)
                ctx["layers_added"].append(l.title)
    else:
        form = GroupLayerForm()
    
    current_layers = GroupLayer.layers_for_group(group)
    
    form.fields["layers"].queryset = Layer.objects.filter(
            owner=request.user
            ).exclude(
            id__in=[li for li in current_layers.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_layers": current_layers,
    })
    ctx = RequestContext(request, ctx)
    return render_to_response("groups/group_add_layers.html", ctx)