예제 #1
0
파일: views.py 프로젝트: andela/wg-kalii
def comparison(request, username=None):
    """
    Shows a comparison of user's weight with another selected user
    """
    is_owner, user = check_access(request.user, username)

    users = list(
        User.objects.filter(~Q(username=request.user.username),
                            Q(weightentry__id__isnull=False)).distinct())

    template_data = {}

    min_date = WeightEntry.objects.filter(user=user).\
        aggregate(Min('date'))['date__min']
    max_date = WeightEntry.objects.filter(user=user).\
        aggregate(Max('date'))['date__max']
    if min_date:
        template_data['min_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': min_date.year,
                                     'month': min_date.month,
                                     'day': min_date.day}
    if max_date:
        template_data['max_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': max_date.year,
                                     'month': max_date.month,
                                     'day': max_date.day}

    last_weight_entries = helpers.get_last_entries(user)

    template_data['is_owner'] = is_owner
    template_data['users'] = users
    template_data['owner_user'] = user
    template_data['show_shariff'] = is_owner
    template_data['last_five_weight_entries_details'] = last_weight_entries
    return render(request, 'comparison.html', template_data)
예제 #2
0
def get_weight_data(request, username=None):
    '''
    Process the data to pass it to the JS libraries to generate an SVG image
    '''

    is_owner, user = check_access(request.user, username)

    date_min = request.GET.get('date_min', False)
    date_max = request.GET.get('date_max', True)

    if date_min and date_max:
        weights = WeightEntry.objects.filter(user=user,
                                             creation_date__range=(date_min, date_max))
    else:
        weights = WeightEntry.objects.filter(user=user)

    chart_data = []

    for i in weights:
        chart_data.append({'x': "%(month)s/%(day)s/%(year)s" % {
                           'year': i.creation_date.year,
                           'month': i.creation_date.month,
                           'day': i.creation_date.day},
                           'y': i.weight,
                           'id': i.id})

    # Return the results to the client
    return Response(chart_data)
예제 #3
0
파일: views.py 프로젝트: teadur/wger
def overview(request, username=None):
    '''
    Shows a plot with the weight data

    More info about the D3 library can be found here:
        * https://github.com/mbostock/d3
        * http://d3js.org/
    '''
    is_owner, user = check_access(request.user, username)

    template_data = {}

    min_date = WeightEntry.objects.filter(user=user).\
        aggregate(Min('date'))['date__min']
    max_date = WeightEntry.objects.filter(user=user).\
        aggregate(Max('date'))['date__max']
    if min_date:
        template_data['min_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': min_date.year,
                                     'month': min_date.month,
                                     'day': min_date.day}
    if max_date:
        template_data['max_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': max_date.year,
                                     'month': max_date.month,
                                     'day': max_date.day}

    last_weight_entries = helpers.get_last_entries(user)

    template_data['is_owner'] = is_owner
    template_data['owner_user'] = user
    template_data['show_shariff'] = is_owner
    template_data['last_five_weight_entries_details'] = last_weight_entries
    return ua_aware_render(request, 'overview.html', template_data)
예제 #4
0
def overview(request, username=None):
    '''
    Shows a plot with the weight data

    More info about the D3 library can be found here:
        * https://github.com/mbostock/d3
        * http://d3js.org/
    '''
    is_owner, user = check_access(request.user, username)

    template_data = {}

    min_date = WeightEntry.objects.filter(user=user).\
        aggregate(Min('creation_date'))['creation_date__min']
    max_date = WeightEntry.objects.filter(user=user).\
        aggregate(Max('creation_date'))['creation_date__max']
    if min_date:
        template_data['min_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': min_date.year,
                                     'month': min_date.month,
                                     'day': min_date.day}
    if max_date:
        template_data['max_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': max_date.year,
                                     'month': max_date.month,
                                     'day': max_date.day}

    template_data['is_owner'] = is_owner
    template_data['owner_user'] = user
    template_data['show_shariff'] = is_owner
    return render(request, 'weight_overview.html', template_data)
