Пример #1
0
def search(request):
    user_profile = get_user_profile(request)
    form = ManoloForm(request.GET)
    query = request.GET['q']

    all_items_premium = form.search(premium=True)
    all_items_standard = form.search(premium=False)

    if request.user.is_authenticated() and user_profile['expired'] is False:
        all_items = all_items_premium
        extra_premium_results = 0
    else:
        all_items = all_items_standard
        extra_premium_results = len(all_items_premium) - len(all_items_standard)

    paginator, page = do_pagination(request, all_items)

    json_path = request.get_full_path() + '&json'
    tsv_path = request.get_full_path() + '&tsv'
    return render(
        request,
        "search/search.html",
        {
            "extra_premium_results": extra_premium_results,
            "paginator": paginator,
            "page": page,
            "query": query,
            "json_path": json_path,
            "tsv_path": tsv_path,
            'user_profile': user_profile,
        },
    )
Пример #2
0
def about(request):
    user_profile = get_user_profile(request)
    return render(
        request,
        "about.html",
        {'user_profile': user_profile},
    )
Пример #3
0
def about(request):
    user_profile = get_user_profile(request)
    return render(
        request,
        "about.html",
        {'user_profile': user_profile},
    )
Пример #4
0
def search(request):
    user_profile = get_user_profile(request)
    query = request.GET.get('q') or ''
    query = query.strip()

    if query_is_dni(query):
        # do dni search
        all_items = do_dni_search(query)
    else:
        all_items = Visitor.objects.filter(
            full_search=SearchQuery(query)
        )

    paginator, page = do_pagination(request, all_items)

    json_path = request.get_full_path() + '&json'
    tsv_path = request.get_full_path() + '&tsv'
    return render(
        request,
        "search/search.html",
        {
            "paginator": paginator,
            "page": page,
            "query": query,
            "json_path": json_path,
            "tsv_path": tsv_path,
            'user_profile': user_profile,
        },
    )
Пример #5
0
def search(request):
    user_profile = get_user_profile(request)
    form = ManoloForm(request.GET)
    query = request.GET['q']

    all_items_premium = form.search(premium=True)
    all_items_standard = form.search(premium=False)

    if request.user.is_authenticated() and user_profile['expired'] is False:
        all_items = all_items_premium
        extra_premium_results = 0
    else:
        all_items = all_items_standard
        extra_premium_results = len(all_items_premium) - len(
            all_items_standard)

    paginator, page = do_pagination(request, all_items)

    json_path = request.get_full_path() + '&json'
    tsv_path = request.get_full_path() + '&tsv'
    return render(
        request,
        "search/search.html",
        {
            "extra_premium_results": extra_premium_results,
            "paginator": paginator,
            "page": page,
            "query": query,
            "json_path": json_path,
            "tsv_path": tsv_path,
            'user_profile': user_profile,
        },
    )
Пример #6
0
def index(request):
    user_profile = get_user_profile(request)
    stats = Statistic.objects.last()
    if stats:
        count = stats.visitor_count
    else:
        count = 0

    if stats and stats.updated_institutions:
        institutions = stats.updated_institutions
        for institution in institutions:
            institution['last_updated'] = datetime.datetime.strptime(
                institution['last_updated'], '%Y-%m-%d')
    else:
        institutions = []

    return render(
        request,
        "index.html",
        {
            'count': count,
            'user_profile': user_profile,
            'institutions': institutions,
        },
    )
Пример #7
0
def search_date(request):
    user_profile = get_user_profile(request)
    if 'q' in request.GET:
        query = request.GET['q']
        if query.strip() == '':
            return redirect('/')

        try:
            query_date_obj = datetime.datetime.strptime(query, '%d/%m/%Y')
        except ValueError:
            results = "No se encontraron resultados."
            return render(
                request,
                "search/search.html",
                {
                    'items': results,
                    'keyword': query,
                    'user_profile': user_profile,
                },
            )
        six_months_ago = datetime.datetime.today() - datetime.timedelta(
            days=180)

        if query_date_obj < six_months_ago:
            can_show_results = True
        else:
            try:
                if request.user.subscriber.credits > 0:
                    can_show_results = True
                else:
                    can_show_results = False
            except AttributeError:
                # user has no subscriber
                can_show_results = False

        date_str = datetime.datetime.strftime(query_date_obj, '%Y-%m-%d')
        # TODO: implement django queryset search here
        results = []
        paginator, page = do_pagination(request, results)

        context = {
            "paginator": paginator,
            "query": query,
            'user_profile': user_profile,
        }

        if can_show_results:
            try:
                if len(results) > 0 and request.user.subscriber:
                    if request.user.subscriber.credits is not None:
                        request.user.subscriber.credits -= 1
                        request.user.subscriber.save()
            except AttributeError:
                pass
            context["page"] = page
        else:
            context["extra_premium_results"] = len(results)
        return render(request, "search/search.html", context)
    else:
        return redirect('/')
