forked from 0x2620/pandora
sitemap
This commit is contained in:
parent
2c678ec450
commit
578cfc7799
2 changed files with 54 additions and 15 deletions
|
@ -7,6 +7,7 @@ from datetime import timedelta, datetime
|
||||||
import gzip
|
import gzip
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
from six.moves.urllib.parse import quote
|
||||||
from celery.task import task, periodic_task
|
from celery.task import task, periodic_task
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import connection, transaction
|
from django.db import connection, transaction
|
||||||
|
@ -14,7 +15,6 @@ from django.db.models import Q
|
||||||
from ox.utils import ET
|
from ox.utils import ET
|
||||||
|
|
||||||
from app.utils import limit_rate
|
from app.utils import limit_rate
|
||||||
from text.models import Text
|
|
||||||
from taskqueue.models import Task
|
from taskqueue.models import Task
|
||||||
|
|
||||||
|
|
||||||
|
@ -204,39 +204,78 @@ def update_sitemap(base_url):
|
||||||
el = ET.SubElement(video, "video:live")
|
el = ET.SubElement(video, "video:live")
|
||||||
el.text = "no"
|
el.text = "no"
|
||||||
|
|
||||||
if Text.objects.filter(name='').exclude(text='').exists():
|
# Featured Lists
|
||||||
t = Text.objects.filter(name='')[0]
|
from itemlist.models import List
|
||||||
|
for l in List.objects.filter(Q(status='featured') | Q(status='public')):
|
||||||
url = ET.SubElement(urlset, "url")
|
url = ET.SubElement(urlset, "url")
|
||||||
# URL of the page. This URL must begin with the protocol (such as http)
|
# URL of the page. This URL must begin with the protocol (such as http)
|
||||||
loc = ET.SubElement(url, "loc")
|
loc = ET.SubElement(url, "loc")
|
||||||
loc.text = absolute_url('/texts')
|
loc.text = absolute_url("list==%s" % quote(l.get_id()))
|
||||||
|
|
||||||
# This date should be in W3C Datetime format, can be %Y-%m-%d
|
# This date should be in W3C Datetime format, can be %Y-%m-%d
|
||||||
lastmod = ET.SubElement(url, "lastmod")
|
lastmod = ET.SubElement(url, "lastmod")
|
||||||
lastmod.text = t.modified.strftime("%Y-%m-%d")
|
lastmod.text = l.modified.strftime("%Y-%m-%d")
|
||||||
# always, hourly, daily, weekly, monthly, yearly, never
|
# always, hourly, daily, weekly, monthly, yearly, never
|
||||||
changefreq = ET.SubElement(url, "changefreq")
|
changefreq = ET.SubElement(url, "changefreq")
|
||||||
changefreq.text = 'monthly'
|
changefreq.text = 'monthly'
|
||||||
# priority of page on site values 0.1 - 1.0
|
# priority of page on site values 0.1 - 1.0
|
||||||
priority = ET.SubElement(url, "priority")
|
priority = ET.SubElement(url, "priority")
|
||||||
|
priority.text = '1.0' if l.status == 'featured' else '0.75'
|
||||||
|
# Featured Edits
|
||||||
|
from edit.models import Edit
|
||||||
|
for l in Edit.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)
|
||||||
|
loc = ET.SubElement(url, "loc")
|
||||||
|
loc.text = absolute_url(l.get_absolute_url()[1:])
|
||||||
|
|
||||||
|
# This date should be in W3C Datetime format, can be %Y-%m-%d
|
||||||
|
lastmod = ET.SubElement(url, "lastmod")
|
||||||
|
lastmod.text = l.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' if l.status == 'featured' else '0.75'
|
||||||
|
# Featured Collections
|
||||||
|
from documentcollection.models import Collection
|
||||||
|
for l in Collection.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)
|
||||||
|
loc = ET.SubElement(url, "loc")
|
||||||
|
loc.text = absolute_url("documents/collection==%s" % quote(l.get_id()))
|
||||||
|
|
||||||
|
# This date should be in W3C Datetime format, can be %Y-%m-%d
|
||||||
|
lastmod = ET.SubElement(url, "lastmod")
|
||||||
|
lastmod.text = l.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' if l.status == 'featured' else '0.75'
|
||||||
|
|
||||||
|
from document.models import Document
|
||||||
|
for d in Document.objects.filter(rightslevel=0).filter(Q(extension='html') | Q(extension='pdf')):
|
||||||
|
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(d.get_id())
|
||||||
|
|
||||||
|
# This date should be in W3C Datetime format, can be %Y-%m-%d
|
||||||
|
lastmod = ET.SubElement(url, "lastmod")
|
||||||
|
lastmod.text = d.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 = '0.75'
|
||||||
|
if d.collections.filter(Q(status='featured') | Q(status='public')).count():
|
||||||
priority.text = '1.0'
|
priority.text = '1.0'
|
||||||
|
|
||||||
for t in Text.objects.filter(Q(status='featured') | Q(status='public')):
|
data = '<?xml version="1.0" encoding="UTF-8"?>\n' + ET.tostring(urlset).decode()
|
||||||
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(t.get_absolute_url()[1:])
|
|
||||||
|
|
||||||
# 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' if t.status == 'featured' else '0.75'
|
|
||||||
|
|
||||||
data = '<?xml version="1.0" encoding="UTF-8"?>\n' + ET.tostring(urlset)
|
|
||||||
with open(sitemap[:-3], 'wb') as f:
|
with open(sitemap[:-3], 'wb') as f:
|
||||||
f.write(data)
|
f.write(data)
|
||||||
with gzip.open(sitemap, 'wb') as f:
|
with gzip.open(sitemap, 'wb') as f:
|
||||||
|
|
|
@ -1183,7 +1183,7 @@ def atom_xml(request):
|
||||||
el.attrib['height'] = str(thumbheight)
|
el.attrib['height'] = str(thumbheight)
|
||||||
feed.append(entry)
|
feed.append(entry)
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
'<?xml version="1.0" encoding="utf-8" ?>\n' + ET.tostring(feed),
|
'<?xml version="1.0" encoding="utf-8" ?>\n' + ET.tostring(feed).decode(),
|
||||||
'application/atom+xml'
|
'application/atom+xml'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1233,7 +1233,7 @@ def oembed(request):
|
||||||
e = ET.SubElement(oxml, key)
|
e = ET.SubElement(oxml, key)
|
||||||
e.text = unicode(oembed[key])
|
e.text = unicode(oembed[key])
|
||||||
return HttpResponse(
|
return HttpResponse(
|
||||||
'<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n' + ET.tostring(oxml),
|
'<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n' + ET.tostring(oxml).decode(),
|
||||||
'application/xml'
|
'application/xml'
|
||||||
)
|
)
|
||||||
return HttpResponse(json.dumps(oembed, indent=2), 'application/json')
|
return HttpResponse(json.dumps(oembed, indent=2), 'application/json')
|
||||||
|
@ -1293,7 +1293,7 @@ def item_xml(request, id):
|
||||||
oxml = ET.Element('item')
|
oxml = ET.Element('item')
|
||||||
xmltree(oxml, 'item', j)
|
xmltree(oxml, 'item', j)
|
||||||
response = HttpResponse(
|
response = HttpResponse(
|
||||||
'<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n' + ET.tostring(oxml),
|
'<?xml version="1.0" encoding="utf-8" standalone="yes"?>\n' + ET.tostring(oxml).decode(),
|
||||||
'application/xml'
|
'application/xml'
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
Loading…
Reference in a new issue