Ejemplo n.º 1
0
def _group_external_link_only_edit(request, group):
    external_link = group.external_link() # This will return None if it's not set yet
    group_form = None
    link_form = None

    if request.method == "POST":
        if "change_group" in request.POST:
            group_form = GroupExternalLinkOnlyForm(request.POST, request.FILES, instance=group)
            link_form = ExternalLinkForm(request.POST, request.FILES, instance=external_link)
            if group_form.is_valid() and link_form.is_valid():
                group = group_form.save()
                link = link_form.save(group)
                messages.success(request, _("%(group)s has been updated.") % {'group': group})
                return redirect("group_edit", group_slug=group.slug)
        elif "upgrade_group" in request.POST:
            group.is_external_link_only = False
            group.save()
            messages.success(request, _("%(group)s has been upgraded.") % {'group': group})
            return redirect("group_edit", group_slug=group.slug)
        elif "delete_group" in request.POST:
            group.delete()
            messages.success(request, _("%(group)s has been deleted.") % {'group': group})
            return redirect("group_list")

    group_form = group_form or GroupExternalLinkOnlyForm(instance=group)
    link_form = link_form or ExternalLinkForm(instance=external_link)
    site = Site.objects.get_current()
    external_group = True
    return render_to_response("groups/group_external_link_only_edit.html", locals(),
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def group_external_link_only_create(request):
    """
    create a form a user can use to create a minimal group which is added to the map
    but does not offer any features, since it has a home somewhere else on the web.
    on POST save this group to the database and automatically add the creator
    to the said group as a manager.
    """
    nav_selected = "communities"
    if request.method == "POST":
        form = GroupExternalLinkOnlyForm(request.POST, request.FILES)
        link_form = ExternalLinkForm(request.POST, request.FILES)
        if form.is_valid() and link_form.is_valid():
            group = form.save()
            link = link_form.save(group)
            GroupUsers.objects.create(group=group, user=request.user, is_manager=True)
            Stream.objects.get(slug="external-community-create").enqueue(content_object=group, start=group.created)
            Record.objects.create_record(request.user, 'group_create', group)
            badge_cache.possibly_award_badge('created_a_community', user=request.user)
            messages.success(request, _("%(group)s has been created.") % {
                    'group': group})
            return redirect("group_detail", group_slug=group.slug)
    else:
        form = GroupExternalLinkOnlyForm()
        link_form = ExternalLinkForm()
    return render_to_response("groups/group_create.html", {
        "form": form,
        "link_form": link_form,
        "site": Site.objects.get_current(),
        "nav_selected": nav_selected,
        'external_group': True,
    }, context_instance=RequestContext(request))
Ejemplo n.º 3
0
def group_external_link_form(request, group_id, link_type=None):
    nav_selected = "communities"
    group = get_object_or_404(Group, id=group_id)
    if not group.is_user_manager(request.user):
        return forbidden(request)

    instance = None
    if link_type == "twitter":
        instance = group.twitter_link()
    elif link_type == "facebook":
        instance = group.facebook_link()

    if request.method == "POST":
        form = ExternalLinkForm(request.POST, instance=instance)
        if form.is_valid():
            link = form.save(group=group)
            return redirect(group)
    else:
        form = ExternalLinkForm(instance=instance)

    template = "group_links/_form.html" if request.is_ajax() \
        else "group_links/form.html"
    return render_to_response(template, locals(), 
                              context_instance=RequestContext(request))