Commit a97dc289 authored by alexandre's avatar alexandre
Browse files

Seperating project from apps

parent 7084a533
......@@ -4,7 +4,6 @@ import sys
from datetime import datetime
from ethertoff.settings import MEDIA_ROOT
from etherpadlite.models import Pad, PadAuthor, PadServer
from django.contrib.auth.models import AnonymousUser
from django.contrib.sites.shortcuts import get_current_site
......
......@@ -18,7 +18,7 @@ from django.core.management.base import BaseCommand, CommandError
# Django Apps import
from etherpadlite.models import Pad, PadAuthor
from ethertoff.settings import BACKUP_DIR
from django.conf import settings
class Command(BaseCommand):
args = ''
......@@ -32,7 +32,7 @@ class Command(BaseCommand):
text = epclient.getText(padID)['text']
backup_file_path = os.path.join(BACKUP_DIR, pad.display_slug)
backup_file_path = os.path.join(settings.BACKUP_DIR, pad.display_slug)
with open(backup_file_path.encode('utf-8'), 'w') as f:
f.write(text.encode('utf-8'))
......@@ -23,7 +23,7 @@ from django.template.loader import render_to_string
from django.contrib.sites.models import Site
from etherpadlite.models import Pad, PadAuthor
from ethertoff.settings import BACKUP_DIR
from django.conf import settings
"""
We scrape all the pages, construct a graph, and ask the RDF store to return us all the metadata.
......@@ -195,9 +195,9 @@ def snif():
d = query_results_to_template_articles(g.query(sparql_query))
with open(os.path.join(BACKUP_DIR, "index.json"), 'w') as f:
with open(os.path.join(settings.BACKUP_DIR, "index.json"), 'w') as f:
json.dump(d, f, indent=2, ensure_ascii=False)
# with open(os.path.join(BACKUP_DIR, "index.html"), 'w') as f:
# with open(os.path.join(settings.BACKUP_DIR, "index.html"), 'w') as f:
# f.write(render_to_string("home.html", {"articles" : d}).encode('utf-8'))
duration = clock() - start
......
......@@ -2,7 +2,8 @@
from django import template
from django.template.defaultfilters import stringfilter
from ethertoff.settings import PAD_NAMESPACE_SEPARATOR, PAD_NAMESPACE_SEPARATOR_DISPLAY
from django.conf import settings
register = template.Library()
......@@ -10,17 +11,18 @@ register = template.Library()
@stringfilter
def dewikify(name):
name = name.replace('-', ' ')
name = name.replace(PAD_NAMESPACE_SEPARATOR, PAD_NAMESPACE_SEPARATOR_DISPLAY)
name = name.replace(settings.PAD_NAMESPACE_SEPARATOR, settings.PAD_NAMESPACE_SEPARATOR_DISPLAY)
return name
@register.filter
def wikifyPath(value):
return value.replace('/', PAD_NAMESPACE_SEPARATOR)
return value.replace('/', settings.PAD_NAMESPACE_SEPARATOR)
@register.filter
def stripPath(value, path):
if path is not None and len(path) > 0:
from ethertoff.settings import PAD_NAMESPACE_SEPARATOR as PNS
from django.conf import settings
PNS = settings.PAD_NAMESPACE_SEPARATOR
pathstring = '{}{}'.format(PNS.join(path), PNS)
return value.replace(pathstring, '')
......@@ -40,4 +42,4 @@ def ensureTrailingSlash(path):
if len(path) > 0:
if path[-1] != '/':
return '{}/'.format(path)
return path
\ No newline at end of file
return path
......@@ -14,19 +14,6 @@ from django.conf.urls.static import static
from django.contrib import admin
admin.autodiscover()
# This is to allow the website to work under a subfolder
# i.e. http://ethertoff.be/2015/
# Define SUBFOLDER in your local_settings.py
BASE_URL = '^'
try:
BASE_URL = r'^' + settings.SUBFOLDER
if BASE_URL and not BASE_URL.endswith(r'/'):
BASE_URL += r'/'
except AttributeError:
pass
app_name = "ethertoff"
urlpatterns = [
path('', views.home, name='home'),
path('admin/', admin.site.urls),
......@@ -59,8 +46,4 @@ urlpatterns = [
#re_path(r's/(?P<slug>[^/]+)$', views.pad, name='pad-slide'),
#re_path(r'p/(?P<slug>[^/]+)$', views.pad, name='pad-print'),
re_path(r'w/(?P<slug>[^/]+)$', views.pad, name='pad-write'),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
#urlpatterns = [
#path(BASE_URL , include(base_urlpatterns)),
#]
]
......@@ -32,6 +32,7 @@ from django.contrib.auth.decorators import login_required
from django.utils.translation import ugettext_lazy as _
from django.db import IntegrityError
from django.core.paginator import Paginator
from django.conf import settings
# Django Apps import
......@@ -49,16 +50,14 @@ from . import forms as ethertoffForms
# By default, the homepage is the pad called ‘start’ (props to DokuWiki!)
try:
from ethertoff.settings import HOME_PAD
HOME_PAD = settings.HOME_PAD
except ImportError:
HOME_PAD = 'About.md'
try:
from ethertoff.settings import BACKUP_DIR
BACKUP_DIR = settings.BACKUP_DIR
except ImportError:
BACKUP_DIR = None
from ethertoff.settings import PAD_FORCE_EXTENSION, PAD_ALLOWED_EXTENSIONS, PAD_DEFAULT_EXTENSION, PADS_PER_PAGE, PAD_NAMESPACE_SEPARATOR, MAX_PAD_SAVE_TRIES, API_LOCAL_URL
"""
Set up an HTMLParser for the sole purpose of unescaping
Etherpad’s HTML entities.
......@@ -89,8 +88,8 @@ def insertAt (path=[], tree=[], pad=''):
return tree
def insertPad (pad, tree):
if PAD_NAMESPACE_SEPARATOR in pad.display_slug:
path = pad.display_slug.split(PAD_NAMESPACE_SEPARATOR)
if settings.PAD_NAMESPACE_SEPARATOR in pad.display_slug:
path = pad.display_slug.split(settings.PAD_NAMESPACE_SEPARATOR)
else:
path = []
......@@ -99,7 +98,7 @@ def insertPad (pad, tree):
# Perhaps move to the model?
def makePadPublic (pad, n=0):
if not pad.is_public:
epclient = EtherpadLiteClient(pad.server.apikey, API_LOCAL_URL if API_LOCAL_URL else pad.server.apiurl)
epclient = EtherpadLiteClient(pad.server.apikey, settings.API_LOCAL_URL if settings.API_LOCAL_URL else pad.server.apiurl)
tail = '' if n == 0 else '-{}'.format(n)
publicid = pad.name+tail
......@@ -118,7 +117,7 @@ def makePadPublic (pad, n=0):
def makePadPrivate(pad):
if pad.is_public:
epclient = EtherpadLiteClient(pad.server.apikey, API_LOCAL_URL if API_LOCAL_URL else pad.server.apiurl)
epclient = EtherpadLiteClient(pad.server.apikey, settings.API_LOCAL_URL if settings.API_LOCAL_URL else pad.server.apiurl)
res = epclient.movePad(pad.publicpadid, pad.padid, force=True)
pad.is_public = False
......@@ -138,9 +137,9 @@ def filterPadSlug(slug):
def ensurePadExtension(slug):
name, ext = os.path.splitext(slug)
if PAD_FORCE_EXTENSION:
if ext.lower() not in PAD_ALLOWED_EXTENSIONS:
ext = PAD_DEFAULT_EXTENSION
if settings.PAD_FORCE_EXTENSION:
if ext.lower() not in settings.PAD_ALLOWED_EXTENSIONS:
ext = settings.PAD_DEFAULT_EXTENSION
return '{}{}'.format(name, ext.lower())
......@@ -184,8 +183,8 @@ def createPad (slug, server, group, n=0):
# Move as a property to the model ?
def getFolderName (slug):
if PAD_NAMESPACE_SEPARATOR in slug:
return slug.rsplit(PAD_NAMESPACE_SEPARATOR, 1)[0]
if settings.PAD_NAMESPACE_SEPARATOR in slug:
return slug.rsplit(settings.PAD_NAMESPACE_SEPARATOR, 1)[0]
else:
return None
......@@ -253,7 +252,7 @@ def padDelete(request, pk):
def renamePad(pad, slug, n=0):
pad.display_slug = treatPadName(slug, n)
while n < MAX_PAD_SAVE_TRIES:
while n < settings.MAX_PAD_SAVE_TRIES:
try:
return pad.save()
except IntegrityError:
......@@ -267,7 +266,7 @@ def padRename(request, pk):
form = ethertoffForms.PadRename(request.POST)
if form.is_valid():
renamePad(pad, form.cleaned_data['name'])
return redirect('manage', path=getFolderName(pad.display_slug).replace(PAD_NAMESPACE_SEPARATOR, '/'))
return redirect('manage', path=getFolderName(pad.display_slug).replace(settings.PAD_NAMESPACE_SEPARATOR, '/'))
else:
form = ethertoffForms.PadRename({
'pk': pad.pk,
......@@ -387,7 +386,7 @@ def pad_write(request, pad):
server = urlparse(pad.server.url)
author = PadAuthor.objects.get(user=request.user)
path = pad.display_slug.split(PAD_NAMESPACE_SEPARATOR)
path = pad.display_slug.split(settings.PAD_NAMESPACE_SEPARATOR)
crumbs = [(path[i], path[:i+1]) for i in range(len(path))]
if author not in pad.group.authors.all():
......@@ -409,7 +408,7 @@ def pad_write(request, pad):
expires = datetime.datetime.utcnow() + datetime.timedelta(
seconds=config.SESSION_LENGTH
)
epclient = EtherpadLiteClient(pad.server.apikey, API_LOCAL_URL if API_LOCAL_URL else pad.server.apiurl)
epclient = EtherpadLiteClient(pad.server.apikey, settings.API_LOCAL_URL if settings.API_LOCAL_URL else pad.server.apiurl)
# Try to use existing session as to allow editing multiple pads at once
makeNewSessionID = False
......@@ -514,8 +513,8 @@ def pad_read(request, mode="r", slug=None):
# Initialize some needed values
pad = get_object_or_404(Pad, display_slug=slug)
padID = pad.publicpadid if pad.is_public else pad.group.groupID + '$' + urllib.parse.quote(pad.name.replace(PAD_NAMESPACE_SEPARATOR, '_'))
epclient = EtherpadLiteClient(pad.server.apikey, API_LOCAL_URL if API_LOCAL_URL else pad.server.apiurl)
padID = pad.publicpadid if pad.is_public else pad.group.groupID + '$' + urllib.parse.quote(pad.name.replace(settings.PAD_NAMESPACE_SEPARATOR, '_'))
epclient = EtherpadLiteClient(pad.server.apikey, settings.API_LOCAL_URL if settings.API_LOCAL_URL else pad.server.apiurl)
# Etherpad gives us authorIDs in the form ['a.5hBzfuNdqX6gQhgz', 'a.tLCCEnNVJ5aXkyVI']
# We link them to the Django users DjangoEtherpadLite created for us
......@@ -560,7 +559,7 @@ def pad_read(request, mode="r", slug=None):
# Create namespaces from the url of the pad
# 'pedagogy::methodology' -> ['pedagogy', 'methodology']
namespaces = [p.rstrip('-') for p in pad.display_slug.split(PAD_NAMESPACE_SEPARATOR)]
namespaces = [p.rstrip('-') for p in pad.display_slug.split(settings.PAD_NAMESPACE_SEPARATOR)]
meta_list = []
......@@ -685,10 +684,10 @@ def generate(request):
def manage(request, path=[]):
if len(path) > 0:
path = path.split('/')
pads = Pad.objects.filter(display_slug__startswith=PAD_NAMESPACE_SEPARATOR.join(path) + PAD_NAMESPACE_SEPARATOR).order_by('name')
pads = Pad.objects.filter(display_slug__startswith=settings.PAD_NAMESPACE_SEPARATOR.join(path) + settings.PAD_NAMESPACE_SEPARATOR).order_by('name')
else:
pads = Pad.objects.all().order_by('name')
# paginator = Paginator(pads, PADS_PER_PAGE)
# paginator = Paginator(pads, settings.PADS_PER_PAGE)
tree = makeLeaf()
......@@ -724,8 +723,8 @@ def all_private(request):
def padOrFallbackPath(request, slug, fallbackPath, mimeType):
try:
pad = Pad.objects.get(display_slug=slug)
padID = pad.group.groupID + '$' + urllib.parse.quote(pad.name.replace(PAD_NAMESPACE_SEPARATOR, '_'))
epclient = EtherpadLiteClient(pad.server.apikey, API_LOCAL_URL if API_LOCAL_URL else pad.server.apiurl)
padID = pad.group.groupID + '$' + urllib.parse.quote(pad.name.replace(settings.PAD_NAMESPACE_SEPARATOR, '_'))
epclient = EtherpadLiteClient(pad.server.apikey, settings.API_LOCAL_URL if settings.API_LOCAL_URL else pad.server.apiurl)
return HttpResponse(epclient.getText(padID)['text'], content_type=mimeType)
except:
# If there is no pad called "css", loads a default css file
......@@ -744,4 +743,4 @@ def offsetprint(request):
return padOrFallbackPath(request, 'offset.css', 'ethertoff/static/css/offset.css', 'text/css')
def css_slide(request):
return padOrFallbackPath(request, 'slidy.css', 'ethertoff/static/css/slidy.css', 'text/css')
\ No newline at end of file
return padOrFallbackPath(request, 'slidy.css', 'ethertoff/static/css/slidy.css', 'text/css')
@import "reset.css";
@import "fonts.css";
/*-- REDEFINE TAGS ---------------------------------------- */
body {
background: #fff;
color: #333;
font-family: "Univers Light";
font-size: 12px;
line-height: 1.5em;
padding: 0.5em;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
word-wrap: break-word;
font-feature-settings: "liga", "dlig", "clig", "kern";
-webkit-font-feature-settings: "liga", "dlig", "clig", "kern";
-o-font-feature-settings: "liga", "dlig", "clig", "kern";
text-rendering: optimizeLegibility;
color: red;
}
/* - BLOCKS ------------------------------------- */
iframe {
outline: 1px solid #333;
}
div {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
img {
border: 3px solid #333;
max-width: 70%;
margin-left: 15%;
margin-bottom: 1em;
}
blockquote {
font-style: italic;
margin-left: 2em;
}
blockquote div {
font-family: patin, serif;
}
p {
margin-bottom: 48px;
}
p + p {
text-indent: 1.5em;
}
legend {
font-size: 0.75em;
line-height: 1.4em;
}
code, pre {
font-family: notcouriersans, monospace;
}
/* - INLINES ------------------------------------- */
a {
color: inherit;
}
a:hover {
background-color: #f7f7f7;
}
h1 {
font-size: 2em !important;
line-height: 1em !important;
position: relative;
z-index: 20;
line-height: 2em;
font-weight: normal;
font-family: "HerscheyFutura", sans-serif;
margin-bottom: 12px;
}
h2 {
font-family: "HerscheyFutura", sans-serif;
font-size: 1em;
line-height: 1.5em;
letter-spacing: 0.08em;
text-transform: uppercase;
margin-bottom: 9px;
}
h3, h4, h5, h6 {
font-weight: normal;
font-family: Univers, sans-serif;
}
h3 {
margin-top: 0px;
text-transform: uppercase;
margin-bottom: 0;
font-size: 28px;
}
h4 {
text-decoration: underline;
margin-bottom: 0;
}
em {
font-style: italic;
}
strong {
font-weight: bold;
}
sup {
font-size: 0.75em;
line-height: 0;
vertical-align: 0.25em;
}
li u {
text-decoration: none;
border-bottom: 1px solid #333;
}
u {
text-decoration: none;
border-bottom: 1px solid #333;
}
/* -- FORMS --------------------------*/
form {
margin-bottom: 1.5em;
}
form label, form textarea {
font-size: 13.33px;
}
form input, form textarea {
background: none;
border: 1px solid #333;
color: #333;
font-family: patin;
}
form input:focus, form textarea:focus {
background-color: white;
}
form input[type=text], form input[type=password] {
height: 20px;
position: relative;
top: -1px;
}
form input[type=submit] {
cursor: pointer;
padding: 0;
height: 24px;
}
form input[type=submit]:hover {
background-color: white;
}
/* - GENERIC CLASSES -------------------------------- */
.button {
text-decoration: none;
border: 1px solid MediumSeaGreen;
padding: 7px 5px;
box-shadow: 0 0 30px 10px #f7f7f7;
margin: 0 0.5em;
position: relative;
top: -3px;
background-color: #f7f7f7;
}
.button:hover {
background-color: white;
}
.small {
font-family: notcouriersans;
color: #333;
font-size: 1em;
line-height: 1.2em;
margin-left: 0cm;
margin-right: 0cm;
}
.inline {
display: inline;
}
/* - PAGE STRUCTURE ---------------------------------*/
.wrap {
margin-bottom: 20px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.wrap:before, .wrap:after {
content: " ";
/* 1 */
display: table;
/* 2 */
}
.wrap:after {
clear: both;
}
.left-side, .middle, .right-side {
float: left;
padding: 10px;
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
}
.left-side {
width: 15%;
}
.right-side {
width: 25%;
}
.middle {
width: 60%;
padding: 10px 20px;
}
/* - NAV ------------------------------------------*/
nav {
line-height: 1.2em;
margin-bottom: 2em;
font-size: 13.33px;
}
nav li {
list-style-position: outside;
list-style-type: none;
margin-left: 14px;
}
nav > ul > li {
margin-left: 0;
}
nav li#create-pad {
list-style-type: none;
margin: 1.5em;
font-size: 16px;
}
nav a {
text-decoration: none;
}
#account-buttons {
margin-top: 14px;
}
#account-buttons li {
display: inline;
}
div#switch {
display: inline;
}
div#switch a.active {
background-color: white;
}
/* - MAIN CONTENT ----------------------------------*/
#content {
font-weight: 200;
}
#content li:before {
content: "– ";
margin-left: 2em;
}
div.intro {
font-family: AutopiaLight, serif;
line-height: 1.8em;
font-size: 12px;
}
.titlepages {
font-family: HerscheyTimes, serif;
font-size: 50px;
line-height: 1em;
}
.notes {
font-family: notcouriersans;
font-size: 1em;
color: #333;
line-height: 1.2em;
margin-left: 0cm;
margin-right: 0cm;
}
ul.indent li:before {
content: "" !important;
}
.inst_logo {
height: 20%;
margin-left: 0;
}
.right-side h2 {
margin-bottom: 1em;
}
div#quotes {
text-align: center;
height: 360px;
}
p.commit-message {
margin-bottom: 0px;
}
/* - AUTHORSHIP -----------------------------*/
.authorship {
font-family: Univers;
font-size: .4em;
height: 1.7em;
color: #333;
text-transform: uppercase;
position: absolute;
margin-top: .9em;
padding-top: 1em;
margin-left: -0.5em;
padding-left: 2px;
border-left: 1px solid #333;
}
.authors {
display: block;
}
ul.authors {
font-size: 11px;
margin-bottom: 10px;
line-height: 25px;
}
ul.authors:before {
margin: 0;
content: "Authors : "
}
ul.authors li {
font-size: 11px;
letter-spacing: 0.5px;
display: inline-block;
border: 1px solid #333;
margin-right: 0.5em;
padding: 0px 5px;
text-transform: uppercase;
height: 23px;
}
ul.authors li:before {
margin-left: 0 !important;
content: "" !important;
}
/* Hides Etherpad background colours */
#content span {
background-color: inherit !important;
}
/* ------ PRINT ------ */
@media screen {
.print-only {
display: none;
}