django.shortcuts.get_list_or_404

Here are the examples of the python api django.shortcuts.get_list_or_404 taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

11 Examples 7

Example 1

Project: classic.rhizome.org Source File: views.py
Function: today
def today(request):
    posts = get_list_or_404(Post, slug='rhizome-today', status__gte=Post.PUBLIC, 
                            publish__lte=datetime.datetime.now())
    post = posts[0]

    year = post.publish.strftime('%Y')
    month = post.publish.strftime('%b')
    day = post.publish.strftime('%d')

    return post_detail(request, post.slug, 
                       year, month, day)

Example 2

Project: patchwork Source File: series.py
    def get(self, request, *args, **kwargs):
        series = get_object_or_404(Series, pk=kwargs['series'])
        revisions = get_list_or_404(SeriesRevision, series=series)
        for revision in revisions:
            revision.patch_list = revision.ordered_patches().\
                select_related('state', 'submitter')
            revision.test_results = TestResult.objects \
                    .filter(revision=revision, patch=None) \
                    .order_by('test__name').select_related('test')

        return render(request, 'patchwork/series.html', {
            'series': series,
            'project': series.project,
            'cover_letter': revision.cover_letter,
            'revisions': revisions,
        })

Example 3

Project: eve-wspace Source File: views.py
Function: kick_member
@require_boss()
def kick_member(request, fleetID, memberID):
    """
    Removes a member from the fleet.
    """
    if not request.is_ajax():
        raise PermissionDenied

    fleet = get_object_or_404(Fleet, pk=fleetID)
    member = get_list_or_404(fleet.members, leavetime=None, user__pk=memberID)
    for mem in member:
        fleet.leave_fleet(mem.user)
    return HttpResponse()

Example 4

Project: Asteroid Source File: views.py
Function: list_commands
def list_commands(request):
    "list all the available commands in the system"
    # if none exist throw a 404
    commands = get_list_or_404(Command)
    context = {
        'commands': commands,
    }
    return render_to_response('list_commands.html', context,
        context_instance=RequestContext(request))

Example 5

Project: addons-server Source File: views.py
@addon_view
@non_atomic_requests
def license(request, addon, version=None):
    if version is not None:
        qs = addon.versions.filter(files__status__in=amo.VALID_FILE_STATUSES)
        version = get_list_or_404(qs, version=version)[0]
    else:
        version = addon.current_version
    if not (version and version.license):
        raise http.Http404
    return render(request, 'addons/impala/license.html',
                  dict(addon=addon, version=version))

Example 6

Project: django-cms Source File: placeholderadmin.py
    @xframe_options_sameorigin
    def edit_plugin(self, request, plugin_id):
        try:
            plugin_id = int(plugin_id)
        except ValueError:
            return HttpResponseNotFound(force_text(_("Plugin not found")))

        queryset = CMSPlugin.objects.values_list('plugin_type', flat=True)
        plugin_type = get_list_or_404(queryset, pk=plugin_id)[0]
        # CMSPluginBase subclass
        plugin_class = plugin_pool.get_plugin(plugin_type)
        # CMSPluginBase subclass instance
        plugin_instance = plugin_class(plugin_class.model, self.admin_site)
        # CMSPlugin subclass instance
        obj = get_object_or_404(plugin_class.model, pk=plugin_id)

        if not self.has_change_plugin_permission(request, obj):
            return HttpResponseForbidden(force_text(_("You do not have permission to edit this plugin")))

        response = plugin_instance.change_view(request, str(plugin_id))

        if request.method == "POST" and plugin_instance.object_successfully_changed:
            self.post_edit_plugin(request, plugin_instance.saved_object)
        return response

Example 7

Project: Asteroid Source File: views.py
Function: list_runs
def list_runs(request):
    "list all the runs that have been made so far"
    runs = get_list_or_404(Run)
    
    paginator = Paginator(runs, 10) # Show 10 runs per page

    # Make sure page request is an int. If not, deliver first page.
    try:
        page = int(request.GET.get('page', '1'))
    except ValueError:
        page = 1

    # If page request (9999) is out of range, deliver last page of results.
    try:
        run_list = paginator.page(page)
    except (EmptyPage, InvalidPage):
        run_list = paginator.page(paginator.num_pages)
    
    context = {
        'runs': run_list,
    }
    return render_to_response('list_runs.html', context,
        context_instance=RequestContext(request))

Example 8

Project: django-quran Source File: views.py
Function: index
def index(request, template_name='quran/index.html'):
    suras = get_list_or_404(Sura)
    return render_to_response(template_name, {'suras': suras})

Example 9

Project: addons-server Source File: views.py
@addon_view
@non_atomic_requests
def developers(request, addon, page):
    if addon.is_persona():
        raise http.Http404()
    if 'version' in request.GET:
        qs = addon.versions.filter(files__status__in=amo.VALID_ADDON_STATUSES)
        version = get_list_or_404(qs, version=request.GET['version'])[0]
    else:
        version = addon.current_version

    if 'src' in request.GET:
        contribution_src = src = request.GET['src']
    else:
        page_srcs = {
            'developers': ('developers', 'meet-developers'),
            'installed': ('meet-the-developer-post-install', 'post-download'),
            'roadblock': ('meetthedeveloper_roadblock', 'roadblock'),
        }
        # Download src and contribution_src are different.
        src, contribution_src = page_srcs.get(page)
    return render(request, 'addons/impala/developers.html',
                  {'addon': addon, 'page': page, 'src': src,
                   'contribution_src': contribution_src,
                   'version': version})

Example 10

Project: kuma Source File: list.py
@block_user_agents
@require_GET
def docuements(request, tag=None):
    """
    List wiki docuements depending on the optionally given tag.
    """
    # Taggit offers a slug - but use name here, because the slugification
    # stinks and is hard to customize.
    tag_obj = None
    if tag:
        matching_tags = get_list_or_404(DocuementTag, name__iexact=tag)
        for matching_tag in matching_tags:
            if matching_tag.name.lower() == tag.lower():
                tag_obj = matching_tag
                break
    docs = Docuement.objects.filter_for_list(locale=request.LANGUAGE_CODE,
                                            tag=tag_obj)
    paginated_docs = paginate(request, docs, per_page=DOCUMENTS_PER_PAGE)
    context = {
        'docuements': paginated_docs,
        'count': docs.count(),
        'tag': tag,
    }
    return render(request, 'wiki/list/docuements.html', context)

Example 11

Project: drf-tracking Source File: views.py
Function: get
    def get(self, request):
        empty_qs = APIRequestLog.objects.none()
        return get_list_or_404(empty_qs)