Пример #1
0
def add_package(request, template_name="package/package_form.html"):

    if not request.user.get_profile().can_add_package:
        return HttpResponseForbidden("permission denied")

    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)

    package_extenders = build_package_extenders(request)

    if form.is_valid():
        new_package = form.save()
        new_package.created_by = request.user
        new_package.last_modified_by = request.user
        new_package.save()
        new_package.fetch_metadata()

        # stick in package_extender form processing
        for package_extender in package_extenders:
            if package_extender['form'].is_valid():
                package_extender['form'].save()
        return HttpResponseRedirect(reverse("package", kwargs={"slug": new_package.slug}))

    return render(request, template_name, {
        "form": form,
        "repo_data": repo_data_for_js(),
        "action": "add",
        "package_extenders": package_extenders
        })
Пример #2
0
def edit_package(request, slug, template_name="package/package_form.html"):
    
    if not request.user.get_profile().can_edit_package:
        return HttpResponseForbidden("permission denied")

    package = get_object_or_404(Package, slug=slug)
    form = PackageForm(request.POST or None, instance=package)
    
    package_extenders = build_package_extenders(request)    
    
    if form.is_valid():
        modified_package = form.save()
        modified_package.last_modified_by = request.user
        modified_package.save()    
        # stick in package_extender form processing
        for package_extender in package_extenders:
            if package_extender['form'].is_valid():
                package_extender['form'].save()            
        return HttpResponseRedirect(reverse("package", kwargs={"slug": modified_package.slug}))
    
    return render(request, template_name, {
        "form": form,
        "package": package,
        "repo_data": repo_data_for_js(),
        "action": "edit",
        })
Пример #3
0
def add_new_grid_package(request, grid_slug, template_name="package/package_form.html"):
    """Add a package to a grid that isn't yet represented on the site."""
    
    if not request.user.get_profile().can_add_grid_package:
        return HttpResponseForbidden("permission denied")

    grid = get_object_or_404(Grid, slug=grid_slug)
    
    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)
    
    if form.is_valid():
        new_package = form.save()
        GridPackage.objects.create(
            grid=grid, 
            package=new_package
        )
        return HttpResponseRedirect(reverse("grid", kwargs={"slug":grid_slug}))
    
    return render_to_response(template_name, {
        "form": form,
        "repo_data": repo_data_for_js(),
        "action": "add",
        },
        context_instance=RequestContext(request))
Пример #4
0
def add_package(request, template_name="package/package_form.html"):

    if not request.user.get_profile().can_add_package:
        return HttpResponseForbidden("permission denied")

    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)

    package_extenders = build_package_extenders(request)

    if form.is_valid():
        new_package = form.save()
        new_package.created_by = request.user
        new_package.last_modified_by = request.user
        new_package.save()
        new_package.fetch_metadata()
        new_package.fetch_commits()

        # stick in package_extender form processing
        for package_extender in package_extenders:
            if package_extender["form"].is_valid():
                package_extender["form"].save()
        return HttpResponseRedirect(reverse("package", kwargs={"slug": new_package.slug}))

    return render(
        request,
        template_name,
        {"form": form, "repo_data": repo_data_for_js(), "action": "add", "package_extenders": package_extenders},
    )
Пример #5
0
def add_new_grid_package(request,
                         grid_slug,
                         template_name="package/package_form.html"):
    """Add a package to a grid that isn't yet represented on the site."""

    if not request.user.get_profile().can_add_grid_package:
        return HttpResponseForbidden("permission denied")

    grid = get_object_or_404(Grid, slug=grid_slug)

    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)

    if form.is_valid():
        new_package = form.save()
        GridPackage.objects.create(grid=grid, package=new_package)
        return HttpResponseRedirect(reverse("grid", kwargs={"slug":
                                                            grid_slug}))

    return render_to_response(template_name, {
        "form": form,
        "repo_data": repo_data_for_js(),
        "action": "add",
    },
                              context_instance=RequestContext(request))
Пример #6
0
def edit_package(request, slug, template_name="package/package_form.html"):

    if not request.user.get_profile().can_edit_package:
        return HttpResponseForbidden("permission denied")

    package = get_object_or_404(Package, slug=slug)
    form = PackageForm(request.POST or None, instance=package)

    package_extenders = build_package_extenders(request)

    if form.is_valid():
        modified_package = form.save()
        modified_package.last_modified_by = request.user
        modified_package.save()
        # stick in package_extender form processing
        for package_extender in package_extenders:
            if package_extender['form'].is_valid():
                package_extender['form'].save()
        return HttpResponseRedirect(reverse("package", kwargs={"slug": modified_package.slug}))

    return render(request, template_name, {
        "form": form,
        "package": package,
        "repo_data": repo_data_for_js(),
        "action": "edit",
        })