예제 #5
0
def calendar(request, username=None, year=None, month=None):
    '''
    Show a calendar with all the workout logs
    '''
    context = {}
    is_owner, user = check_access(request.user, username)
    year = int(year) if year else datetime.date.today().year
    month = int(month) if month else datetime.date.today().month

    (current_workout, schedule) = Schedule.objects.get_current_workout(user)
    grouped_log_entries = group_log_entries(user, year, month)

    context['calendar'] = WorkoutCalendar(grouped_log_entries).formatmonth(
        year, month)
    context['logs'] = grouped_log_entries
    context['current_year'] = year
    context['current_month'] = month
    context['current_workout'] = current_workout
    context['owner_user'] = user
    context['is_owner'] = is_owner
    context['impressions'] = WorkoutSession.IMPRESSION
    context['month_list'] = WorkoutLog.objects.filter(user=user).dates(
        'date', 'month')
    context['show_shariff'] = is_owner and user.userprofile.ro_access
    return render(request, 'calendar/month.html', context)
예제 #6
0
def get_weight_data(request, username=None):
    '''
    Process the data to pass it to the JS libraries to generate an SVG image
    '''

    is_owner, user = check_access(request.user, username)

    date_min = request.GET.get('date_min', False)
    date_max = request.GET.get('date_max', True)
    fitbit = request.GET.get('fitbit')
    weights = []
    chart_data = []

    if fitbit:
        results = get_fitbit(request.user)
        if results[0]:
            weights_raw = results[1]
            for i in weights_raw:
                chart_data.append({'date': i[0].date, 'weight': i[0].weight})
    else:
        if date_min and date_max:
            weights = WeightEntry.objects.filter(user=user,
                                                 date__range=(date_min,
                                                              date_max))
        else:
            weights = WeightEntry.objects.filter(user=user)
        for i in weights:
            chart_data.append({'date': i.date, 'weight': i.weight})

    # Return the results to the client
    return Response(chart_data)
예제 #7
0
def get_weight_data(request, username=None):
    '''
    Process the data to pass it to the JS libraries to generate an SVG image
    '''

    is_owner, user = check_access(request.user, username)

    date_min = request.GET.get('date_min', False)
    date_max = request.GET.get('date_max', True)

    if date_min and date_max:
        weights = WeightEntry.objects.filter(user=user,
                                             date__range=(date_min, date_max))
    else:
        weights = WeightEntry.objects.filter(user=user)

    chart_data = []

    for i in weights:
        chart_data.append({
            'x': "%(month)s/%(day)s/%(year)s" % {
                'year': i.date.year,
                'month': i.date.month,
                'day': i.date.day
            },
            'y': i.weight,
            'id': i.id
        })

    # Return the results to the client
    return Response(chart_data)
예제 #8
0
파일: views.py 프로젝트: jonathankamau/wger
def overview(request, username=None):
    """
    Shows a plot with the weight data
    """
    is_owner, user = check_access(request.user, username)
    context = {
        'is_owner': is_owner,
        'owner_user': user,
        'show_shariff': False,
    }
    return render(request, 'overview.html', context)
예제 #9
0
def overview(request, username=None):
    '''
    Shows a plot with the weight data

    More info about the D3 library can be found here:
        * https://github.com/mbostock/d3
        * http://d3js.org/
    '''
    is_owner, user = check_access(request.user, username)

    template_data = {}

    min_date = WeightEntry.objects.filter(user=user).\
        aggregate(Min('date'))['date__min']
    max_date = WeightEntry.objects.filter(user=user).\
        aggregate(Max('date'))['date__max']
    if min_date:
        template_data['min_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': min_date.year,
                                     'month': min_date.month,
                                     'day': min_date.day}
    if max_date:
        template_data['max_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': max_date.year,
                                     'month': max_date.month,
                                     'day': max_date.day}

    last_five_weight_entries = WeightEntry.objects.filter(
        user=user).order_by('-date')[:5]
    last_five_weight_entries_details = []

    for index, entry in enumerate(last_five_weight_entries):
        curr_entry = entry
        prev_entry_index = index + 1

        if prev_entry_index < len(last_five_weight_entries):
            prev_entry = last_five_weight_entries[prev_entry_index]
        else:
            prev_entry = None

        if prev_entry and curr_entry:
            weight_diff = curr_entry.weight - prev_entry.weight
            day_diff = (curr_entry.date - prev_entry.date).days
        else:
            weight_diff = day_diff = None
        last_five_weight_entries_details.append(
            (curr_entry, weight_diff, day_diff))

    template_data['is_owner'] = is_owner
    template_data['owner_user'] = user
    template_data['show_shariff'] = is_owner
    template_data[
        'last_five_weight_entries_details'] = last_five_weight_entries_details
    return render(request, 'weight_overview.html', template_data)
