Пример #1
0
def tag_search(request, klass, template):
    """Search subset of models with the given tag.

    Usess ``watson`` for the full-text search.
    """
    # Generate a queryset from a model, manager or queryset:
    form = SearchForm(request.GET)
    page_no = pagination.get_page_no(request.GET)
    if form.is_valid():
        queryset = get_queryset(klass)
        object_list = watson.search(
            form.cleaned_data['q'], models=(queryset, ))
        pagination_qs = '&%s' % urlencode({'q': form.cleaned_data['q']})
    else:
        object_list = []
        pagination_qs = ''
    page = pagination.get_page(object_list, page_no)
    page.object_list_top = [o.object for o in page.object_list_top]
    page.object_list_bottom = [o.object for o in page.object_list_bottom]
    context = {
        'page': page,
        'form': form,
        'pagination_qs': pagination_qs,
    }
    return TemplateResponse(request, template, context)
Пример #2
0
def organization_list(request):
    page_no = pagination.get_page_no(request.GET)
    object_list = Organization.active.all()
    page = pagination.get_page(object_list, page_no)
    context = {
        'page': page,
    }
    return TemplateResponse(request, 'organizations/object_list.html', context)
Пример #3
0
def post_list(request):
    """List the published ``Posts``"""
    page_no = pagination.get_page_no(request.GET)
    featured_list = Post.published.select_related("author").filter(is_featured=True)[:3]
    object_list = Post.published.select_related("author").all()
    page = pagination.get_page(object_list, page_no, page_size=5)
    context = {"page": page, "featured_list": featured_list}
    return TemplateResponse(request, "blog/object_list.html", context)
Пример #4
0
def resource_list(request):
    page_no = pagination.get_page_no(request.GET)
    object_list = Resource.published.all()
    page = pagination.get_page(object_list, page_no)
    context = {
        'page': page,
    }
    return TemplateResponse(request, 'resources/object_list.html', context)
Пример #5
0
def event_list(request):
    page_no = pagination.get_page_no(request.GET)
    now = timezone.now()
    object_list = Event.published.filter(start_datetime__gte=now)
    page = pagination.get_page(object_list, page_no)
    context = {
        'page': page,
    }
    return TemplateResponse(request, 'events/object_list.html', context)
Пример #6
0
def article_list(request, section=Article.DEFAULT):
    page_no = pagination.get_page_no(request.GET)
    kwargs = {'section': section} if section else {}
    object_list = Article.published.filter(**kwargs)
    page = pagination.get_page(object_list, page_no)
    context = {
        'page': page,
    }
    return TemplateResponse(request, 'news/object_list.html', context)
Пример #7
0
def hub_list(request):
    """List al the available ``Hubs``."""
    page_no = pagination.get_page_no(request.GET)
    object_list = Hub.active.all()
    page = pagination.get_page(object_list, page_no)
    context = {
        'page': page,
    }
    return TemplateResponse(request, 'hubs/object_list.html', context)
Пример #8
0
def resource_list(request):
    page_no = pagination.get_page_no(request.GET)
    object_list = Resource.published.all()
    page = pagination.get_page(object_list, page_no)
    featured_list = Resource.published.filter(is_featured=True)[:3]
    context = {
        'page': page,
        'featured_list': featured_list,
    }
    return TemplateResponse(request, 'resources/object_list.html', context)
Пример #9
0
def challenge_list(request):
    page_no = pagination.get_page_no(request.GET)
    now = timezone.now()
    object_list = (Challenge.objects
                   .filter(end_datetime__gte=now, status=Challenge.PUBLISHED)
                   .order_by('start_datetime'))
    page = pagination.get_page(object_list, page_no)
    context = {
        'page': page,
    }
    return TemplateResponse(request, 'challenges/object_list.html', context)
Пример #10
0
def hub_list(request):
    """List al the available ``Hubs``."""
    page_no = pagination.get_page_no(request.GET)
    object_list = Hub.active.all()
    page = pagination.get_page(object_list, page_no)
    featured_list = Hub.active.filter(is_featured=True)[:3]
    context = {
        'page': page,
        'featured_list': featured_list,
    }
    return TemplateResponse(request, 'hubs/object_list.html', context)