Пример #8
0
def about(request):
    developers = Developer.objects.all().order_by('rank')
    context = get_user_profile(request)
    context['developers'] = developers
    return render(
        request,
        "about.html",
        context
    )
Пример #9
0
def index(request):
    user_profile = get_user_profile(request)
    count = Visitor.objects.count()
    return render(
        request,
        "index.html",
        {
            'count': count,
            'user_profile': user_profile,
        },
    )
Пример #10
0
    def test_get_user_profile__user_is_authenticated_has_0_credits(self):
        mock_subscriber = MagicMock()
        mock_subscriber.credits = 0

        mock_request = MagicMock()
        mock_request.user.is_authenticated.return_value = True
        mock_request.user.subscriber = mock_subscriber
        result = get_user_profile(mock_request)
        self.assertEqual(True, result["expired"])
        self.assertEqual(False, result["about_to_expire"])
        self.assertEqual(0, result["credits"])
Пример #11
0
def statistics(request):
    user_profile = get_user_profile(request)
    visitors = Statistic_detail.objects.all()
    return render(
        request,
        "statistics.html",
        {
            'user_profile': user_profile,
            'visitors': visitors,
        },
    )
Пример #12
0
def index(request):
    user_profile = get_user_profile(request)
    count = Visitor.objects.count()
    return render(
        request,
        "index.html",
        {
            'count': count,
            'user_profile': user_profile,
        },
    )
Пример #13
0
def statistics(request):
    user_profile = get_user_profile(request)
    visitors = Statistic_detail.objects.all()
    visitor_counts = dict()

    for entry in VisitorScrapeProgress.objects.all().order_by('cutoff_date'):
        date_str = str(entry.cutoff_date.strftime('%Y'))
        visitor_counts[date_str] = entry.visitor_count

    print(visitor_counts)

    return render(
        request,
        "statistics.html",
        {
            'user_profile': user_profile,
            'visitors': visitors,
            'visitor_counts': list(visitor_counts.values()),
            'visitor_counts_start': list(visitor_counts.keys())[0],
        },
    )
Пример #14
0
def search_date(request):
    user_profile = get_user_profile(request)
    if 'q' in request.GET:
        query = request.GET['q']
        if query.strip() == '':
            return redirect('/')

        try:
            date_obj = datetime.datetime.strptime(query, '%d/%m/%Y').date()
        except ValueError:
            results = "No se encontraron resultados."
            return render(
                request,
                "search/search.html",
                {
                    'items': results,
                    'keyword': query,
                    'user_profile': user_profile,
                },
            )

        date_str = datetime.datetime.strftime(date_obj, '%Y-%m-%d')
        results = SearchQuerySet().filter(date=date_str)

        all_items = results
        paginator, page = do_pagination(request, all_items)

        return render(
            request,
            "search/search.html",
            {
                "paginator": paginator,
                "page": page,
                "query": query,
                'user_profile': user_profile,
            },
        )
    else:
        return redirect('/')
Пример #15
0
def search_date(request):
    user_profile = get_user_profile(request)
    if 'q' in request.GET:
        query = request.GET['q']
        if query.strip() == '':
            return redirect('/')

        try:
            date_obj = datetime.datetime.strptime(query, '%d/%m/%Y').date()
        except ValueError:
            results = "No se encontraron resultados."
            return render(
                request,
                "search/search.html",
                {
                    'items': results,
                    'keyword': query,
                    'user_profile': user_profile,
                },
            )

        date_str = datetime.datetime.strftime(date_obj, '%Y-%m-%d')
        results = SearchQuerySet().filter(date=date_str)

        all_items = results
        paginator, page = do_pagination(request, all_items)

        return render(
            request, "search/search.html",
            {
                "paginator": paginator,
                "page": page,
                "query": query,
                'user_profile': user_profile,
            },
        )
    else:
        return redirect('/')