示例#1
0
def done(request):
#     can_view_pkgs = request.user.has_perm('pkgs.can_view_pkgs')
#     can_view_manifests = request.user.has_perm('manifests.can_view_manifests')
#     can_view_catalogs = request.user.has_perm('catalogs.can_view_catalogs')
#     change_pkgs = request.user.has_perm('pkgs.change_pkgs')
#     delete_pkgs = request.user.has_perm('pkgs.delete_pkgs')
    if request.method == 'POST': # If the form has been submitted...
        final_items_to_move = request.POST.getlist('final_items_to_move[]')
        confirm_move = request.POST.get('confirm_move')
        confirm_add = request.POST.get('confirm_add')
        confirm_remove = request.POST.get('confirm_remove')
        new_dest_catalog = request.POST.get('new_dest_catalog')
        if new_dest_catalog:
            new_dest_catalog = new_dest_catalog.lower()
        tuple(final_items_to_move)
        for n,pkg in enumerate(final_items_to_move):
            pkg = pkg.split('___')
            final_items_to_move[n] = pkg
        if confirm_remove:
            for pkg_name, pkg_version, pkg_orig in final_items_to_move:
                if pkg_orig != 'no-catalog':
                    Packages.remove(pkg_name, pkg_version, pkg_orig, request.user)
        elif confirm_add:
            for pkg_name, pkg_version, pkg_orig, pkg_catalog in final_items_to_move:
                if pkg_orig == 'no-catalog':
                    if pkg_catalog == 'set-new' and new_dest_catalog:
                        Packages.move(pkg_name, pkg_version, new_dest_catalog, 
                                      request.user)
                    elif pkg_catalog != 'set-new':
                        Packages.move(pkg_name, pkg_version, pkg_catalog, request.user)
                else:
                    if pkg_catalog == 'set-new' and new_dest_catalog:
                        Packages.add(pkg_name, pkg_version, pkg_orig, new_dest_catalog, 
                                     request.user)
                    elif pkg_catalog != 'set-new':
                        Packages.add(pkg_name, pkg_version, pkg_orig, pkg_catalog, 
                                     request.user)
        else:
            for pkg_name, pkg_version, pkg_catalog in final_items_to_move:
                if new_dest_catalog:
#                    pkg_catalog = new_dest_catalog
                    Packages.move(pkg_name, pkg_version, new_dest_catalog, request.user)
                elif pkg_catalog != 'set-new':
                    Packages.move(pkg_name, pkg_version, pkg_catalog, request.user)
        Packages.makecatalogs(request.user)
        c = RequestContext(request, {'user': request.user,
                   'final_items_to_move': final_items_to_move,
                   'confirm_move': confirm_move,
                   'confirm_add': confirm_add,
                   'confirm_remove': confirm_remove,
#                    'can_view_pkgs': can_view_pkgs,
#                    'can_view_manifests': can_view_manifests,
#                    'can_view_catalogs': can_view_catalogs,
#                    'change_pkgs': change_pkgs,
#                    'delete_pkgs': delete_pkgs,
                   'done': 'Done',
                   'page': 'pkgs'})
        return render_to_response('pkgs/done.html', c)
    else:
        return HttpResponse("No form submitted.\n")
示例#2
0
def done(request):
    if request.method == 'POST': # If the form has been submitted...
        final_items_to_move = request.POST.getlist('final_items_to_move[]')
        confirm_move = request.POST.get('confirm_move')
        confirm_add = request.POST.get('confirm_add')
        confirm_remove = request.POST.get('confirm_remove')
        new_dest_catalog = request.POST.get('new_dest_catalog')
        if new_dest_catalog:
            new_dest_catalog = new_dest_catalog.lower()
        tuple(final_items_to_move)
        for n,pkg in enumerate(final_items_to_move):
            pkg = pkg.split('___')
            final_items_to_move[n] = pkg
        if confirm_remove:
            for pkg_name, pkg_version, pkg_orig in final_items_to_move:
                if pkg_orig != 'no-catalog':
                    Packages.remove(pkg_name, pkg_version, pkg_orig)
        elif confirm_add:
            for pkg_name, pkg_version, pkg_orig, pkg_catalog in final_items_to_move:
                if pkg_orig == 'no-catalog':
                    if pkg_catalog == 'set-new' and new_dest_catalog:
                        Packages.move(pkg_name, pkg_version, new_dest_catalog)
                    elif pkg_catalog != 'set-new':
                        Packages.move(pkg_name, pkg_version, pkg_catalog)
                else:
                    if pkg_catalog == 'set-new' and new_dest_catalog:
                        Packages.add(pkg_name, pkg_version, pkg_orig, new_dest_catalog)
                    elif pkg_catalog != 'set-new':
                        Packages.add(pkg_name, pkg_version, pkg_orig, pkg_catalog)
        else:
            for pkg_name, pkg_version, pkg_catalog in final_items_to_move:
                if new_dest_catalog:
                    pkg_catalog = new_dest_catalog
                elif pkg_catalog != 'set-new':
                    Packages.move(pkg_name, pkg_version, pkg_catalog)
        Packages.makecatalogs()
        context = {'user': request.user,
                   'final_items_to_move': final_items_to_move,
                   'confirm_move': confirm_move,
                   'confirm_add': confirm_add,
                   'confirm_remove': confirm_remove,
                   'done': 'Done',
                   'page': 'pkgs'}
        return render_to_response('pkgs/done.html', context)
    else:
        return HttpResponse("No form submitted.\n")