Пример #11
0
def post_list(request, section=None):
    """List the published ``Posts``"""
    page_no = pagination.get_page_no(request.GET)
    query_kwargs = {'section': section} if section else {}
    featured_list = (Post.published.select_related('author')
                     .filter(is_featured=True, **query_kwargs)[:3])
    object_list = (Post.published.select_related('author')
                   .filter(**query_kwargs))
    page = pagination.get_page(object_list, page_no, page_size=5)
    context = {
        'page': page,
        'featured_list': featured_list,
    }
    return TemplateResponse(request, 'blog/object_list.html', context)
Пример #12
0
def app_list(request, domain=None):
    """Lists the published ``Applications``"""
    if domain:
        domain = get_object_or_404(Domain, slug=domain)
    extra_qs = {"domain": domain} if domain else {}
    page_no = pagination.get_page_no(request.GET)
    # Validate the domain is valid if provided:
    order_form = forms.OrderForm(request.GET, order_choices=APPS_SORTING_CHOICES)
    order_value = order_form.cleaned_data["order"] if order_form.is_valid() else ""
    object_list = Application.objects.filter(status=Application.PUBLISHED, **extra_qs)
    if order_value:
        object_list = object_list.order_by(order_value)
    page = pagination.get_page(object_list, page_no)
    context = {"page": page, "order": order_value, "order_form": order_form, "domain_list": Domain.objects.all()}
    return TemplateResponse(request, "apps/object_list.html", context)
Пример #13
0
def event_list(request, timeframe='upcoming', section=None):
    page_no = pagination.get_page_no(request.GET)
    query_kwargs = get_timeframe_kwargs(timeframe)
    if section:
        query_kwargs['section'] = section
    object_list = Event.published.filter(**query_kwargs)
    page = pagination.get_page(object_list, page_no)
    featured_list = Event.published.filter(
        is_featured=True, **get_timeframe_kwargs('upcoming'))
    context = {
        'page': page,
        'timeframe': timeframe,
        'featured_list': featured_list,
    }
    return TemplateResponse(request, 'events/object_list.html', context)
Пример #14
0
def profile_list(request):
    page_no = pagination.get_page_no(request.GET)
    order_form = forms.OrderForm(
        request.GET, order_choices=PROFILE_SORTING_CHOICES)
    order_value = order_form.cleaned_data['order'] if order_form.is_valid() else ''
    object_list = Profile.active.all()
    if order_value:
        # TODO consider using non case-sensitive ordering:
        object_list = object_list.order_by(order_value)
    page = pagination.get_page(object_list, page_no)
    context = {
        'page': page,
        'order': order_value,
        'order_form': order_form,
    }
    return TemplateResponse(request, 'people/object_list.html', context)
Пример #15
0
def actioncluster_list_iot(request):
    """List IOT project ideas."""
    extra_qs = {"is_approved": False, "status": ActionCluster.PUBLISHED}
    page_no = pagination.get_page_no(request.GET)
    object_list = ActionCluster.objects.select_related("domain").filter(**extra_qs)
    featured_list = ActionCluster.objects.select_related("domain").filter(is_featured=True, **extra_qs)[:3]
    page = pagination.get_page(object_list, page_no)
    context = {
        "featured_list": featured_list,
        "page": page,
        "domain_list": Domain.objects.all(),
        "stage_list": ActionCluster.STAGE_CHOICES,
        "appname": "actionclusters",
        "category": "iot",
    }
    return TemplateResponse(request, "actionclusters/object_list.html", context)
Пример #16
0
def testbed_list(request):
    """List of all the testbeds."""
    testbed_query = {}
    if request.GET:
        form = TestbedFilterForm(request.GET)
        if form.is_valid():
            testbed_query = get_testbed_query(form.cleaned_data)
    else:
        form = TestbedFilterForm()
    page_no = pagination.get_page_no(request.GET)
    object_list = Testbed.active.filter(**testbed_query)
    page = pagination.get_page(object_list, page_no)
    context = {
        'page': page,
        'form': form,
    }
    return TemplateResponse(request, 'testbed/object_list.html', context)
Пример #17
0
def search(request):
    form = SearchForm(request.GET) if 'q' in request.GET else SearchForm()
    page_no = pagination.get_page_no(request.GET)
    if form.is_valid():
        object_list = watson.search(form.cleaned_data['q'])
        pagination_qs = '&%s' % urlencode({'q': form.cleaned_data['q']})
    else:
        object_list = []
        pagination_qs = ''
    page = pagination.get_page(object_list, page_no)
    page.object_list_top = [o.object for o in page.object_list_top]
    page.object_list_bottom = [o.object for o in page.object_list_bottom]
    context = {
        'form': form,
        'page': page,
        'pagination_qs': pagination_qs,
    }
    return TemplateResponse(request, 'search/object_list.html', context)
