Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Colour code the workout calendar

Roland Geiderbf3c03df4b83
diff --git a/wger/core/static/css/workout-manager-common.css b/wger/core/static/css/workout-manager-common.css
index e12762ed2..7c2d165cb 100644
--- a/wger/core/static/css/workout-manager-common.css
+++ b/wger/core/static/css/workout-manager-common.css
@@ -290,67 +290,44 @@ body .boxInner:hover .titleBox, body.touch .boxInner.touchFocus .titleBox {
/**************************************************************
* Weight log calendar
**************************************************************/
- th.month, th.month:hover{
+table.month td{
+ height: 4em;
text-align: center;
- background-color: #d3d7cf;
- border-bottom: 2px solid black;
-}
-td.filled, td.filled:hover{
- background-color: #ad7fa8;
}
-td.filled a:hover{
- /*background-color: inherit;*/
+table.month td {
+ width: 14.285%;
}
-table.month tbody tr:hover td.filled{
- background-color: #ad7fa8;
+table.month th.month{
+ text-align: center;
+ background-color: #eeeeec;
}
-table.month td.filled a{
- display: block;
+
+table.month a.calendar-link{
height:100%;
- width:100%;
- color: black;
}
-table.month td a{
- color: black;
- text-shadow: none;
- text-decoration: none;
-}
-table.month td{
- padding: 0px;
- margin-top: 10px;
- margin-bottom: 10px;
- margin-left:7px;
- margin-right:7px;
-}
-table.month th{
- text-align: center;
+
+table.month td.session-bad {
+ background-color: #F2DEDE;
}
-table.month th {
- height: 2em;
+table.month td.session-bad:hover {
+ background-color: #C9302C;
}
-table.month td {
- height: 4em;
- width: 14.2857%;
- text-align: center;
- vertical-align: middle;
+table.month td.session-neutral {
+ background-color: #F5F5F5;
}
-
-td.today, table.month tbody tr:hover td.today{
- font-weight: bold;
+table.month td.session-neutral:hover {
+ background-color: #babdb6;
}
-.calendar-log-data{
- display:none;
+
+table.month td.session-good {
+ background-color: #dff0d8;
}
-.calendar-log-data ul.grouper-list > li{
- float:left;
- list-style:none;
- margin-left:0px;
- height: 120px;
- clear: right;
+table.month td.session-good:hover {
+ background-color: #449D44;
}
@media only screen and (max-width : 480px) {
diff --git a/wger/manager/templates/mobile/workout/calendar.html b/wger/manager/templates/mobile/workout/calendar.html
index 9b8c401b7..24b8cbf03 100644
--- a/wger/manager/templates/mobile/workout/calendar.html
+++ b/wger/manager/templates/mobile/workout/calendar.html
@@ -8,7 +8,8 @@
{% block header %}
<script>
$(document).ready(function() {
- $('table.month td.filled a').click(function(e){
+ $('.calendar-log-data').hide();
+ $('table.month td a.btn').click(function(e){
e.preventDefault();
$('.calendar-log-data').hide();
$('#' + $(this).data('log')).toggle();
@@ -171,6 +172,12 @@ day in your current workout:{% endblocktrans %} {{current_workout}}</p>
<p>{% blocktrans %}The coloured days in the calendar have weight logs,
you can click on them to see the details.{% endblocktrans %}</p>
+<p>
+ <div style="background-color: #C9302C; display: inline;">&nbsp;</div> {{ impressions.0.1 }}<br>
+ <div style="background-color: #EC971F; display: inline;">&nbsp;</div> {{ impressions.1.1 }}<br>
+ <div style="background-color: #449D44; display: inline;">&nbsp;</div> {{ impressions.2.1 }}
+</p>
+
<h3>{% trans 'Log' %}</h3>
<a href="{% url 'manager:workout:calendar' %}" class="btn btn-default btn-block">
<img src="{% static 'images/icons/calendar.svg' %}"
diff --git a/wger/manager/templates/workout/calendar.html b/wger/manager/templates/workout/calendar.html
index 6417c15f4..e464b2475 100644
--- a/wger/manager/templates/workout/calendar.html
+++ b/wger/manager/templates/workout/calendar.html
@@ -8,7 +8,8 @@
{% block header %}
<script>
$(document).ready(function() {
- $('table.month td.filled a').click(function(e){
+ $('.calendar-log-data').hide();
+ $('table.month td a.btn').click(function(e){
e.preventDefault();
$('.calendar-log-data').hide();
$('#' + $(this).data('log')).toggle();
@@ -137,6 +138,12 @@ day in your current workout:{% endblocktrans %} <strong>{{current_workout}}</str
<p>{% blocktrans %}The coloured days in the calendar have weight logs,
you can click on them to see the details.{% endblocktrans %}</p>
+<p>
+ <div style="background-color: #C9302C; display: inline;">&nbsp;</div> {{ impressions.0.1 }}<br>
+ <div style="background-color: #EC971F; display: inline;">&nbsp;</div> {{ impressions.1.1 }}<br>
+ <div style="background-color: #449D44; display: inline;">&nbsp;</div> {{ impressions.2.1 }}
+</p>
+
<h3>{% trans 'Log' %}</h3>
<p>
<a href="{% url 'manager:workout:calendar' %}">
diff --git a/wger/manager/views/log.py b/wger/manager/views/log.py
index 2a73282e4..0e7f00bdf 100644
--- a/wger/manager/views/log.py
+++ b/wger/manager/views/log.py
@@ -314,7 +314,7 @@ class WorkoutCalendar(HTMLCalendar):
'''
def __init__(self, workout_logs):
super(WorkoutCalendar, self).__init__()
- self.workout_logs = self.group_by_day(workout_logs)
+ self.workout_logs = workout_logs
def formatday(self, day, weekday):
if day != 0:
@@ -323,56 +323,51 @@ class WorkoutCalendar(HTMLCalendar):
if datetime.date.today() == date_obj:
cssclass += ' today'
if day in self.workout_logs:
- cssclass += ' filled'
+ current_log = self.workout_logs.get(day)
+ if current_log['impression'] == WorkoutSession.IMPRESSION_BAD:
+ background_css = 'btn-danger'
+ elif current_log['impression'] == WorkoutSession.IMPRESSION_GOOD:
+ background_css = 'btn-success'
+ else:
+ background_css = 'btn-warning'
+
+ url = reverse('manager:log:log', kwargs={'pk': current_log['log'].workout_id})
+ formatted_date = date_obj.strftime('%Y-%m-%d')
body = []
-
- for log in self.workout_logs[day]:
- url = reverse('manager:log:log', kwargs={'pk': log.workout_id})
- formatted_date = date_obj.strftime('%Y-%m-%d')
- body.append('<a href="{0}" data-log="log-{1}">'.format(url, formatted_date))
- body.append(repr(day))
- body.append('</a>')
+ body.append('<a href="{0}"'
+ 'data-log="log-{1}"'
+ 'class="btn btn-block {2} calendar-link">'.format(url,
+ formatted_date,
+ background_css))
+ body.append(repr(day))
+ body.append('</a>')
return self.day_cell(cssclass, '{0}'.format(''.join(body)))
return self.day_cell(cssclass, day)
return self.day_cell('noday', '&nbsp;')
def formatmonth(self, year, month):
'''
- Format the table header. This is the same code from python's calendar module
- but with an additional 'table' class
+ Format the table header. This is basically the same code from python's
+ calendar module but with additional bootstrap classes
'''
self.year, self.month = year, month
- v = []
- a = v.append
- a('<table border="0" cellpadding="0" cellspacing="0" class="month table">')
- a('\n')
- a(self.formatmonthname(year, month))
- a('\n')
- a(self.formatweekheader())
- a('\n')
+ out = []
+ out.append('<table class="month table table-bordered">\n')
+ out.append(self.formatmonthname(year, month))
+ out.append('\n')
+ out.append(self.formatweekheader())
+ out.append('\n')
for week in self.monthdays2calendar(year, month):
- a(self.formatweek(week))
- a('\n')
- a('</table>')
- a('\n')
- return ''.join(v)
-
- def group_by_day(self, workout_logs):
- '''
- Helper function that
- '''
- field = lambda log: log.date.day
- result = dict(
- [(day, list(items)) for day, items in groupby(workout_logs, field)]
- )
-
- return result
+ out.append(self.formatweek(week))
+ out.append('\n')
+ out.append('</table>\n')
+ return ''.join(out)
def day_cell(self, cssclass, body):
'''
Renders a day cell
'''
- return '<td class="{0}">{1}</td>'.format(cssclass, body)
+ return '<td class="{0}" style="vertical-align: middle;">{1}</td>'.format(cssclass, body)
def calendar(request, year=None, month=None):
@@ -389,17 +384,24 @@ def calendar(request, year=None, month=None):
month = int(month)
context = {}
- logs_filtered = []
- temp_date_list = []
+ logs_filtered = {}
logs = WorkoutLog.objects.filter(user=request.user,
date__year=year,
date__month=month).order_by('exercise')
- # Process the logs, 'overview' list for the calendar
+ # Process the logs. Group by date and check for impressions
for log in logs:
- if log.date not in temp_date_list:
- temp_date_list.append(log.date)
- logs_filtered.append(log)
+ 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}
(current_workout, schedule) = Schedule.objects.get_current_workout(request.user)
context['calendar'] = WorkoutCalendar(logs_filtered).formatmonth(year, month)
@@ -407,5 +409,6 @@ def calendar(request, year=None, month=None):
context['current_year'] = year
context['current_month'] = month
context['current_workout'] = current_workout
+ context['impressions'] = WorkoutSession.IMPRESSION
context['month_list'] = WorkoutLog.objects.filter(user=request.user).dates('date', 'month')
return render(request, 'workout/calendar.html', context)
diff --git a/wger/settings_global.py b/wger/settings_global.py
index 76ad2b3a7..415b377c8 100644
--- a/wger/settings_global.py
+++ b/wger/settings_global.py
@@ -31,7 +31,7 @@ SITE_ROOT = os.path.realpath(os.path.dirname(__file__))
#
# Application definition
#
-SITE_ID = 1
+SITE_ID = 2
ROOT_URLCONF = 'wger.urls'
WSGI_APPLICATION = 'wger.wsgi.application'
@@ -124,6 +124,14 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.core.context_processors.request'
)
+TEMPLATE_LOADERS = (
+ # Django mobile
+ 'django_mobile.loader.Loader',
+
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+)
+
# Store the user messages in the session
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'