Пример #7
0
def edit_package(request, slug, template_name="package/package_form.html"):
    package = get_object_or_404(Project, slug=slug)
    if not request.user.profile.can_edit_package(package):
        return HttpResponseForbidden("permission denied")

    form = PackageForm(request.POST or None, instance=package)

    initial = [{
        'role': tm.role,
        'account_name': tm.account.name,
        'account_type': tm.account.type,
        'role_confirmed_by_account': tm.role_confirmed_by_account,
        'initialized': True,
    } for tm in package.teammembership_set.all()]
    if request.POST:
        formset = TeamMembersFormSet(request.POST)
    else:
        formset = TeamMembersFormSet(initial=initial)

    formset.extra = 0

    if form.is_valid() and formset.is_valid():
        modified_package = form.save()
        modified_package.last_modified_by = request.user
        modified_package.save()

        for inlineform in formset:
            if hasattr(inlineform, 'cleaned_data') and inlineform.cleaned_data:
                data = inlineform.cleaned_data

                account_type = AccountType.objects.get(
                    name=data['account_type'])

                if data['DELETE']:
                    account = Account.objects.get(account_type=account_type,
                                                  name=data['account_name'])
                    membership = TeamMembership.objects.get(
                        account=account, project=modified_package)
                    membership.delete()
                else:
                    account, __ = Account.objects.get_or_create(
                        account_type=account_type, name=data['account_name'])
                    membership, __ = TeamMembership.objects.get_or_create(
                        account=account, project=modified_package)
                    membership.role = data['role']
                    membership.save()

        messages.add_message(request, messages.INFO,
                             'Project updated successfully')
        return HttpResponseRedirect(
            reverse("package", kwargs={"slug": modified_package.slug}))

    return render(
        request, template_name, {
            "form": form,
            "formset": formset,
            "package": package,
            "repo_data": repo_data_for_js(),
            "action": "Save",
        })
Пример #8
0
def add_package(request, template_name="package/package_form.html"):
    
    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)
    
    if form.is_valid():
        new_package = form.save()
        return HttpResponseRedirect(reverse("package", kwargs={"slug":new_package.slug}))
    
    return render_to_response(template_name, {
        "form": form,
        "repos": repos_for_js(),
        "action": "add",
        },
        context_instance=RequestContext(request))
Пример #9
0
def edit_package(request, slug, template_name="package/package_form.html"):
    
    package = get_object_or_404(Package, slug=slug)
    form = PackageForm(request.POST or None, instance=package)
    
    if form.is_valid():
        form.save()
        return HttpResponseRedirect(reverse("package", kwargs={"slug": package.slug}))
    
    return render_to_response(template_name, {
        "form": form,
        "package": package,
        "repos": repos_for_js(),
        "action": "edit",
        },
        context_instance=RequestContext(request))
Пример #10
0
def add_package(request, template_name="package/package_form.html"):

    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)

    if form.is_valid():
        new_package = form.save()
        new_package.created_by = request.user
        new_package.last_modified_by = request.user
        new_package.save()
        new_package.fetch_metadata()
        return HttpResponseRedirect(reverse("package", kwargs={"slug": new_package.slug}))

    return render_to_response(
        template_name,
        {"form": form, "repo_data": repo_data_for_js(), "action": "add"},
        context_instance=RequestContext(request),
    )
Пример #11
0
def add_package(request, template_name="package/package_form.html"):

    if not request.user.profile.can_add_package:
        return HttpResponseForbidden("permission denied")

    new_package = Project()
    form = PackageForm(request.POST or None, instance=new_package)
    formset = TeamMembersFormSet(request.POST or None)

    if form.is_valid() and formset.is_valid():
        new_package = form.save()
        new_package.draft_added_by = request.user
        new_package.last_modified_by = request.user
        new_package.save()
        rebuild_project_search_index(new_package)
        #new_package.fetch_metadata()
        #new_package.fetch_commits()

        for inlineform in formset:
            if hasattr(inlineform, 'cleaned_data') and inlineform.cleaned_data:
                data = inlineform.cleaned_data

                account_type = AccountType.objects.get(
                    name=data['account_type'])
                account, created = Account.objects.get_or_create(
                    account_type=account_type, name=data['account_name'])

                membership = TeamMembership.objects.create(account=account,
                                                           project=new_package,
                                                           role=data['role'])
                membership.save()

        return HttpResponseRedirect(
            reverse("package", kwargs={"slug": new_package.slug}))

    return render(
        request, template_name, {
            "form": form,
            "formset": formset,
            "repo_data": repo_data_for_js(),
            "action": "add",
        })
