Skip to content

armgit / wger

Public Imported from GitHub
0

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.py
new file mode 100644
index 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.txt
new file mode 100644
index 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.xml
diff --git a/manager/urls.py b/manager/urls.py
index 206b09564..5ceb897b2 100644
--- a/manager/urls.py
+++ b/manager/urls.py
@@ -2,8 +2,6 @@ from django.conf.urls import patterns, url
from django.contrib.auth.decorators import login_required
from django.core.urlresolvers import reverse_lazy
-from django.views.generic import TemplateView
-
from manager.views import WorkoutEditView
from manager.views import WorkoutDeleteView
from manager.views import WorkoutLogDetailView
@@ -19,10 +17,10 @@ urlpatterns = patterns('manager.views',
# The landing page
url(r'^$', 'index', name='index'),
-
+
# The dashboard
url(r'^dashboard$', 'dashboard', name='dashboard'),
-
+
# User
url(r'^logout$', 'logout', name='logout'),
diff --git a/nutrition/sitemap.py b/nutrition/sitemap.py
new file mode 100644
index 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.html
index 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 syncdb
diff --git a/workout_manager/settings_global.py b/workout_manager/settings_global.py
index 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.py
index b024ac7cc..7cf82acce 100644
--- a/workout_manager/urls.py
+++ b/workout_manager/urls.py
@@ -1,9 +1,17 @@
from django.conf.urls import include, url
from 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 NutritionSitemap
from django.contrib import admin
admin.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'}),
)