Example #1
0
def search(request):
    if request.method == "GET":
        if len(request.GET) > 0:
            form = SearchForm(request.GET)
            if form.is_valid():
                results_set = form.build_queryset()
                paginator = Paginator(results_set, per_page=20, orphans=10)
                GET_data = request.GET.copy()
                
                try:
                    page = int(request.GET.get('page', '1'))
                    if GET_data.get('page', False):
                        del GET_data['page']
                except ValueError:
                    page = 1
                
                try:
                    results = paginator.page(page)
                except (EmptyPage, InvalidPage):
                    results = paginator.page(paginator.num_pages)
                
                return render(request, 'courses/search.html', {
                    'form': form,
                    'results': results,
                    'path': ''.join([request.path, '?', GET_data.urlencode()]),
                })
            else:
                return render(request, 'courses/search.html', {
                    'form': form,
                })
        else:
            form = SearchForm()
            return render(request, 'courses/search.html', {
                'form': form,
            })
Example #2
0
def schedule(request):
    last_full, last_reg = _get_refresh_history()
    featuring_queries = FeaturingQuery.objects.all()

    if not request.method == "GET" or len(request.GET) == 0:
        form = SearchForm()
        return render(request, 'schedule/schedule.html', {
            'form': form,
            'last_full': last_full,
            'last_reg': last_reg,
            'featuring_queries': featuring_queries
        })
    else:
        form = SearchForm(request.GET)
        if form.is_valid():
            results_set, term = form.build_queryset_and_term()
            request.session['term_key'] = term.key
            paginator = Paginator(results_set, per_page=20, orphans=5)
            GET_data = request.GET.copy()

            try:
                page = int(request.GET.get('page', '1'))
                if GET_data.get('page', False):
                    del GET_data['page']
            except ValueError:
                page = 1

            try:
                results = paginator.page(page)
            except (EmptyPage, InvalidPage):
                results = paginator.page(paginator.num_pages)

            for course in results.object_list:
                if course.id in request.session.get('schedule_courses', []):
                    course.added = True

            return render(request, 'schedule/schedule.html', {
                'form': form,
                'results': results,
                'path': ''.join([request.path, '?', GET_data.urlencode()]),
                'last_full': last_full,
                'last_reg': last_reg,
                'featuring_queries': featuring_queries
            })
        else:
            return render(request, 'schedule/schedule.html', {
                'form': form,
                'last_full': last_full,
                'last_reg': last_reg,
                'featuring_queries': featuring_queries
            })
Example #3
0
def search(request):
    last_full, last_reg = _get_refresh_history()

    if request.method == "GET":
        if len(request.GET) > 0:
            form = SearchForm(request.GET)
            if form.is_valid():
                results_set, term = form.build_queryset_and_term()
                paginator = Paginator(results_set, per_page=20, orphans=10)
                GET_data = request.GET.copy()

                page = int(request.GET.get('page', '1'))
                GET_data.pop('page', None)

                try:
                    results = paginator.page(page)
                except (EmptyPage, InvalidPage):
                    results = paginator.page(paginator.num_pages)

                return render(request, 'search/search.html', {
                    'form': form,
                    'results': results,
                    'path': ''.join([request.path, '?', GET_data.urlencode()]),
                    'last_full': last_full,
                    'last_reg': last_reg
                })
            else:
                return render(request, 'search/search.html', {
                    'form': form,
                    'last_full': last_full,
                    'last_reg': last_reg
                })
        else:
            form = SearchForm()
            return render(request, 'search/search.html', {
                'form': form,
                'last_full': last_full,
                'last_reg': last_reg
            })
    else:
        return HttpResponseNotAllowed(['GET'])
Example #4
0
def schedule(request):
    if not request.method == "GET" or len(request.GET) == 0:
        form = SearchForm()
        return render(request, 'courses/schedule.html', {
            'form': form,
        })
    else:
        form = SearchForm(request.GET)
        if form.is_valid():
            results_set = form.build_queryset()
            paginator = Paginator(results_set, per_page=10, orphans=5)
            GET_data = request.GET.copy()

            try:
                page = int(request.GET.get('page', '1'))
                if GET_data.get('page', False):
                    del GET_data['page']
            except ValueError:
                page = 1

            try:
                results = paginator.page(page)
            except (EmptyPage, InvalidPage):
                results = paginator.page(paginator.num_pages)

            for course in results.object_list:
                if course.id in request.session.get('schedule_courses', []):
                    course.added = True

            return render(request, 'courses/schedule.html', {
                'form': form,
                'results': results,
                'path': ''.join([request.path, '?', GET_data.urlencode()]),
            })
        else:
            return render(request, 'courses/schedule.html', {
                'form': form,
            })