Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add a sitemap.xml generator and serve a robots.txt file
Roland Geiderf7d8a2715b76
diff --git a/exercises/sitemap.py b/exercises/sitemap.pynew file mode 100644index 000000000..6cd8038b7--- /dev/null+++ b/exercises/sitemap.py@@ -0,0 +1,27 @@+# -*- coding: utf-8 -*-++# This file is part of Workout Manager.+#+# Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License++from django.contrib.sitemaps import Sitemap+from exercises.models import Exercise+from manager.utils import load_language+++class ExercisesSitemap(Sitemap):+ changefreq = "monthly"+ priority = 0.5++ def items(self):+ return Exercise.objects.filter(category__language=load_language())diff --git a/manager/templates/robots.txt b/manager/templates/robots.txtnew file mode 100644index 000000000..ca345c9a1--- /dev/null+++ b/manager/templates/robots.txt@@ -0,0 +1,2 @@+Sitemap: http://wger.de/de/sitemap.xml+Sitemap: http://wger.de/en/sitemap.xmldiff --git a/manager/urls.py b/manager/urls.pyindex 206b09564..5ceb897b2 100644--- a/manager/urls.py+++ b/manager/urls.py@@ -2,8 +2,6 @@ from django.conf.urls import patterns, urlfrom django.contrib.auth.decorators import login_requiredfrom django.core.urlresolvers import reverse_lazy-from django.views.generic import TemplateView-from manager.views import WorkoutEditViewfrom manager.views import WorkoutDeleteViewfrom manager.views import WorkoutLogDetailView@@ -19,10 +17,10 @@ urlpatterns = patterns('manager.views',# The landing pageurl(r'^$', 'index', name='index'),-+# The dashboardurl(r'^dashboard$', 'dashboard', name='dashboard'),-+# Userurl(r'^logout$', 'logout', name='logout'),diff --git a/nutrition/sitemap.py b/nutrition/sitemap.pynew file mode 100644index 000000000..d70611979--- /dev/null+++ b/nutrition/sitemap.py@@ -0,0 +1,27 @@+# -*- coding: utf-8 -*-++# This file is part of Workout Manager.+#+# Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License++from django.contrib.sitemaps import Sitemap+from nutrition.models import Ingredient+from manager.utils import load_language+++class NutritionSitemap(Sitemap):+ changefreq = "monthly"+ priority = 0.5++ def items(self):+ return Ingredient.objects.filter(language=load_language())diff --git a/software/templates/code.html b/software/templates/code.htmlindex 5b7d991a7..dd1013d1a 100644--- a/software/templates/code.html+++ b/software/templates/code.html@@ -98,6 +98,10 @@ fastest to set up is Sqlite, but you can use<a href="https://docs.djangoproject.com/en/1.4/ref/databases/">whatever Django supports</a>.Initialise the database and create a super user.{% endblocktrans %}</p>+<p>{% blocktrans %}For the sitemap.xml to work, you need to set a correct domain name+in the sites app. This is done via django's admin interface.{% endblocktrans %}</p>++<code>$ cd ..$ python manage.py syncdbdiff --git a/workout_manager/settings_global.py b/workout_manager/settings_global.pyindex 53df5ad01..2a3d3dd54 100644--- a/workout_manager/settings_global.py+++ b/workout_manager/settings_global.py@@ -1,4 +1,26 @@-# Django settings for workout_manager project.+# -*- coding: utf-8 -*-++# This file is part of Workout Manager.+#+# Workout Manager is free software: you can redistribute it and/or modify+# it under the terms of the GNU Affero General Public License as published by+# the Free Software Foundation, either version 3 of the License, or+# (at your option) any later version.+#+# Workout Manager is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU Affero General Public License+++'''+This file contains the global settings that don't need to be changed by the user+For a full list of options, visit:+ https://docs.djangoproject.com/en/1.4/ref/settings/#std:setting-LANGUAGES+'''+ADMINS = (#('Your name', '[email protected]'),@@ -135,6 +157,8 @@ INSTALLED_APPS = ('django.contrib.admin',# Uncomment the next line to enable admin documentation:# 'django.contrib.admindocs',++ # Apps from workout manager'manager','weight','exercises',@@ -143,6 +167,9 @@ INSTALLED_APPS = (# reCaptcha support, see https://github.com/praekelt/django-recaptcha'captcha',++ # The sitemaps app+ 'django.contrib.sitemaps',)diff --git a/workout_manager/urls.py b/workout_manager/urls.pyindex b024ac7cc..7cf82acce 100644--- a/workout_manager/urls.py+++ b/workout_manager/urls.py@@ -1,9 +1,17 @@from django.conf.urls import include, urlfrom django.conf.urls.i18n import i18n_patterns+from django.conf.urls.i18n import patterns+from django.views.generic.simple import direct_to_template++from exercises.sitemap import ExercisesSitemap+from nutrition.sitemap import NutritionSitemapfrom django.contrib import adminadmin.autodiscover()+sitemaps = {'exercises': ExercisesSitemap,+ 'nutrition': NutritionSitemap}+urlpatterns = i18n_patterns('',url(r'^admin/', include(admin.site.urls)),url(r'^', include('manager.urls')),@@ -12,4 +20,11 @@ urlpatterns = i18n_patterns('',url(r'nutrition/', include('nutrition.urls')),url(r'software/', include('software.urls', namespace='software', app_name='software')),url(r'^browserid/', include('django_browserid.urls')),+ url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': sitemaps})+)++# Send robots.txt without any language prefix+urlpatterns = urlpatterns + patterns('',+ (r'^robots\.txt$', direct_to_template,+ {'template': 'robots.txt', 'mimetype': 'text/plain'}),)