From 4445a9086c83037ea1b924a7476017e7f07967c1 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Fri, 17 Jan 2014 18:24:34 +0000 Subject: [PATCH] include overview text in sitemap.xml --- pandora/item/tasks.py | 16 ++++++++++++++++ pandora/text/models.py | 11 +++++++---- pandora/text/views.py | 6 +++--- pandora/urls.py | 2 ++ 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/pandora/item/tasks.py b/pandora/item/tasks.py index 10a6e2acf..a8f6610eb 100644 --- a/pandora/item/tasks.py +++ b/pandora/item/tasks.py @@ -163,6 +163,22 @@ def update_sitemap(base_url): el = ET.SubElement(video, "video:duration") el.text = "%s" % int(duration) + if Text.objects.filter(name='').exclude(text='').exists(): + t = Text.objects.filter(name='')[0] + url = ET.SubElement(urlset, "url") + # URL of the page. This URL must begin with the protocol (such as http) + loc = ET.SubElement(url, "loc") + loc.text = absolute_url('/texts') + # This date should be in W3C Datetime format, can be %Y-%m-%d + lastmod = ET.SubElement(url, "lastmod") + lastmod.text = t.modified.strftime("%Y-%m-%d") + # always, hourly, daily, weekly, monthly, yearly, never + changefreq = ET.SubElement(url, "changefreq") + changefreq.text = 'monthly' + # priority of page on site values 0.1 - 1.0 + priority = ET.SubElement(url, "priority") + priority.text = '1.0' + for t in Text.objects.filter(Q(status='featured')|Q(status='public')): url = ET.SubElement(urlset, "url") # URL of the page. This URL must begin with the protocol (such as http) diff --git a/pandora/text/models.py b/pandora/text/models.py index 2ff188f6c..46a166dac 100644 --- a/pandora/text/models.py +++ b/pandora/text/models.py @@ -56,10 +56,13 @@ class Text(models.Model): @classmethod def get(cls, id): - id = id.split(':') - username = id[0] - name = ":".join(id[1:]) - return cls.objects.get(user__username=username, name=name) + if id == '': + return cls.objects.get(name='') + else: + id = id.split(':') + username = id[0] + name = ":".join(id[1:]) + return cls.objects.get(user__username=username, name=name) def get_absolute_url(self): return '/texts/%s' % quote(self.get_id().replace('_', '\t').replace(' ', '_')).replace('/', '%2F') diff --git a/pandora/text/views.py b/pandora/text/views.py index 9d96a918f..a5d769e29 100644 --- a/pandora/text/views.py +++ b/pandora/text/views.py @@ -437,12 +437,12 @@ def upload(request): response = json_response(status=400, text='this request requires POST') return render_to_json_response(response) -def text(request, id): +def text(request, id=''): id = id.replace('_', ' ').replace('\t', '_') try: text = models.Text.get(id) - if not text.accessible(request.user): + if id != '' and not text.accessible(request.user): raise template = 'text.html' context = RequestContext(request, { @@ -454,7 +454,7 @@ def text(request, id): 'title': ox.strip_tags(text.name), 'url': request.build_absolute_uri(text.get_absolute_url()), }) - except models.Text.DoesNotExist: + except: template = 'index.html' context = RequestContext(request, { 'base_url': request.build_absolute_uri('/'), diff --git a/pandora/urls.py b/pandora/urls.py index fa2cf346f..13943f2f5 100644 --- a/pandora/urls.py +++ b/pandora/urls.py @@ -37,6 +37,8 @@ urlpatterns = patterns('', (r'^text/(?P.*?)/icon(?P\d*).jpg$', 'text.views.icon'), (r'^texts/(?P.*?)/text.pdf$', 'text.views.pdf'), (r'^texts/(?P.*?)/text.pdf.html$', 'text.views.pdf_viewer'), + (r'^texts/$', 'text.views.text'), + (r'^texts/(?P.*?)/\d+$', 'text.views.text'), (r'^texts/(?P.*?)$', 'text.views.text'), (r'^robots.txt$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'robots.txt'), 'content_type': 'text/plain'}), (r'^favicon.ico$', serve_static_file, {'location': os.path.join(settings.STATIC_ROOT, 'png/icon.16.png'), 'content_type': 'image/x-icon'}),