Commit d1ab5668 authored by svilayphiou's avatar svilayphiou

Attempt to fix the Site domain error when indexing the pads.

I put it in a function so that it's not executed when applying the
migrations at the install of Ethertoff.
The function is launched only when indexing.
parent 2c1c1628
......@@ -175,7 +175,8 @@ class Pad(models.Model):
return self.display_slug
def get_absolute_url(self):
return reverse('ethertoff.views.xhtml', args=[self.display_slug.replace('.md','')])
#return reverse('ethertoff.views.xhtml', args=[self.display_slug.replace('.md','')])
return ('pad-read', (), {'slug': self.display_slug.replace('.md','')})
@property
def padid(self):
......
......@@ -7,7 +7,7 @@ import re
import sys
import codecs
import json
from urllib import error
from urllib.error import HTTPError
from time import clock
# PyPi imports
......@@ -21,7 +21,7 @@ from django.template.loader import render_to_string
# Django Apps import
#from django.contrib.sites.models import Site
from django.contrib.sites.models import Site
from etherpadlite.models import Pad, PadAuthor
from ethertoff.settings import BACKUP_DIR
......@@ -99,9 +99,11 @@ short_names = {
}
HOST = None
#if Site.objects.count() > 0:
#site = Site.objects.all()[0]
#HOST = site.domain
def get_host():
if Site.objects.count() > 0:
site = Site.objects.all()[0]
HOST = site.domain
return HOST
def query_results_to_template_articles(query_results):
"""
......@@ -116,9 +118,9 @@ def query_results_to_template_articles(query_results):
for s, p, o in query_results:
print(s.encode('utf-8'), p.encode('utf-8'), o.encode('utf-8'))
uri = unicode(s).strip()
key = unicode(p).strip()
value = unicode(o).strip()
uri = str(s).strip()
key = str(p).strip()
value = str(o).strip()
if uri != current_uri:
if article:
......@@ -159,6 +161,7 @@ def query_results_to_template_articles(query_results):
def snif():
global HOST
HOST = get_host()
if not HOST:
return "No site domain settings found"
host = u"http://%s" % HOST
......@@ -180,9 +183,14 @@ def snif():
print("no *.md extension, probably not meant for publication")
continue
try:
result = g.parse(host + pad.get_absolute_url())
print(host)
print(pad.get_absolute_url())
slug = pad.get_absolute_url()[2]["slug"] + ".md"
print(slug)
result = g.parse(host + "/r/" + slug)
print(result)
print("succesfully parsed")
except(HTTPError, e):
except HTTPError as e:
if e.code == 403:
# Some of the pads will not be public yet—
# They gives a ‘403 FORBIDDEN’ response
......@@ -195,7 +203,7 @@ def snif():
d = query_results_to_template_articles(g.query(sparql_query))
with open(os.path.join(BACKUP_DIR, "index.json"), 'w') as f:
f.write(json.dumps(d, indent=2, ensure_ascii=False).encode('utf-8'))
f.write(json.dumps(d, sort_keys = True, ensure_ascii=False))
# with open(os.path.join(BACKUP_DIR, "index.html"), 'w') as f:
# f.write(render_to_string("home.html", {"articles" : d}).encode('utf-8'))
......
......@@ -15,4 +15,5 @@ python-dateutil>=2.7.3
pytz>=2018.4
rdflib>=4.2.2
six>=1.11.0
South>=1.0.2
\ No newline at end of file
South>=1.0.2
html5lib
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