Пример #12
0
def add_package(request, template_name="package/package_form.html"):

    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)

    if form.is_valid():
        new_package = form.save()
        new_package.created_by = request.user
        new_package.last_modified_by = request.user
        new_package.save()
        new_package.fetch_metadata()
        return HttpResponseRedirect(
            reverse("package", kwargs={"slug": new_package.slug}))

    return render_to_response(template_name, {
        "form": form,
        "repo_data": repo_data_for_js(),
        "action": "add",
    },
                              context_instance=RequestContext(request))
Пример #13
0
def edit_package(request, slug, template_name="package/package_form.html"):

    package = get_object_or_404(Package, slug=slug)
    form = PackageForm(request.POST or None, instance=package)

    if form.is_valid():
        modified_package = form.save()
        modified_package.last_modified_by = request.user
        modified_package.save()

        return HttpResponseRedirect(
            reverse("package", kwargs={"slug": modified_package.slug}))

    return render_to_response(template_name, {
        "form": form,
        "package": package,
        "repo_data": repo_data_for_js(),
        "action": "edit",
    },
                              context_instance=RequestContext(request))
Пример #14
0
def edit_package(request, slug, template_name="package/package_form.html"):

    if not request.user.get_profile().can_edit_package:
        return HttpResponseForbidden("permission denied")

    package = get_object_or_404(Package, slug=slug)
    form = PackageForm(request.POST or None, instance=package)

    if form.is_valid():
        modified_package = form.save()
        modified_package.last_modified_by = request.user
        modified_package.save()
        messages.add_message(request, messages.INFO, 'Package updated successfully')
        return HttpResponseRedirect(reverse("package", kwargs={"slug": modified_package.slug}))

    return render(request, template_name, {
        "form": form,
        "package": package,
        "repo_data": repo_data_for_js(),
        "action": "edit",
        })
Пример #15
0
def add_new_grid_package(request,
                         grid_slug,
                         template_name="package/package_form.html"):

    grid = get_object_or_404(Grid, slug=grid_slug)

    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)

    if form.is_valid():
        new_package = form.save()
        GridPackage.objects.create(grid=grid, package=new_package)
        return HttpResponseRedirect(reverse("grid", kwargs={"slug":
                                                            grid_slug}))

    return render_to_response(template_name, {
        "form": form,
        "repos": repos_for_js(),
        "action": "add",
    },
                              context_instance=RequestContext(request))
Пример #16
0
def add_new_grid_package(request, grid_slug, template_name="package/package_form.html"):
    
    grid = get_object_or_404(Grid, slug=grid_slug)
    
    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)
    
    if form.is_valid():
        new_package = form.save()
        GridPackage.objects.create(
            grid=grid, 
            package=new_package
        )
        return HttpResponseRedirect(reverse("grid", kwargs={"slug":grid_slug}))
    
    return render_to_response(template_name, {
        "form": form,
        "repo_data": repo_data_for_js(),
        "action": "add",
        },
        context_instance=RequestContext(request))
Пример #17
0
def edit_package(request, slug, template_name="package/package_form.html"):

    if not request.user.profile.can_edit_package:
        return HttpResponseForbidden("permission denied")

    package = get_object_or_404(Package, slug=slug)
    form = PackageForm(request.POST or None, instance=package)

    if form.is_valid():
        modified_package = form.save()
        modified_package.last_modified_by = request.user
        modified_package.save()
        messages.add_message(request, messages.INFO, 'Package updated successfully')
        return HttpResponseRedirect(reverse("package", kwargs={"slug": modified_package.slug}))

    return render(request, template_name, {
        "form": form,
        "package": package,
        "repo_data": repo_data_for_js(),
        "action": "edit",
        })
Пример #18
0
def add_package(request, template_name="package/package_form.html"):

    if not request.user.profile.can_add_package:
        return HttpResponseForbidden("permission denied")

    new_package = Package()
    form = PackageForm(request.POST or None, instance=new_package)

    if form.is_valid():
        new_package = form.save()
        new_package.created_by = request.user
        new_package.last_modified_by = request.user
        new_package.save()
        #new_package.fetch_metadata()
        #new_package.fetch_commits()

        return HttpResponseRedirect(reverse("package", kwargs={"slug": new_package.slug}))

    return render(request, template_name, {
        "form": form,
        "repo_data": repo_data_for_js(),
        "action": "add",
        })