예제 #10
0
    def test_helper(self):
        '''
        Test the helper function
        '''

        user_share = User.objects.get(pk=1)
        self.assertTrue(user_share.userprofile.ro_access)

        user_no_share = User.objects.get(pk=2)
        self.assertFalse(user_no_share.userprofile.ro_access)

        anon = AnonymousUser()

        # Logged out user
        self.assertEqual(check_access(anon, 'admin'), (False, user_share))
        self.assertRaises(Http404, check_access, anon, 'test')
        self.assertRaises(Http404, check_access, anon, 'not_a_username')
        self.assertRaises(Http404, check_access, anon)

        # Logged in user
        self.assertEqual(check_access(user_share, 'admin'), (True, user_share))
        self.assertRaises(Http404, check_access, user_share, 'test')
        self.assertEqual(check_access(user_share), (True, user_share))
        self.assertRaises(Http404, check_access, user_share, 'not_a_username')

        self.assertEqual(check_access(user_no_share, 'admin'), (False, user_share))
        self.assertEqual(check_access(user_no_share, 'test'), (True, user_no_share))
        self.assertEqual(check_access(user_no_share), (True, user_no_share))
        self.assertRaises(Http404, check_access, user_no_share, 'not_a_username')
예제 #11
0
    def test_helper(self):
        """
        Test the helper function
        """

        user_share = User.objects.get(pk=1)
        self.assertTrue(user_share.userprofile.ro_access)

        user_no_share = User.objects.get(pk=2)
        self.assertFalse(user_no_share.userprofile.ro_access)

        anon = AnonymousUser()

        # Logged out user
        self.assertEqual(check_access(anon, 'admin'), (False, user_share))
        self.assertRaises(Http404, check_access, anon, 'test')
        self.assertRaises(Http404, check_access, anon, 'not_a_username')
        self.assertRaises(Http404, check_access, anon)

        # Logged in user
        self.assertEqual(check_access(user_share, 'admin'), (True, user_share))
        self.assertRaises(Http404, check_access, user_share, 'test')
        self.assertEqual(check_access(user_share), (True, user_share))
        self.assertRaises(Http404, check_access, user_share, 'not_a_username')

        self.assertEqual(check_access(user_no_share, 'admin'),
                         (False, user_share))
        self.assertEqual(check_access(user_no_share, 'test'),
                         (True, user_no_share))
        self.assertEqual(check_access(user_no_share), (True, user_no_share))
        self.assertRaises(Http404, check_access, user_no_share,
                          'not_a_username')
예제 #12
0
파일: log.py 프로젝트: voszp/wger
def calendar(request, username=None, year=None, month=None):
    '''
    Show a calendar with all the workout logs
    '''
    is_owner, user = check_access(request.user, username)

    logger.info('aa bb cc')
    uid, token = make_token(user)
    year = int(year) if year else datetime.date.today().year
    month = int(month) if month else datetime.date.today().month

    context = {}
    logs = WorkoutLog.objects.filter(user=user,
                                     date__year=year,
                                     date__month=month).order_by('exercise')
    logs_filtered = cache.get(
        cache_mapper.get_workout_log(user.pk, year, month))
    if not logs_filtered:
        logs_filtered = {}

        # Process the logs. Group by date and check for impressions
        for log in logs:
            if log.date not in logs_filtered:
                session = log.get_workout_session()

                if session:
                    impression = session.impression
                else:
                    # Default is 'neutral'
                    impression = WorkoutSession.IMPRESSION_NEUTRAL

                logs_filtered[log.date.day] = {
                    'impression': impression,
                    'log': log
                }
        cache.set(cache_mapper.get_workout_log(user.pk, year, month),
                  logs_filtered)

    (current_workout, schedule) = Schedule.objects.get_current_workout(user)
    context['calendar'] = WorkoutCalendar(logs_filtered).formatmonth(
        year, month)
    context['logs'] = process_log_entries(logs)[0]
    context['current_year'] = year
    context['current_month'] = month
    context['current_workout'] = current_workout
    context['owner_user'] = user
    context['is_owner'] = is_owner
    context['impressions'] = WorkoutSession.IMPRESSION
    context['month_list'] = WorkoutLog.objects.filter(user=user).dates(
        'date', 'month')
    context['show_shariff'] = is_owner and user.userprofile.ro_access
    return render(request, 'workout/calendar.html', context)
