示例#1
0
def edit(request, revision):
    """
    Edit package - only for the author
    """
    if request.user.pk != revision.author.pk:
        # redirecting to view mode without displaying an error
        messages.info(request,
                      "Not sufficient priviliges to edit the source. "
                      "You've been redirected to view mode.")

        return HttpResponseRedirect(
            reverse(
                "jp_%s_revision_details" % revision.package.get_type_name(),
                args=[revision.package.id_number, revision.revision_number])
        )
        #return HttpResponseForbidden('You are not the author of this Package')

    libraries = revision.dependencies.all()
    library_counter = len(libraries)
    sdk_list = None
    if revision.package.is_addon():
        library_counter += 1
        sdk_list = SDK.objects.exclude_disabled(current=revision.sdk.version)

    return render(request,
        "%s_edit.html" % revision.package.get_type_name(), {
            'revision': revision,
            'item': revision.package,
            'single': True,
            'libraries': libraries,
            'library_counter': library_counter,
            'readonly': False,
            'edit_mode': True,
            'sdk_list': sdk_list})
示例#2
0
文件: views.py 项目: zalun/FlightDeck
def view(request, revision):
    """
    Show package - read only
    """
    libraries = revision.dependencies.all()
    library_counter = len(libraries)
    if revision.package.is_addon():
        library_counter += 1

    # prepare the json for the Tree
    tree = simplejson.dumps(
        {
            "Lib": revision.get_modules_tree(),
            "Data": revision.get_attachments_tree(),
            "Plugins": revision.get_dependencies_tree(),
        }
    )

    return render(
        request,
        "%s_view.html" % revision.package.get_type_name(),
        {
            "revision": revision,
            "libraries": libraries,
            "library_counter": library_counter,
            "readonly": True,
            "tree": tree,
        },
    )
示例#3
0
文件: views.py 项目: zalun/FlightDeck
def get_revisions_list_html(request, revision_id):
    " returns revision list to be displayed in the modal window "
    current = get_object_with_related_or_404(PackageRevision, pk=revision_id)
    if not current.package.can_view(request.user):
        raise Http404
    revisions = current.package.revisions.all()
    revision_number = int(current.revision_number)
    return render(
        request,
        "_package_revisions_list.html",
        {"package": current.package, "revisions": revisions, "revision_number": revision_number, "current": current},
    )
示例#4
0
def browser(request, page_number=1, type_id=None, username=None):
    """
    Display a list of addons or libraries with pages
    Filter based on the request (type_id, username).
    """
    # calculate which template to use
    template_suffix = ''
    packages = Package.objects.active()

    author = None
    if username:
        try:
            profile = Profile.objects.get_user_by_username_or_nick(username)
        except ObjectDoesNotExist:
            raise Http404
        author = profile.user
        packages = packages.filter(author__pk=author.pk)
        template_suffix = '%s_user' % template_suffix
    if type_id:
        other_type = 'l' if type_id == 'a' else 'a'
        other_packages_number = len(packages.filter(type=other_type))
        packages = packages.filter(type=type_id)
        template_suffix = '%s_%s' % (template_suffix,
                                     settings.PACKAGE_PLURAL_NAMES[type_id])

    packages = packages.sort_recently_active()
    limit = request.GET.get('limit', settings.PACKAGES_PER_PAGE)

    try:
        pager = Paginator(
            packages,
            per_page=limit,
            orphans=1
        ).page(page_number)
    except (EmptyPage, InvalidPage):
        raise Http404

    packages = {
            "all_public_addons": author.packages_originated.addons().active().count(),
            "all_public_libraries": author.packages_originated.libraries().active().count()}
    return render(request,
        'package_browser%s.html' % template_suffix, {
            'pager': pager,
            'single': False,
            'author': author,
            'person': author,
            'packages': packages,
            'other_packages_number': other_packages_number
        })
示例#5
0
def get_revisions_list_html(request, id_number, revision_number=None):
    " returns revision list to be displayed in the modal window "
    package = get_object_with_related_or_404(Package, id_number=id_number)
    revisions = package.revisions.all()
    if revision_number:
        current = package.revisions.get(revision_number=revision_number)
    else:
        current = None
    if revision_number:
        revision_number = int(revision_number)
    return render(request,
        '_package_revisions_list.html', {
            'package': package,
            'revisions': revisions,
            'revision_number': revision_number,
            'current': current})
示例#6
0
def view(request, revision):
    """
    Show package - read only
    """
    libraries = revision.dependencies.all()
    library_counter = len(libraries)
    if revision.package.is_addon():
        library_counter += 1

    # prepare the json for the Tree
    tree = simplejson.dumps({'Lib': revision.get_modules_tree(),
            'Data': revision.get_attachments_tree(),
            'Plugins': revision.get_dependencies_tree()})

    return render(request,
        "%s_view.html" % revision.package.get_type_name(), {
            'revision': revision,
            'libraries': libraries,
            'library_counter': library_counter,
            'readonly': True,
            'tree': tree
        })