Exemplo n.º 1
0
        def inner_decorator(request, *args, **kwargs):
            site_identifier = kwargs.get('site_identifier', None)
            site = Site.get_by_site_identifier(site_identifier)

            if not site or not site.users.filter(id=request.user.id):
                print site.users.all()
                messages.error(request, 'Either that site is invalid or you do not have access.')
                return redirect('login')

            return func(request, *args, **kwargs)
Exemplo n.º 2
0
def site_update(request, site_identifier):
    if not request.user.has_perm('tracker.change_site'):
        messages.error(request, 'Unfortunately, you do not have access to edit the site.')
        return redirect('sites')

    site = Site.get_by_site_identifier(site_identifier)
    form = SiteForm(instance=site)

    if request.method == 'POST':
        form = SiteForm(request.POST, instance=site)

        if form.is_valid():
            site = form.save()
            messages.info(request, "<em>%s</em> was updated." % (site.name))
            return redirect('sites')

    return {
        'TEMPLATE': 'www/site_update.html',
        'form': form,
    }
Exemplo n.º 3
0
def site(request, site_identifier):
    site = Site.get_by_site_identifier(site_identifier)
    query = Q()
    filters = {}

    if request.method == 'POST':
        if 'segment' in request.POST:
            # TODO: Store the filters into a segmentation model
            # Segment model has pickled version of Q() crazyness, total count the last time the segment ran, last time it ran, FK to site
            qs = convert_to_querystring(request.POST)

            return redirect('%s?%s' % (request.path, qs))
        else:
            raise Exception('Incorrect POST')

    (query, filters) = _get_filter_query(request)
    # print query
    # print filters

    # TODO: Abiliity to change time period.
    time_period = (timezone.now() - timedelta(days=30))
    filtered_authenticated_site_users = AuthenticatedSiteUser.get_filtered_authenticated_site_users(site, time_period, query)

    page_size = 10
    paginator = Paginator(filtered_authenticated_site_users, page_size)
    authenticated_site_users_count = paginator.count

    if filters:
        authenticated_site_users_count = AuthenticatedSiteUser.get_authenticated_site_users_count(site, time_period)

    site_users_count = SiteUser.get_site_users_count(site)

    page = request.GET.get('p')
    try:
        paginated_authenticated_site_users = paginator.page(page)
    except PageNotAnInteger:
        paginated_authenticated_site_users = paginator.page(1)
    except EmptyPage:
        paginated_authenticated_site_users = paginator.page(paginator.num_pages)

    authenticated_site_users_counts_dict = {}
    authenticated_site_users_counts = []

    for user in filtered_authenticated_site_users:
        date = user.last_visit_created.date()

        if date in authenticated_site_users_counts_dict:
            authenticated_site_users_counts_dict[date] = authenticated_site_users_counts_dict[date] + 1
        else:
            authenticated_site_users_counts_dict[date] = 1

    site_users_counts_dict = Visit.get_filtered_site_users_grouped_by_date(site, time_period)
    site_users_counts = []

    numdays = 30
    date_list = [ datetime.today().date() - timedelta(days=x) for x in range(0, numdays) ]

    for date in date_list:
        if date in site_users_counts_dict:
            site_users_counts.append(site_users_counts_dict[date])
        else:
            site_users_counts.append(0)

        if date in authenticated_site_users_counts_dict:
            authenticated_site_users_counts.append(authenticated_site_users_counts_dict[date])
        else:
            authenticated_site_users_counts.append(0)

    highest_site_user_count = max(authenticated_site_users_counts + site_users_counts)

    return {
        'TEMPLATE': 'www/site.html',
        'site': site,
        'filters': filters,
        'paginated_authenticated_site_users': paginated_authenticated_site_users,
        'filtered_authenticated_site_users_count': paginator.count,
        'filtered_authenticated_site_users_ratio': (float(paginator.count) / float(authenticated_site_users_count)) * 100 if authenticated_site_users_count else 0,
        'authenticated_site_users_count': authenticated_site_users_count,
        'site_users_count': site_users_count,
        'authenticated_site_users_ratio': (float(authenticated_site_users_count) / float(site_users_count)) * 100 if site_users_count else 0,
        'days': range(1, 30),
        'authenticated_site_users_counts': authenticated_site_users_counts,
        'site_users_counts': site_users_counts,
        'highest_site_user_count': highest_site_user_count,
    }