예제 #13
0
파일: views.py 프로젝트: jamessimas/wger
def overview(request, username=None):
    '''
    Shows a plot with the weight data

    More info about the D3 library can be found here:
        * https://github.com/mbostock/d3
        * http://d3js.org/
    '''
    is_owner, user = check_access(request.user, username)

    template_data = {}

    min_date = WeightEntry.objects.filter(user=user).\
        aggregate(Min('date'))['date__min']
    max_date = WeightEntry.objects.filter(user=user).\
        aggregate(Max('date'))['date__max']
    if min_date:
        template_data['min_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': min_date.year,
                                     'month': min_date.month,
                                     'day': min_date.day}
    if max_date:
        template_data['max_date'] = 'new Date(%(year)s, %(month)s, %(day)s)' % \
                                    {'year': max_date.year,
                                     'month': max_date.month,
                                     'day': max_date.day}

    last_five_weight_entries = WeightEntry.objects.filter(user=user).order_by('-date')[:5]
    last_five_weight_entries_details = []

    for index, entry in enumerate(last_five_weight_entries):
        curr_entry = entry
        prev_entry_index = index + 1

        if prev_entry_index < len(last_five_weight_entries):
            prev_entry = last_five_weight_entries[prev_entry_index]
        else:
            prev_entry = None

        if prev_entry and curr_entry:
            weight_diff = curr_entry.weight - prev_entry.weight
            day_diff = (curr_entry.date - prev_entry.date).days
        else:
            weight_diff = day_diff = None
        last_five_weight_entries_details.append((curr_entry, weight_diff, day_diff))

    template_data['is_owner'] = is_owner
    template_data['owner_user'] = user
    template_data['show_shariff'] = is_owner
    template_data['last_five_weight_entries_details'] = last_five_weight_entries_details
    return render(request, 'weight_overview.html', template_data)
예제 #14
0
파일: log.py 프로젝트: marchiore/wger
def calendar(request, username=None, year=None, month=None):
    '''
    Show a calendar with all the workout logs
    '''
    is_owner, user = check_access(request.user, username)

    uid, token = make_token(user)
    year = int(year) if year else datetime.date.today().year
    month = int(month) if month else datetime.date.today().month

    context = {}
    logs = WorkoutLog.objects.filter(user=user,
                                     date__year=year,
                                     date__month=month).order_by('exercise')
    logs_filtered = cache.get(cache_mapper.get_workout_log(user.pk, year, month))
    if not logs_filtered:
        logs_filtered = {}

        # Process the logs. Group by date and check for impressions
        for log in logs:
            if log.date not in logs_filtered:
                session = log.get_workout_session()

                if session:
                    impression = session.impression
                else:
                    # Default is 'neutral'
                    impression = WorkoutSession.IMPRESSION_NEUTRAL

                logs_filtered[log.date.day] = {'impression': impression,
                                               'log': log}
        cache.set(cache_mapper.get_workout_log(user.pk, year, month), logs_filtered)

    (current_workout, schedule) = Schedule.objects.get_current_workout(user)
    context['calendar'] = WorkoutCalendar(logs_filtered).formatmonth(year, month)
    context['logs'] = process_log_entries(logs)[0]
    context['current_year'] = year
    context['current_month'] = month
    context['current_workout'] = current_workout
    context['owner_user'] = user
    context['is_owner'] = is_owner
    context['impressions'] = WorkoutSession.IMPRESSION
    context['month_list'] = WorkoutLog.objects.filter(user=user).dates('date', 'month')
    context['show_shariff'] = is_owner and user.userprofile.ro_access
    return render(request, 'workout/calendar.html', context)
예제 #15
0
def day(request, username, year, month, day):
    '''
    Show the logs for a single day
    '''
    context = {}
    is_owner, user = check_access(request.user, username)

    try:
        date = datetime.date(int(year), int(month), int(day))
    except ValueError as e:
        logger.error("Error on date: {0}".format(e))
        return HttpResponseForbidden()
    context['logs'] = group_log_entries(user, date.year, date.month, date.day)
    context['date'] = date
    context['owner_user'] = user
    context['is_owner'] = is_owner
    context['show_shariff'] = is_owner and user.userprofile.ro_access

    return render(request, 'calendar/day.html', context)
