Implement some site maps

This is incomplete as events etc are not implemented yet, but should suffice as a decent starting point

Closes #27, but we should track this for new apps
parent dc613930
......@@ -101,6 +101,9 @@ class Board(Committee):
default=True,
)
def get_absolute_url(self):
return '/committee/boards/{}'.format(self.name.lower())
class ActiveMembershipManager(models.Manager):
"""Get only active memberships"""
......@@ -110,8 +113,8 @@ class ActiveMembershipManager(models.Manager):
class CommitteeMembership(models.Model):
active_memberships = ActiveMembershipManager()
objects = models.Manager()
active_memberships = ActiveMembershipManager()
member = models.ForeignKey(
Member,
......
from django.contrib import sitemaps
from django.urls import reverse
from . import models
class StaticViewSitemap(sitemaps.Sitemap):
priority = 0.5
changefreq = 'daily'
def items(self):
return ['committees:index']
def location(self, item):
return reverse(item)
class CommitteeSitemap(sitemaps.Sitemap):
def items(self):
return models.Committee.active_committees.all()
def location(self, item):
return item.get_absolute_url()
class BoardSitemap(sitemaps.Sitemap):
changefreq = 'yearly'
def items(self):
return models.Board.objects.all()
def location(self, item):
return item.get_absolute_url()
sitemap = {
'committees-static': StaticViewSitemap,
'committees-committees': CommitteeSitemap,
'committees-boards': BoardSitemap,
}
......@@ -9,5 +9,5 @@ from . import views
urlpatterns = [
url(r'^$', views.index, name='index'),
url(r'^details/(?P<committee_id>\d)/$', views.details, name='details'),
url(r'^boards/(board-(?P<year>\d{4}-\d{4}))?$', views.boards, name='boards'),
url(r'^boards/(board-(?P<year>\d{4}-\d{4}))?$', views.boards, name='board'),
]
from django.db import models
from django.utils import timezone
from django.core.validators import MinValueValidator
from django.urls import reverse
from utils.validators import validate_file_extension
......@@ -41,6 +42,9 @@ class MiscellaneousDocument(models.Model):
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('documents:miscellaneous-document', args=(self.pk,))
class GeneralMeeting(models.Model):
minutes = models.FileField(
......
from django.contrib import sitemaps
from django.urls import reverse
from . import models
class StaticViewSitemap(sitemaps.Sitemap):
priority = 0.5
changefreq = 'daily'
def items(self):
return ['documents:index']
def location(self, item):
return reverse(item)
class MiscellaneousDocumentsSitemap(sitemaps.Sitemap):
def items(self):
return models.MiscellaneousDocument.objects.exclude(members_only=True)
def location(self, item):
return item.get_absolute_url()
sitemap = {
'documents-static': StaticViewSitemap,
'documents-miscellaneous': MiscellaneousDocumentsSitemap,
}
from django.contrib import sitemaps
from django.urls import reverse
from . import models
class StaticViewSitemap(sitemaps.Sitemap):
priority = 0.5
changefreq = 'daily'
def items(self):
return ['members:index']
def location(self, item):
return reverse(item)
class BecomeAMemberDocumentSitemap(sitemaps.Sitemap):
priority = 0.1
def items(self):
return models.BecomeAMemberDocument.objects.all()
def location(self, item):
return reverse('members:become-a-member-document', args=(item.pk,))
sitemap = {
'members-static': StaticViewSitemap,
'members-become-documents': BecomeAMemberDocumentSitemap,
}
......@@ -5,5 +5,5 @@ from . import views
urlpatterns = [
url('^become-a-member-document/(?P<pk>[0-9]*)', views.get_become_a_member_document, name='become-a-member-document'),
url('^', views.index),
url('^', views.index, name='index'),
]
from django.contrib import sitemaps
from django.urls import reverse
class StaticViewSitemap(sitemaps.Sitemap):
changefreq = 'monthly'
def items(self):
return ['merchandise:index']
def location(self, item):
return reverse(item)
sitemap = {
'merchandise-static': StaticViewSitemap,
}
......@@ -2,6 +2,7 @@ from django.db import models
from django.conf import settings
from django.core.validators import MinValueValidator
from django.utils.text import slugify
from django.urls import reverse
from utils.validators import validate_file_extension
......@@ -48,6 +49,10 @@ class Thabloid(models.Model):
os.path.dirname(self.page_url())))
return [self.page_url(i+1) for i in range(len(pages))]
def get_absolute_url(self):
return reverse('viewer', kwargs={'year': self.year,
'issue': self.issue})
def save(self, *args, **kwargs):
super(Thabloid, self).save(*args, **kwargs)
src = self.file.path
......
from django.contrib import sitemaps
from django.urls import reverse
from . import models
class StaticViewSitemap(sitemaps.Sitemap):
changefreq = 'monthly'
def items(self):
return ['thabloid:index']
def location(self, item):
return reverse(item)
class ThabloidSitemap(sitemaps.Sitemap):
changefreq = 'never'
def items(self):
return models.Thabloid.objects.all()
def location(self, item):
return item.get_absolute_url()
sitemap = {
'thabloid-static': StaticViewSitemap,
'thabloid-thabloids': ThabloidSitemap,
}
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2016-08-17 18:15
from __future__ import unicode_literals
from django.db import migrations
def insert_sites(apps, schema_editor):
"""Populate the sites model"""
Site = apps.get_model('sites', 'Site')
Site.objects.create(domain='thalia.nu', name='thalia')
class Migration(migrations.Migration):
dependencies = [
('sites', '0001_initial'),
]
operations = [
migrations.RunPython(insert_sites)
]
......@@ -39,6 +39,8 @@ INSTALLED_APPS = [
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'django.contrib.sitemaps',
# Dependencies
'static_precompiler',
'tinymce',
......
from django.contrib import sitemaps
from django.urls import reverse
class StaticViewSitemap(sitemaps.Sitemap):
priority = 0.5
changefreq = 'daily'
def items(self):
return ['index', 'become-active', 'sister-associations', 'contact']
def location(self, item):
return reverse(item)
......@@ -19,11 +19,26 @@ from django.conf import settings
from django.conf.urls import url, include
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.views.generic import TemplateView
from utils.views import private_thumbnails
import members
from .sitemaps import StaticViewSitemap
from committees.sitemaps import sitemap as committees_sitemap
from members.sitemaps import sitemap as members_sitemap
from documents.sitemaps import sitemap as documents_sitemap
from thabloid.sitemaps import sitemap as thabloid_sitemap
thalia_sitemap = {
'main-static': StaticViewSitemap,
}
thalia_sitemap.update(committees_sitemap)
thalia_sitemap.update(members_sitemap)
thalia_sitemap.update(documents_sitemap)
thalia_sitemap.update(thabloid_sitemap)
urlpatterns = [
url(r'^$', TemplateView.as_view(template_name='index.html'), name='index'),
url(r'^admin/', admin.site.urls),
......@@ -49,6 +64,9 @@ urlpatterns = [
# Default login helpers
url(r'^', include('django.contrib.auth.urls')),
url(r'^i18n/', include('django.conf.urls.i18n')),
# Sitemap
url(r'^sitemap\.xml$', sitemap, {'sitemaps': thalia_sitemap},
name='django.contrib.sitemaps.views.sitemap'),
# Dependencies
url(r'^tinymce/', include('tinymce.urls')),
] + static(settings.MEDIA_URL + 'public/',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment