rename document -> etherpad
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
from django.contrib import admin
|
||||
from django.db.models import F
|
||||
|
||||
from .models import TopicGroup, Topic, Documentation, Document, FileUpload
|
||||
from .models import TopicGroup, Topic, Documentation, Etherpad, FileUpload
|
||||
from .forms import (
|
||||
TopicGroupAdminForm,
|
||||
TopicAdminForm,
|
||||
DocumentationAdminForm,
|
||||
DocumentAdminForm,
|
||||
EtherpadAdminForm,
|
||||
FileUploadAdminForm,
|
||||
)
|
||||
|
||||
@@ -22,15 +22,15 @@ class DocumentationInline(admin.TabularInline):
|
||||
class FileUploadInline(admin.TabularInline):
|
||||
model = FileUpload
|
||||
extra = 0
|
||||
verbose_name = "Dokument"
|
||||
verbose_name_plural = "Dokumentensammlung"
|
||||
verbose_name = "Datei"
|
||||
verbose_name_plural = "Dateien"
|
||||
|
||||
|
||||
class DocumentInline(admin.TabularInline):
|
||||
model = Document
|
||||
class EtherpadInline(admin.TabularInline):
|
||||
model = Etherpad
|
||||
extra = 0
|
||||
verbose_name = "Dokument"
|
||||
verbose_name_plural = "Dokumentensammlung"
|
||||
verbose_name = "Etherpad"
|
||||
verbose_name_plural = "Etherpads"
|
||||
|
||||
|
||||
class TopicInline(admin.TabularInline):
|
||||
@@ -75,7 +75,7 @@ class DocumentationAdmin(admin.ModelAdmin):
|
||||
form = DocumentationAdminForm
|
||||
model = Documentation
|
||||
inlines = (
|
||||
DocumentInline,
|
||||
EtherpadInline,
|
||||
FileUploadInline,
|
||||
)
|
||||
|
||||
@@ -89,9 +89,9 @@ class DocumentationAdmin(admin.ModelAdmin):
|
||||
super().save_model(request, obj, form, change)
|
||||
|
||||
|
||||
class DocumentAdmin(admin.ModelAdmin):
|
||||
form = DocumentAdminForm
|
||||
model = Document
|
||||
class EtherpadAdmin(admin.ModelAdmin):
|
||||
form = EtherpadAdminForm
|
||||
model = Etherpad
|
||||
|
||||
list_filter = [
|
||||
"documentation",
|
||||
@@ -128,5 +128,5 @@ class FileUploadAdmin(admin.ModelAdmin):
|
||||
admin.site.register(TopicGroup, TopicGroupAdmin)
|
||||
admin.site.register(Topic, TopicAdmin)
|
||||
admin.site.register(Documentation, DocumentationAdmin)
|
||||
admin.site.register(Document, DocumentAdmin)
|
||||
admin.site.register(Etherpad, EtherpadAdmin)
|
||||
admin.site.register(FileUpload, FileUploadAdmin)
|
||||
|
||||
@@ -2,7 +2,7 @@ from ckeditor_uploader.widgets import CKEditorUploadingWidget
|
||||
from django import forms
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from .models import TopicGroup, Topic, Documentation, Document, FileUpload
|
||||
from .models import TopicGroup, Topic, Documentation, Etherpad, FileUpload
|
||||
|
||||
|
||||
class DateInput(forms.DateInput):
|
||||
@@ -46,9 +46,9 @@ class DocumentationAdminForm(forms.ModelForm):
|
||||
widgets = {"description": CKEditorUploadingWidget(config_name="default")}
|
||||
|
||||
|
||||
class DocumentAdminForm(forms.ModelForm):
|
||||
class EtherpadAdminForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Document
|
||||
model = Etherpad
|
||||
fields = [
|
||||
"title",
|
||||
"documentation",
|
||||
@@ -65,9 +65,9 @@ class FileUploadAdminForm(forms.ModelForm):
|
||||
]
|
||||
|
||||
|
||||
class DocumentForm(forms.ModelForm):
|
||||
class EtherpadForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Document
|
||||
model = Etherpad
|
||||
|
||||
fields = [
|
||||
"title",
|
||||
|
||||
@@ -90,9 +90,12 @@ class Documentation(models.Model):
|
||||
return self.topic.title + " / " + self.title
|
||||
|
||||
def get_absolute_url(self):
|
||||
return reverse(
|
||||
"docu", kwargs={"topic_slug": self.topic.slug, "slug": self.slug}
|
||||
)
|
||||
kwargs = {
|
||||
"topic_slug": self.topic.slug,
|
||||
"slug": self.slug,
|
||||
}
|
||||
|
||||
return reverse("docu", kwargs=kwargs)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
if not self.slug:
|
||||
@@ -101,7 +104,7 @@ class Documentation(models.Model):
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
||||
class Document(models.Model):
|
||||
class Etherpad(models.Model):
|
||||
title = models.CharField(verbose_name="Titel", max_length=128)
|
||||
etherpad_key = models.CharField(max_length=50, blank=True)
|
||||
date = models.DateField(verbose_name="Datum", default=date.today)
|
||||
@@ -111,8 +114,8 @@ class Document(models.Model):
|
||||
objects = models.Manager()
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Dokument"
|
||||
verbose_name_plural = "Dokumente"
|
||||
verbose_name = "Etherpad"
|
||||
verbose_name_plural = "Etherpads"
|
||||
|
||||
constraints = [
|
||||
UniqueConstraint(
|
||||
@@ -120,9 +123,9 @@ class Document(models.Model):
|
||||
),
|
||||
]
|
||||
|
||||
def clean(self):
|
||||
pad_name = slugify(
|
||||
str(self.date)
|
||||
def __get_pad_name(self):
|
||||
return (
|
||||
slugify(self.date)
|
||||
+ "-"
|
||||
+ self.documentation.topic.slug
|
||||
+ "-"
|
||||
@@ -131,6 +134,9 @@ class Document(models.Model):
|
||||
+ slugify(self.title)
|
||||
)
|
||||
|
||||
def clean(self):
|
||||
pad_name = slugify(self.__get_pad_name())
|
||||
|
||||
if len(pad_name) > 50:
|
||||
raise ValidationError(
|
||||
_(
|
||||
@@ -140,15 +146,7 @@ class Document(models.Model):
|
||||
)
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
self.etherpad_key = createPadifNotExists(
|
||||
slugify(self.date)
|
||||
+ "-"
|
||||
+ self.documentation.topic.slug
|
||||
+ "-"
|
||||
+ self.documentation.slug
|
||||
+ "-"
|
||||
+ slugify(self.title)
|
||||
)
|
||||
self.etherpad_key = createPadifNotExists(self.__get_pad_name())
|
||||
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@@ -167,5 +165,9 @@ class FileUpload(models.Model):
|
||||
|
||||
objects = models.Manager()
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Datei"
|
||||
verbose_name_plural = "Dateien"
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
@@ -13,8 +13,8 @@ from authentications.decorators import authenticated_user
|
||||
from documents.api import get_pad_link
|
||||
from documents.etherpadlib import add_ep_cookie
|
||||
from tasks.models import Task
|
||||
from .forms import DocumentForm, FileUploadForm
|
||||
from .models import TopicGroup, Topic, Documentation, Document, FileUpload
|
||||
from .forms import EtherpadForm, FileUploadForm
|
||||
from .models import TopicGroup, Topic, Documentation, Etherpad, FileUpload
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -76,7 +76,7 @@ def show_docu(request, topic_slug=None, slug=None):
|
||||
|
||||
if request.method == "POST":
|
||||
if "btn_etherpad" in request.POST:
|
||||
form = DocumentForm(request.POST)
|
||||
form = EtherpadForm(request.POST)
|
||||
|
||||
if form.is_valid():
|
||||
form.save()
|
||||
@@ -101,17 +101,17 @@ def show_docu(request, topic_slug=None, slug=None):
|
||||
"documentation": active_docu,
|
||||
}
|
||||
|
||||
form_add_etherpad = DocumentForm(initial=initial)
|
||||
form_add_etherpad = EtherpadForm(initial=initial)
|
||||
form_add_file = FileUploadForm(initial=initial)
|
||||
|
||||
files = deque(FileUpload.objects.filter(documentation=active_docu))
|
||||
|
||||
docus = deque(Document.objects.filter(documentation=active_docu).order_by("-date"))
|
||||
documents = deque([])
|
||||
docus = deque(Etherpad.objects.filter(documentation=active_docu).order_by("-date"))
|
||||
etherpads = deque([])
|
||||
|
||||
# list of etherpad url-link of any documents
|
||||
# list of etherpad url-link of any etherpads
|
||||
for elem in docus:
|
||||
documents.append(
|
||||
etherpads.append(
|
||||
{
|
||||
"title": elem.title,
|
||||
"date": elem.date,
|
||||
@@ -124,7 +124,7 @@ def show_docu(request, topic_slug=None, slug=None):
|
||||
"form_add_file": form_add_file,
|
||||
"active_topic": active_topic,
|
||||
"active_docu": active_docu,
|
||||
"documents": documents,
|
||||
"documents": etherpads,
|
||||
"files": files,
|
||||
}
|
||||
|
||||
@@ -139,9 +139,9 @@ def show_docu(request, topic_slug=None, slug=None):
|
||||
|
||||
|
||||
class EtherpadCreateView(LoginRequiredMixin, CreateView):
|
||||
model = Document
|
||||
model = Etherpad
|
||||
template_name = "intern/etherpad_create.html"
|
||||
form_class = DocumentForm
|
||||
form_class = EtherpadForm
|
||||
|
||||
topic_slug = None
|
||||
slug = None
|
||||
|
||||
Reference in New Issue
Block a user