Browse Source

Zacatky dynamickeho korekturovatka.

remotes/origin/korektury-ajax
parent
commit
e000dd2353
  1. 2
      korektury/static/korektury/opraf.css
  2. 298
      korektury/static/korektury/opraf.js
  3. 127
      korektury/templates/korektury/opraf.html
  4. 6
      korektury/urls.py
  5. 195
      korektury/views.py

2
korektury/static/korektury/opraf.css

@ -2,6 +2,7 @@ body,
.adding{
background: #f3f3f3;
color: black;
overflow: auto;
}
.comitting
{
@ -23,6 +24,7 @@ img{background:white;}
/*border-bottom-left-radius: 10px; */
border-left: 2px solid yellow;
border-bottom: 2px solid yellow;
z-index: 1;
}
.pointer-done-hi,

298
korektury/static/korektury/opraf.js

@ -4,54 +4,58 @@ function place_comments_one_div(img_id, comments)
if( img == null ) {
return;
}
var par = img.parentNode;
var par = $(img.parentNode);
var w = img.clientWidth;
var h = img.clientHeight;
var w_skip = 10;
var h_skip = 5;
var pointer_min_h = 30;
var pointer_min_h = 10;
var bott_max = 0;
var comments_sorted = comments.sort(function (a,b) {
return a[2] - b[2];
return a.y - b.y;
//pokus o hezci kladeni poiteru, ale nic moc
if( a[3] < b[3] ) {
return (a[2] + pointer_min_h)- b[2];
if( a.x < b.x ) {
return (a.y + pointer_min_h)- b.y;
} else {
return (a[2] - pointer_min_h)- b[2];
return (a.y - pointer_min_h)- b.y;
}
});
//console.log("w:" + w);
for (c in comments_sorted) {
var id = comments_sorted[c][0];
var x = comments_sorted[c][1];
var y = comments_sorted[c][2];
for (var c of comments_sorted) {
var id = c.id;
var x = c.x;
var y = c.y;
var el = document.getElementById(id);
var elp = document.getElementById(id + "-pointer");
var elp;
var el;
[elp, el] = create_corr_div(c);
if( el == null || elp == null ) {
continue;
}
par.appendChild(elp);
par.appendChild(el);
par.append(elp);
par.append(el);
var delta_y = (y > bott_max) ? 0: bott_max - y + h_skip;
elp.style.left = x;
elp.style.top = y ;
elp.style.width = w - x + w_skip;
elp.style.height = pointer_min_h + delta_y;
elp.img_id = img_id;
el.img_id = img_id;
elp.css({
left: x,
top: y,
width : w - x + w_skip,
height : pointer_min_h + delta_y});
//elp.img_id = img_id;
//el.img_id = img_id;
el.style.position = 'absolute';
el.style.left = w + w_skip;
el.style.top = y + delta_y;
el.css({
position: 'absolute',
left: w + w_skip,
top: y + delta_y});
var bott = el.offsetTop + el.offsetHeight;
var bott = el.position().top + el.height() + 10;
bott_max = ( bott_max > bott ) ? bott_max : bott;
//console.log( "par.w:" + par.style.width);
@ -268,3 +272,249 @@ String.prototype.unescapeHTML = function () {
);
};
$(function() {
// This function gets cookie with a given name
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
var csrftoken = getCookie('csrftoken');
/*
The functions below will create a header with csrftoken
*/
function csrfSafeMethod(method) {
// these HTTP methods do not require CSRF protection
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
}
function sameOrigin(url) {
// test that a given url is a same-origin URL
// url could be relative or scheme relative or absolute
var host = document.location.host; // host + port
var protocol = document.location.protocol;
var sr_origin = '//' + host;
var origin = protocol + sr_origin;
// Allow absolute or scheme relative URLs to same origin
return (url == origin || url.slice(0, origin.length + 1) == origin + '/') ||
(url == sr_origin || url.slice(0, sr_origin.length + 1) == sr_origin + '/') ||
// or any other URL that isn't scheme relative or absolute i.e relative.
!(/^(\/\/|http:|https:).*/.test(url));
}
$.ajaxSetup({
beforeSend: function(xhr, settings) {
if (!csrfSafeMethod(settings.type) && sameOrigin(settings.url)) {
// Send the token to same-origin, relative URLs only.
// Send the token only if the method warrants CSRF protection
// Using the CSRFToken value acquired earlier
xhr.setRequestHeader("X-CSRFToken", csrftoken);
}
}
});
});
// AJAX for posting
function create_post(inputs) {
console.log("create post is working!"); // sanity check
console.log(inputs);
var dict = {};
$.each(inputs,function(i,field){dict[field.name]=field.value})
$.ajax({
url : "request/", // the endpoint
type : "POST", // http method
data : dict, // data sent with the post request
// handle a successful response
success : function(json) {
alert("Success");
// $('#post-text').val(''); // remove the value from the input
console.log(json); // log the returned json to the console
console.log("success"); // another sanity check
},
// handle a non-successful response
error : function(xhr,errmsg,err) {
alert("Fail");
// $('#results').html("<div class='alert-box alert radius' data-alert>Oops! We have encountered an error: "+errmsg+
// " <a href='#' class='close'>&times;</a></div>"); // add the error to the dom
console.log(xhr.status + ": " + xhr.responseText); // provide a bit more info about the error to the console
}
});
};
function create_corr_div(corr){
/*
<div onclick='img_click(this,event)'
id='op{{o.id}}-pointer'
class='pointer{%if o.status = 'opraveno' %}-done{% elif o.status = 'neni_chyba' %}-wontfix{% endif %}'>
</div>
*/
var corr_status = '';
switch (corr.status){
case 'opraveno':
corr_status='-done';
break;
case 'neni-chyba':
corr_status='-wontfix';
}
var pointer;
pointer = $("<div>",{
id:'op'+corr.id+'-pointer',
class: 'pointer'+corr_status,
onclick: 'img_click(this,event)'
});
var all_buttons;
all_buttons = $('<div>');
var header;
header = $('<div>',{class:'corr-header'}).append(
$('<div>',{class:'author',id:'op'+corr.id+'-autor'}).append(corr.autor),
all_buttons);
/*
<div name='op{{o.id}}' id='op{{o.id}}'
class='box{%if o.status = 'opraveno' %}-done{% elif o.status = 'neni_chyba' %}-wontfix{% endif %}'
onmouseover='box_onmouseover(this,{% if o.status = 'opraveno' %}"done"{% elif o.status = 'neni_chyba' %}"wontfix"{%else%}""{% endif %})'
onmouseout='box_onmouseout(this,{% if o.status = 'opraveno' %}"done"{% elif o.status = 'neni_chyba' %}"wontfix"{%else%}""{% endif %})'>
<div class='corr-header'>
<div class='author' id='op{{o.id}}-autor'>{{o.autor}}</div>
<div class='float-right'>
<!-- Existujici korektura !-->
<form class="corr-form" action='' method='POST'>
{% csrf_token %}
<input type='hidden' name="au" value="{{o.autor}}"/>
<input type='hidden' name='pdf' value='{{pdf.id}}'>
<input type='hidden' name='id' value='{{o.id}}'>
<input type='hidden' name='scroll'>
{% if o.komentare %}
<button name='action' value='del' type='button'
title="Opravu nelze smazat &ndash; už ji někdo okomentoval">
<img src="{% static "korektury/imgs/delete-gr.png"%}"/>
</button>
{% else %}
<button type='submit' name='action' value='del' title='Smaž opravu'>
<img src="{% static "korektury/imgs/delete.png"%}"/>
</button>
{% endif %}
{% if o.status = 'opraveno' or o.status = 'neni_chyba' %}
<button type='submit' name='action' value='undone' title='Označ jako neopravené'>
<img src="{% static "korektury/imgs/undo.png"%}"/>
</button>
{% else %}
<button type='submit' name='action' value='done' title='Označ jako opravené'>
<img src="{% static "korektury/imgs/check.png"%}"/>
</button>
<button type='submit' name='action' value='wontfix' title='Označ jako irelevantní '>
<img src="{% static "korektury/imgs/cross.png" %}"/>
</button>
{% endif %}
</form>
<!-- /Existujici korektura !-->
{% if o.komentare %}
<button type='button' title="Korekturu nelze upravit &ndash; už ji někdo okomentoval">
<img src="{% static "korektury/imgs/edit-gr.png" %}"/>
</button>
{% else %}
<button type='button' onclick='box_edit(this,"update");' title='Oprav opravu'>
<img src="{% static "korektury/imgs/edit.png" %}"/>
</button>
{% endif %}
<button type='button' onclick='box_edit(this, "comment");' title='Komentovat'>
<img src="{% static "korektury/imgs/comment.png" %}"/>
</button>
<button type='button' onclick='toggle_visibility(this);' title='Skrýt/Zobrazit'>
<img src="{% static "korektury/imgs/hide.png" %}"/>
</button>
</div>
</div> */
var body;
body = $('<div>',{class:'corr-body', id:'op'+corr.id+'-body'}).append(
$('<div>',{id:'op'+corr.id+'-text'}).append(corr.text)
);
/*
+<div class='corr-body' id='op{{o.id}}-body'>
+<div id='op{{o.id}}-text'>{{o.text}}</div>
{% for k in o.komentare %}
<hr>
<div class='comment' id='k{{k.id}}'>
<div class='corr-header'>
<div class='author'>{{k.autor}}</div>
<div class="float-right">
<!-- Komentar !-->
<form class="corr-form" action='' method='POST'>
{% csrf_token %}
<input type='hidden' name='pdf' value='{{pdf.id}}'>
<input type='hidden' name='id' value='{{k.id}}'>
<input type='hidden' name='scroll'>
<button type='submit' name='action' value='del-comment' title='Smaž komentář'
onclick='return confirm("Opravdu smazat komentář?")'>
<img src="{% static "korektury/imgs/delete.png" %}"/>
</button>
</form>
<!-- /Komentar !-->
<button type='button' onclick='update_comment(this);' title='Uprav komentář'>
<img src="{% static "korektury/imgs/edit.png"%}"/>
</button>
</div>
</div>
<div id='kt{{k.id}}'>{{k.text}}</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
*/
var corr_div;
corr_div = $('<div>',{
name: corr.id,
id: corr.id,
'class': 'box'+corr_status,
onmouseover: 'box_onmouseover(this,'+(corr_status==''?'\'\'':corr_status)+')',
onmouseout: 'box_onmouseout(this,'+(corr_status==''?'\'\'':corr_status)+')'
}).append(header,body)
return [pointer,corr_div];
}
function show_corrections(corrs){
var num_pages;
var pages;
pages = (corrs.map(function(cur,idx,arr){
return cur.strana;
}));
num_pages = Math.max.apply(null,pages);
for(var i=0;i<num_pages;i++){
page_corrs = corrs.filter(function(element,idx,arr){return element.strana==i?1:0});
place_comments_one_div('img-'+i,page_corrs);
}
}

127
korektury/templates/korektury/opraf.html

@ -4,10 +4,14 @@
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" media="screen, projection" href="{% static "korektury/opraf.css"%}" />
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<script src="{% static "korektury/opraf.js"%}"></script>
<title>Korektury {{pdf.nazev}}</title>
</head>
<body {% if pdf.status = 'zanaseni'%} class="comitting" {% elif pdf.status = 'zastarale' %} class="deprecated" {% endif %} onload='place_comments()'>
<body {% if pdf.status = 'zanaseni'%} class="comitting" {% elif pdf.status = 'zastarale' %} class="deprecated" {% endif %}'>
<h1>Korektury {{pdf.nazev}}</h1>
{% if pdf.status = 'zanaseni' %} <h2> Probíhá zanášení korektur, zvažte, zda chcete přidávat nové </h2> {% endif %}
{% if pdf.status = 'zastarale' %} <h2> Toto PDF je již zastaralé, nepřidávejte nové korektury </h2> {% endif %}
@ -24,7 +28,7 @@
<div id="commform-div">
<!-- Pridat korekturu / komentar !-->
<form action='' onsubmit='save_scroll(this)' id="commform" method="POST">
<form class="corr-form" action='' id="commform" method="POST">
{% csrf_token %}
<input size="24" name="au" value="{{user.first_name}} {{user.last_name}}" readonly/>
<input type=submit value="Oprav!"/>
@ -88,115 +92,30 @@
{% endfor %}</p>
<hr>
{% for o in opravy %}
<div onclick='img_click(this,event)'
id='op{{o.id}}-pointer'
class='pointer{%if o.status = 'opraveno' %}-done{% elif o.status = 'neni_chyba' %}-wontfix{% endif %}'>
</div>
<div name='op{{o.id}}' id='op{{o.id}}'
class='box{%if o.status = 'opraveno' %}-done{% elif o.status = 'neni_chyba' %}-wontfix{% endif %}'
onmouseover='box_onmouseover(this,{% if o.status = 'opraveno' %}"done"{% elif o.status = 'neni_chyba' %}"wontfix"{%else%}""{% endif %})'
onmouseout='box_onmouseout(this,{% if o.status = 'opraveno' %}"done"{% elif o.status = 'neni_chyba' %}"wontfix"{%else%}""{% endif %})'>
<div class='corr-header'>
<div class='author' id='op{{o.id}}-autor'>{{o.autor}}</div>
<div class='float-right'>
<!-- Existujici korektura !-->
<form action='' onsubmit='save_scroll(this)' method='POST'>
{% csrf_token %}
<input type='hidden' name="au" value="{{o.autor}}"/>
<input type='hidden' name='pdf' value='{{pdf.id}}'>
<input type='hidden' name='id' value='{{o.id}}'>
<input type='hidden' name='scroll'>
{% if o.komentare %}
<button name='action' value='del' type='button'
title="Opravu nelze smazat &ndash; už ji někdo okomentoval">
<img src="{% static "korektury/imgs/delete-gr.png"%}"/>
</button>
{% else %}
<button type='submit' name='action' value='del' title='Smaž opravu'>
<img src="{% static "korektury/imgs/delete.png"%}"/>
</button>
{% endif %}
{% if o.status = 'opraveno' or o.status = 'neni_chyba' %}
<button type='submit' name='action' value='undone' title='Označ jako neopravené'>
<img src="{% static "korektury/imgs/undo.png"%}"/>
</button>
{% else %}
<button type='submit' name='action' value='done' title='Označ jako opravené'>
<img src="{% static "korektury/imgs/check.png"%}"/>
</button>
<button type='submit' name='action' value='wontfix' title='Označ jako irelevantní '>
<img src="{% static "korektury/imgs/cross.png" %}"/>
</button>
{% endif %}
</form>
<!-- /Existujici korektura !-->
{% if o.komentare %}
<button type='button' title="Korekturu nelze upravit &ndash; už ji někdo okomentoval">
<img src="{% static "korektury/imgs/edit-gr.png" %}"/>
</button>
{% else %}
<button type='button' onclick='box_edit(this,"update");' title='Oprav opravu'>
<img src="{% static "korektury/imgs/edit.png" %}"/>
</button>
{% endif %}
<button type='button' onclick='box_edit(this, "comment");' title='Komentovat'>
<img src="{% static "korektury/imgs/comment.png" %}"/>
</button>
<button type='button' onclick='toggle_visibility(this);' title='Skrýt/Zobrazit'>
<img src="{% static "korektury/imgs/hide.png" %}"/>
</button>
</div>
</div>
<div class='corr-body' id='op{{o.id}}-body'>
<div id='op{{o.id}}-text'>{{o.text}}</div>
{% for k in o.komentare %}
<hr>
<div class='comment' id='k{{k.id}}'>
<div class='corr-header'>
<div class='author'>{{k.autor}}</div>
<div class="float-right">
<!-- Komentar !-->
<form action='' onsubmit='save_scroll(this)' method='POST'>
{% csrf_token %}
<input type='hidden' name='pdf' value='{{pdf.id}}'>
<input type='hidden' name='id' value='{{k.id}}'>
<input type='hidden' name='scroll'>
<button type='submit' name='action' value='del-comment' title='Smaž komentář'
onclick='return confirm("Opravdu smazat komentář?")'>
<img src="{% static "korektury/imgs/delete.png" %}"/>
</button>
</form>
<!-- /Komentar !-->
<button type='button' onclick='update_comment(this);' title='Uprav komentář'>
<img src="{% static "korektury/imgs/edit.png"%}"/>
</button>
</div>
</div>
<div id='kt{{k.id}}'>{{k.text}}</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
<script>
var comments = [
{% for s in opravy_strany %}
["img-{{s.strana}}", [{% for o in s.op_id %}["op{{o.id}}",{{o.x}},{{o.y}}],{% endfor %}[]]],
{% endfor %}
[]]
var cor_data;
$(document).ready(function get_corrs(){
$.getJSON("korektury/",function(data){
show_corrections(data.opravy);
cor_data = data});
});
/*
function place_comments() {
for (var i=0; i < comments.length-1; i++) {
place_comments_one_div(comments[i][0], comments[i][1])
}
}
}*/
$('.corr-form').on('submit', function(event) {
//alert("Submitting");
event.preventDefault();
var inputs = $(this).serializeArray();
save_scroll(this);
console.log("Submitting");
create_post(inputs);
});
{% if scroll %}
window.scrollTo(0,{{scroll}});
{% endif %}

6
korektury/urls.py

@ -7,6 +7,10 @@ staff_member_required = user_passes_test(lambda u: u.is_staff)
urlpatterns = [
url(r'^korektury/$', staff_member_required(views.KorekturyListView.as_view()), name='korektury-list'),
url(r'^korektury/(?P<pdf>\d+)/$', staff_member_required(views.KorekturyView.as_view()), name='korektury'),
url(r'^korektury/(?P<pdf>\d+)/$', views.KorekturyBaseView.as_view(), name='korektury'),
url(r'^korektury/(?P<pdf>\d+)/korektury/$', views.KorekturyView.as_view(), name='korektury'),
url(r'^korektury/(?P<pdf>\d+)/request/$', views.KorekturyRequestView.as_view(), name='korektury-request'),
# FIXME url(r'^korektury/(?P<pdf>\d+)/$', staff_member_required(views.KorekturyView.as_view()), name='korektury'),
# FIXME url(r'^korektury/(?P<pdf>\d+)/request/$', staff_member_required(views.KorekturyRequestView.as_view()), name='korektury-request'),
url(r'^korektury/help/', staff_member_required(views.KorekturyHelpView.as_view()), name='korektury-help'),
]

195
korektury/views.py

@ -3,15 +3,15 @@ from django.shortcuts import get_object_or_404, render
from django.views import generic
from django.utils.translation import ugettext as _
from django.conf import settings
from django.http import HttpResponseForbidden
from django.http import HttpResponseForbidden,HttpResponse
from django.core.mail import send_mail
from django.core.context_processors import csrf
from .models import Oprava,Komentar,KorekturovanePDF, Organizator
from .forms import OpravaForm
import subprocess
import shutil
import os
import json
import unicodedata
class KorekturyHelpView(generic.TemplateView):
@ -22,7 +22,7 @@ class KorekturyListView(generic.ListView):
template_name = 'korektury/seznam.html'
### Korektury
class KorekturyView(generic.TemplateView):
class KorekturyBaseView(generic.TemplateView):
model = Oprava
template_name = 'korektury/opraf.html'
form_class = OpravaForm
@ -164,7 +164,192 @@ class KorekturyView(generic.TemplateView):
send_mail(subject, text, from_email, list(emails))
def get_context_data(self, **kwargs):
context = super(KorekturyView,self).get_context_data(**kwargs)
context = super(KorekturyBaseView,self).get_context_data(**kwargs)
pdf = get_object_or_404(KorekturovanePDF, id=self.kwargs['pdf'])
context['pdf'] = pdf
context['img_name'] = os.path.split(pdf.pdf.path)[1].split('.')[0]
context['img_path'] = settings.KOREKTURY_IMG_DIR
context['img_indexes'] = range(pdf.stran)
context['form_oprava'] = OpravaForm()
opravy = Oprava.objects.filter(pdf=self.kwargs['pdf'])
zasluhy = {}
for o in opravy:
if o.autor in zasluhy:
zasluhy[o.autor]+=1
else:
zasluhy[o.autor]=1
o.komentare = o.komentar_set.all()
for k in o.komentare:
if k.autor in zasluhy:
zasluhy[k.autor]+=1
else:
zasluhy[k.autor]=1
zasluhy = [{'autor':jmeno, 'pocet':pocet} for (jmeno,pocet) in zasluhy.items()]
zasluhy.sort(key=lambda z:z['pocet'],reverse=True)
strany = set(o.strana for o in opravy)
opravy_na_stranu = [{'strana': s, 'op_id': opravy.filter(strana=s)} for s in strany]
context['opravy_strany'] = opravy_na_stranu
context['opravy'] = opravy
context['zasluhy'] = zasluhy
return context
def form_valid(self,form):
return super(KorekturyView,self).form_valid(form)
### Korektury
class KorekturyView(generic.TemplateView):
model = Oprava
template_name = 'korektury/opraf.html'
form_class = OpravaForm
def get(self,request,*args,**kwargs):
pdf = get_object_or_404(KorekturovanePDF, id=self.kwargs['pdf'])
context = {}
context['pdf'] = pdf.id
context['img_name'] = os.path.split(pdf.pdf.path)[1].split('.')[0]
context['img_path'] = settings.KOREKTURY_IMG_DIR
context['img_indexes'] = range(pdf.stran)
opravy = Oprava.objects.filter(pdf=self.kwargs['pdf'])
strany = set(o.strana for o in opravy)
opravy_na_stranu = [{'strana': s, 'op_id': map(lambda o:o.id,opravy.filter(strana=s))} for s in strany]
context['opravy_strany'] = opravy_na_stranu
opravy = list(opravy.values())
for o in opravy:
o["autor"] = str(Organizator.objects.filter(id=(o[u"autor_id"]))[0])
context['opravy'] = opravy
return HttpResponse(json.dumps(context),content_type="application/json")
class KorekturyRequestView(generic.TemplateView):
model = Oprava
template_name = 'korektury/opraf.html'
form_class = OpravaForm
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
q = request.POST
scroll = q.get('scroll')
# prirazeni autora podle prihlaseni
autor_user = request.user
# pokud existuje ucet (user), ale neni to organizator = 403
autor = Organizator.objects.filter(user=autor_user).first()
if not autor:
return HttpResponseForbidden()
if not scroll:
scroll = 0
action = q.get('action')
if (action == u''): # Přidej
x = int(q.get('x'))
y = int(q.get('y'))
text = q.get('txt')
strana = int(q.get('img-id')[4:])
pdf = KorekturovanePDF.objects.get(id=q.get('pdf'))
op = Oprava(x=x,y=y, autor=autor, text=text, strana=strana,pdf = pdf)
op.save()
self.send_email_notification_komentar(op, autor, text)
elif (action == u'del'):
id = int(q.get('id'))
op = Oprava.objects.get(id=id)
op.delete()
elif (action == u'update'):
id = int(q.get('id'))
op = Oprava.objects.get(id=id)
text = q.get('txt')
op.autor = autor
op.text = text
op.save()
elif (action == u'undone'):
id = int(q.get('id'))
op = Oprava.objects.get(id=id)
op.status = op.STATUS_K_OPRAVE
op.save()
elif (action == u'done'):
id = int(q.get('id'))
op = Oprava.objects.get(id=id)
op.status = op.STATUS_OPRAVENO
op.save()
elif (action == u'wontfix'):
id = int(q.get('id'))
op = Oprava.objects.get(id=id)
op.status = op.STATUS_NENI_CHYBA
op.save()
elif (action == u'comment'):
id = int(q.get('id'))
op = Oprava.objects.get(id=id)
text = q.get('txt')
kom = Komentar(oprava=op,autor=autor,text=text)
kom.save()
self.send_email_notification_komentar(op, autor, text)
elif (action == u'update-comment'):
id = int(q.get('id'))
kom = Komentar.objects.get(id=id)
text = q.get('txt')
kom.text = text
kom.autor = autor
kom.save()
elif (action == u'del-comment'):
id = int(q.get('id'))
kom = Komentar.objects.get(id=id)
kom.delete()
context = self.get_context_data()
context['scroll'] = scroll
context['autor'] = autor
return render(request, 'korektury/opraf.html',context)
def send_email_notification_komentar(self, oprava, autor, text):
''' Rozesle e-mail pri pridani komentare,
ktery obsahuje text komentare.
'''
# parametry e-mailu
odkaz = "https://mam.mff.cuni.cz/korektury/{}/".format(oprava.pdf.pk)
from_email = 'korekturovatko@mam.mff.cuni.cz'
subject = u'Nová korektura od {} v {}'.format(autor,
oprava.pdf.nazev)
text = u"Text komentáře:\n\n{}\n\n=== Konec textu komentáře ===\n\
\nodkaz do korekturovátka: {}\n\
\nVaše korekturovátko\n".format(text, odkaz)
# Prijemci e-mailu
emails = set()
# e-mail autora korektury
email = oprava.autor.user.email
if email:
emails.add(email)
# nalezeni e-mailu na autory komentaru
for komentar in oprava.komentar_set.all():
email_komentujiciho = komentar.autor.user.email
if email_komentujiciho:
emails.add(email_komentujiciho)
# zodpovedny org
if oprava.pdf.org:
email_zobpovedny = oprava.pdf.org.user.email
if email_zobpovedny:
emails.add(email_zobpovedny)
# odstran e-mail autora opravy
email = autor.user.email
if email:
emails.discard(email)
if not settings.SEND_EMAIL_NOTIFICATIONS:
print "Poslal bych upozornění na tyto adresy: ", " ".join(emails)
return
send_mail(subject, text, from_email, list(emails))
def get_context_data(self, **kwargs):
context = super(KorekturyRequestView,self).get_context_data(**kwargs)
pdf = get_object_or_404(KorekturovanePDF, id=self.kwargs['pdf'])
context['pdf'] = pdf
context['img_name'] = os.path.split(pdf.pdf.path)[1].split('.')[0]

Loading…
Cancel
Save