예제 #16
0
파일: log.py 프로젝트: wger-project/wger
def day(request, username, year, month, day):
    """
    Show the logs for a single day
    """
    context = {}
    is_owner, user = check_access(request.user, username)

    try:
        date = datetime.date(int(year), int(month), int(day))
    except ValueError as e:
        logger.error("Error on date: {0}".format(e))
        return HttpResponseForbidden()
    context["logs"] = group_log_entries(user, date.year, date.month, date.day)
    context["date"] = date
    context["owner_user"] = user
    context["is_owner"] = is_owner
    context["show_shariff"] = is_owner and user.userprofile.ro_access

    return render(request, "calendar/day.html", context)
예제 #17
0
파일: log.py 프로젝트: jamessimas/wger
def calendar(request, username=None, year=None, month=None):
    '''
    Show a calendar with all the workout logs
    '''
    context = {}
    is_owner, user = check_access(request.user, username)
    year = int(year) if year else datetime.date.today().year
    month = int(month) if month else datetime.date.today().month

    (current_workout, schedule) = Schedule.objects.get_current_workout(user)
    grouped_log_entries = group_log_entries(user, year, month)

    context['calendar'] = WorkoutCalendar(grouped_log_entries).formatmonth(year, month)
    context['logs'] = grouped_log_entries
    context['current_year'] = year
    context['current_month'] = month
    context['current_workout'] = current_workout
    context['owner_user'] = user
    context['is_owner'] = is_owner
    context['impressions'] = WorkoutSession.IMPRESSION
    context['month_list'] = WorkoutLog.objects.filter(user=user).dates('date', 'month')
    context['show_shariff'] = is_owner and user.userprofile.ro_access
    return render(request, 'calendar/month.html', context)
예제 #18
0
파일: log.py 프로젝트: wger-project/wger
def calendar(request, username=None, year=None, month=None):
    """
    Show a calendar with all the workout logs
    """
    context = {}
    is_owner, user = check_access(request.user, username)
    year = int(year) if year else datetime.date.today().year
    month = int(month) if month else datetime.date.today().month

    (current_workout, schedule) = Schedule.objects.get_current_workout(user)
    grouped_log_entries = group_log_entries(user, year, month)

    context["calendar"] = WorkoutCalendar(grouped_log_entries).formatmonth(year, month)
    context["logs"] = grouped_log_entries
    context["current_year"] = year
    context["current_month"] = month
    context["current_workout"] = current_workout
    context["owner_user"] = user
    context["is_owner"] = is_owner
    context["impressions"] = WorkoutSession.IMPRESSION
    context["month_list"] = WorkoutLog.objects.filter(user=user).dates("date", "month")
    context["show_shariff"] = is_owner and user.userprofile.ro_access
    return render(request, "calendar/month.html", context)
예제 #19
0
파일: views.py 프로젝트: andela/wg-kalii
def get_weight_data(request, username=None):
    """
    Process the data to pass it to the JS libraries to generate an SVG image
    """

    is_owner, user = check_access(request.user, username)

    date_min = request.GET.get('date_min', False)
    date_max = request.GET.get('date_max', True)

    if date_min and date_max:
        weights = WeightEntry.objects.filter(user=user,
                                             date__range=(date_min, date_max))
    else:
        weights = WeightEntry.objects.filter(user=user)

    chart_data = []

    for i in weights:
        chart_data.append({'date': i.date, 'weight': i.weight})

    # Return the results to the client
    return Response(chart_data)
예제 #20
0
파일: views.py 프로젝트: DeveloperMal/wger
def get_weight_data(request, username=None):
    '''
    Process the data to pass it to the JS libraries to generate an SVG image
    '''

    is_owner, user = check_access(request.user, username)

    date_min = request.GET.get('date_min', False)
    date_max = request.GET.get('date_max', True)

    if date_min and date_max:
        weights = WeightEntry.objects.filter(user=user,
                                             date__range=(date_min, date_max))
    else:
        weights = WeightEntry.objects.filter(user=user)

    chart_data = []

    for i in weights:
        chart_data.append({'date': i.date,
                           'weight': i.weight})

    # Return the results to the client
    return Response(chart_data)