Пример #18
0
def actioncluster_list(request, current=True, domain=None, stage=None, year=None, filter_name="", description=""):
    """List all the available ``ActionCluster``."""
    extra_qs = {"is_approved": True, "status": ActionCluster.PUBLISHED}
    if domain:
        # Validate domain is valid if provided:
        extra_qs["domain"] = get_object_or_404(Domain, slug=domain)
        filter_name = extra_qs["domain"].name
    elif stage:
        # Validate stage is valid if provided:
        pk, name = get_stage_or_404(stage)
        extra_qs["stage"] = pk
        filter_name = name
    elif year:
        extra_qs["year"] = get_object_or_404(Year, year=year)
        filter_name = extra_qs["year"].year
        description = extra_qs["year"].description
    else:
        if current:
            extra_qs["year"] = get_object_or_404(Year, default_year=True)
            filter_name = "Current Year (" + extra_qs["year"].year + ")"
            description = extra_qs["year"].description
        else:
            extra_qs["year"] = get_object_or_404(Year, default_year=False)
            filter_name = "Archive 2015"

    page_no = pagination.get_page_no(request.GET)
    object_list = ActionCluster.objects.select_related("domain").filter(**extra_qs).order_by("needs_partner")
    featured_list = ActionCluster.objects.select_related("domain").filter(is_featured=True, **extra_qs)[:3]
    page = pagination.get_page(object_list, page_no)
    context = {
        "featured_list": featured_list,
        "page": page,
        "domain_list": Domain.objects.all(),
        "stage_list": ActionCluster.STAGE_CHOICES,
        "filter_name": filter_name,
        "description": description,
        "current_domain": domain,
        "current_stage": int(stage) if stage else None,
        "appname": "actionclusters",
    }
    return TemplateResponse(request, "actionclusters/object_list.html", context)
Пример #19
0
def app_list(request, domain=None, stage=None, filter_name=""):
    """Lists the published ``Applications``"""
    extra_qs = {}
    if domain:
        # Validate domain is valid if provided:
        extra_qs["domain"] = get_object_or_404(Domain, slug=domain)
        filter_name = extra_qs["domain"].name
    if stage:
        # Validate stage is valid if provided:
        pk, name = get_stage_or_404(stage)
        extra_qs["stage"] = pk
        filter_name = name
    page_no = pagination.get_page_no(request.GET)
    order_form = forms.OrderForm(request.GET, order_choices=APPS_SORTING_CHOICES)
    order_value = order_form.cleaned_data["order"] if order_form.is_valid() else ""
    object_list_app = Application.objects.select_related("domain").filter(status=Application.PUBLISHED, **extra_qs)
    object_list_ac = ActionCluster.objects.select_related("domain").filter(status=ActionCluster.PUBLISHED, **extra_qs)
    object_list = list(chain(object_list_app, object_list_ac))
    if order_value:
        object_list = object_list.order_by(order_value)
    featured_list_app = Application.objects.select_related("domain").filter(
        status=Application.PUBLISHED, is_featured=True, **extra_qs
    )[:3]
    featured_list_ac = ActionCluster.objects.select_related("domain").filter(
        status=ActionCluster.PUBLISHED, is_featured=True, **extra_qs
    )[:3]
    featured_list = list(chain(featured_list_app, featured_list_ac))[:3]
    page = pagination.get_page(object_list, page_no)
    context = {
        "featured_list": featured_list,
        "page": page,
        "order": order_value,
        "order_form": order_form,
        "domain_list": Domain.objects.all(),
        "stage_list": Application.STAGE_CHOICES,
        "filter_name": filter_name,
        "current_domain": domain,
        "current_stage": int(stage) if stage else None,
    }
    return TemplateResponse(request, "apps/object_list.html", context)
Пример #20
0
 def test_invalid_number_returns_default(self):
     payload = {'page': 'INVALID'}
     page = pagination.get_page_no(payload)
     eq_(page, 1)
Пример #21
0
 def test_empty_get_request_returns_default(self):
     payload = {}
     page = pagination.get_page_no(payload)
     eq_(page, 1)
Пример #22
0
 def test_valid_integer_is_returned(self):
     payload = {'page': '34'}
     page = pagination.get_page_no(payload)
     eq_(page, 34)
Пример #23
0
 def test_negative_integer_returns_default(self):
     payload = {'page': '-11'}
     page = pagination.get_page_no(payload)
     eq_(page, 1)