added documents as a app and model
This commit is contained in:
12
fet2020/documents/__init__.py
Normal file
12
fet2020/documents/__init__.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
from etherpad_lite import EtherpadLiteClient
|
||||||
|
from django.conf import settings
|
||||||
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
t=datetime.now() + timedelta(days=1)
|
||||||
|
|
||||||
|
with open("/srv/andis_test/etherpad-lite/etherpad-lite/APIKEY.txt","r") as f:
|
||||||
|
k=f.read()
|
||||||
|
epc=EtherpadLiteClient( base_params={'apikey':k,}, base_url="http://localhost:9001/api")
|
||||||
|
a=epc.createAuthorIfNotExistsFor(name="andis", authorMapper="andis")
|
||||||
|
g=epc.createGroupIfNotExistsFor(groupMapper="fet")
|
||||||
|
|
||||||
23
fet2020/documents/admin.py
Normal file
23
fet2020/documents/admin.py
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
from django.contrib import admin
|
||||||
|
from .models import Document
|
||||||
|
from django.urls import path
|
||||||
|
from django.contrib.auth import views as auth_views
|
||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
|
||||||
|
@admin.register(Document)
|
||||||
|
class DocumentModelAdmin(admin.ModelAdmin):
|
||||||
|
def my_view(self,request, extra_context=None):
|
||||||
|
return render(request,"admin/documents/preview.html")
|
||||||
|
|
||||||
|
def get_urls(self):
|
||||||
|
urls = super().get_urls()
|
||||||
|
select_list_url = [ path("<int:id>/preview", self.admin_site.admin_view(self.my_view),
|
||||||
|
name='preview'),
|
||||||
|
path("preview", self.admin_site.admin_view(self.my_view),
|
||||||
|
name='preview')
|
||||||
|
|
||||||
|
]
|
||||||
|
return select_list_url #+ urls
|
||||||
|
|
||||||
|
#admin.site.register(Document,DocumentModelAdmin)
|
||||||
7
fet2020/documents/apps.py
Normal file
7
fet2020/documents/apps.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class DocumentsConfig(AppConfig):
|
||||||
|
name = 'documents'
|
||||||
|
from django.contrib.admin.apps import AdminConfig
|
||||||
|
|
||||||
0
fet2020/documents/migrations/__init__.py
Normal file
0
fet2020/documents/migrations/__init__.py
Normal file
8
fet2020/documents/models.py
Normal file
8
fet2020/documents/models.py
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
from django.db import models
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
class Document(models.Model):
|
||||||
|
key = models.CharField(max_length=200, primary_key=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
3
fet2020/documents/tests.py
Normal file
3
fet2020/documents/tests.py
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
||||||
6
fet2020/documents/urls.py
Normal file
6
fet2020/documents/urls.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import documents.views as views
|
||||||
|
from django.urls import path
|
||||||
|
|
||||||
|
urlpatterns=[
|
||||||
|
path("document/<id>", views.document)
|
||||||
|
]
|
||||||
91
fet2020/documents/views.py
Normal file
91
fet2020/documents/views.py
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
from django.shortcuts import render
|
||||||
|
|
||||||
|
# Create your views here.
|
||||||
|
|
||||||
|
|
||||||
|
from django.http import HttpResponseRedirect
|
||||||
|
from django.template import RequestContext
|
||||||
|
from django.contrib.auth.decorators import login_required
|
||||||
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
import urllib
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
from .models import Document
|
||||||
|
from documents import epc
|
||||||
|
from documents import g as group
|
||||||
|
SERVER_URL="http://etherpad.2020.fet.at/"
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
@login_required
|
||||||
|
def document(request, id=None):
|
||||||
|
"""Create and session and display an embedded pad
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Initialize some needed values
|
||||||
|
#pad = Document.objects.get(key=id)
|
||||||
|
padID=id
|
||||||
|
padLink = SERVER_URL + 'p/' + group["groupID"] + '$' + \
|
||||||
|
padID
|
||||||
|
server = urlparse(SERVER_URL)
|
||||||
|
author = epc.createAuthorIfNotExistsFor(name=str(request.user), authorMapper=str(request.user))['authorID']
|
||||||
|
|
||||||
|
|
||||||
|
# Create the session on the etherpad-lite side
|
||||||
|
expires = datetime.datetime.utcnow() + datetime.timedelta(
|
||||||
|
hours=3
|
||||||
|
)
|
||||||
|
epclient = epc
|
||||||
|
|
||||||
|
try:
|
||||||
|
result = epclient.createSession(
|
||||||
|
groupID=str(group['groupID']),
|
||||||
|
authorID=str(author),
|
||||||
|
validUntil=str(int(expires.timestamp()))
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
response = render(
|
||||||
|
'etherpad-lite/pad.html',
|
||||||
|
{
|
||||||
|
'pad': padID,
|
||||||
|
'link': padLink,
|
||||||
|
'server': str(server),
|
||||||
|
'uname': str(request.user),
|
||||||
|
'error': 'etherpad-lite session request returned:' +
|
||||||
|
'"' + str(e) + '"'
|
||||||
|
}
|
||||||
|
|
||||||
|
)
|
||||||
|
return response
|
||||||
|
|
||||||
|
# Set up the response
|
||||||
|
response = render(request,
|
||||||
|
'documents/pad.html',
|
||||||
|
{
|
||||||
|
'pad': padID,
|
||||||
|
'link': padLink,
|
||||||
|
'server': str(server),
|
||||||
|
'uname': str(request.user),
|
||||||
|
'error': False
|
||||||
|
}#, context=(request)
|
||||||
|
)
|
||||||
|
|
||||||
|
# Delete the existing session first
|
||||||
|
if ('padSessionID' in request.COOKIES):
|
||||||
|
epclient.deleteSession(request.COOKIES['sessionID'])
|
||||||
|
response.delete_cookie('sessionID', server.hostname)
|
||||||
|
response.delete_cookie('padSessionID')
|
||||||
|
|
||||||
|
# Set the new session cookie for both the server and the local site
|
||||||
|
response.set_cookie(
|
||||||
|
'sessionID',
|
||||||
|
value=result['sessionID'],
|
||||||
|
expires=expires,
|
||||||
|
domain=server.hostname,
|
||||||
|
httponly=False
|
||||||
|
)
|
||||||
|
response.set_cookie(
|
||||||
|
'padSessionID',
|
||||||
|
value=result['sessionID'],
|
||||||
|
expires=expires,
|
||||||
|
httponly=False
|
||||||
|
)
|
||||||
|
return response
|
||||||
@@ -15,6 +15,7 @@ import os
|
|||||||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
SESSION_COOKIE_DOMAIN =".2020.fet.at"
|
||||||
|
|
||||||
# Quick-start development settings - unsuitable for production
|
# Quick-start development settings - unsuitable for production
|
||||||
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
|
||||||
@@ -34,6 +35,7 @@ CKEDITOR_UPLOAD_PATH = 'upload'
|
|||||||
INSTALLED_APPS = [
|
INSTALLED_APPS = [
|
||||||
'posts.apps.PostsConfig',
|
'posts.apps.PostsConfig',
|
||||||
'members.apps.MembersConfig',
|
'members.apps.MembersConfig',
|
||||||
|
'documents.apps.DocumentsConfig',
|
||||||
'django.contrib.admin',
|
'django.contrib.admin',
|
||||||
'django.contrib.auth',
|
'django.contrib.auth',
|
||||||
'django.contrib.contenttypes',
|
'django.contrib.contenttypes',
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ router.register(r'members', MemberViewSet)
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('posts/', include('posts.urls')),
|
path('posts/', include('posts.urls')),
|
||||||
|
path('documents/', include('documents.urls')),
|
||||||
path('admin/doc/', include('django.contrib.admindocs.urls')),
|
path('admin/doc/', include('django.contrib.admindocs.urls')),
|
||||||
path('admin/', admin.site.urls),
|
path('admin/', admin.site.urls),
|
||||||
path('', views.index, name='home'),
|
path('', views.index, name='home'),
|
||||||
|
|||||||
7
fet2020/templates/admin/documents/app_index.html
Normal file
7
fet2020/templates/admin/documents/app_index.html
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{% extends "admin/app_index.html" %}
|
||||||
|
|
||||||
|
{% block sidebar %}
|
||||||
|
<h1>Hello</h1>
|
||||||
|
<ul><li>asdf</li></ul>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
7
fet2020/templates/admin/documents/change_list.html
Normal file
7
fet2020/templates/admin/documents/change_list.html
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{% extends "admin/change_list.html" %}
|
||||||
|
|
||||||
|
{% block object-tools-items %}
|
||||||
|
|
||||||
|
{{ block.super }}
|
||||||
|
<li><a href="#">sdf</a></li>
|
||||||
|
{% endblock %}
|
||||||
5
fet2020/templates/admin/documents/preview.html
Normal file
5
fet2020/templates/admin/documents/preview.html
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
{% extends "admin/base_site.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<h1> Preview </h1>
|
||||||
|
{% endblock %}
|
||||||
7
fet2020/templates/admin/index.html
Normal file
7
fet2020/templates/admin/index.html
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{% extends "admin/index.html" %}
|
||||||
|
{% block content%}
|
||||||
|
<div style="float:left; width:100%">
|
||||||
|
{{block.super}}
|
||||||
|
Hello
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
50
fet2020/templates/documents/base.html
Normal file
50
fet2020/templates/documents/base.html
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
|
||||||
|
<!DOCTYPE html>
|
||||||
|
{% load i18n %}
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
|
||||||
|
<meta charset="UTF-8" />
|
||||||
|
<title>{% block title %}{% endblock %}</title>
|
||||||
|
<link href="{{ STATIC_URL }}etherpad-lite/css/style.css" rel="stylesheet" type="text/css" />
|
||||||
|
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js" ></script>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div id="nav"><nav>
|
||||||
|
{% block nav %}
|
||||||
|
{% if user.is_authenticated %}
|
||||||
|
<a class="nav" href="/accounts/profile/">{% trans "profile" %}</a>
|
||||||
|
<a class="nav" href="/logout">{% trans "logout" %}</a>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
</nav></div>
|
||||||
|
<div id="wrapper">
|
||||||
|
{% block wrapper %}
|
||||||
|
<div id="main">
|
||||||
|
<div id="content">
|
||||||
|
{% if messages %}
|
||||||
|
<div id="messages">
|
||||||
|
{% block messages %}
|
||||||
|
{% for message in messages %}
|
||||||
|
<div class="{{ message.class }}">
|
||||||
|
<span class="mark">!</span>{{ message.text }}<span class="mark">!</span>
|
||||||
|
</div>
|
||||||
|
{% endfor %}
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% block content %}{% endblock %}
|
||||||
|
</div>
|
||||||
|
<div id="sidebar"><aside>
|
||||||
|
{% block sidebar %}{% endblock %}
|
||||||
|
</aside></div>
|
||||||
|
<div id="footer"><footer>
|
||||||
|
</footer></div>
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
|
||||||
34
fet2020/templates/documents/pad.html
Normal file
34
fet2020/templates/documents/pad.html
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
{% extends "documents/base.html" %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block title %}{{pad.name}}{% endblock %}
|
||||||
|
|
||||||
|
{% block wrapper %}
|
||||||
|
{% if error %}
|
||||||
|
<div id="main">
|
||||||
|
<div id="errors">
|
||||||
|
<h2>Errors:</h2>
|
||||||
|
<p>{{error}}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{% else %}
|
||||||
|
<iframe src="{{link}}?userName={{uname}}" style="height: 95%; width: 100%; min-height: 500px; display: block"></iframe>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
/**
|
||||||
|
* This little script is necessary for some browsers that don't respect the
|
||||||
|
* height css attribute on iframes.
|
||||||
|
*/
|
||||||
|
function resizeEtherpad() {
|
||||||
|
height = jQuery(window).height()*94/100;
|
||||||
|
jQuery('#wrapper iframe').height(height);
|
||||||
|
}
|
||||||
|
|
||||||
|
jQuery(document).ready( function() {
|
||||||
|
resizeEtherpad()
|
||||||
|
jQuery(window).resize(resizeEtherpad);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user