|
@@ -4,8 +4,9 @@ from django.utils.encoding import force_text
|
|
|
from django.utils.safestring import mark_safe
|
|
|
|
|
|
from .models import (
|
|
|
- Document, Cost, Good, CostUse, GoodUse, Service, ServiceUse)
|
|
|
+ Document, Cost, Good, AbstractUse, CostUse, GoodUse, Service, ServiceUse)
|
|
|
|
|
|
+import markdown
|
|
|
|
|
|
class GoodInline(admin.TabularInline):
|
|
|
model = Good
|
|
@@ -58,10 +59,19 @@ class DocumentAdmin(admin.ModelAdmin):
|
|
|
new, edit_url)))
|
|
|
copy.short_description = 'Copier'
|
|
|
|
|
|
-
|
|
|
class AbstractUseInline(admin.TabularInline):
|
|
|
""" An inline with some knowledge of the currently edited Document
|
|
|
"""
|
|
|
+ fields = ['share', 'help', 'view_help', 'resource']
|
|
|
+ readonly_fields = ['view_help']
|
|
|
+
|
|
|
+ class Media:
|
|
|
+ js = ("edit_help.js",)
|
|
|
+
|
|
|
+ def view_help(self, obj):
|
|
|
+ return mark_safe(markdown.markdown(getattr(obj, 'help', '')
|
|
|
+ + ''' <a class='edit_help' title='Editer le text'><img src="/static/admin/img/icon-changelink.svg" alt="Modifier"></a>'''))
|
|
|
+
|
|
|
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
|
|
if db_field.name == "resource" and getattr(request, 'document', None):
|
|
|
kwargs["queryset"] = db_field.related_model.objects.filter(
|
|
@@ -69,7 +79,6 @@ class AbstractUseInline(admin.TabularInline):
|
|
|
return super().formfield_for_foreignkey(
|
|
|
db_field, request, **kwargs)
|
|
|
|
|
|
-
|
|
|
class GoodUseInline(AbstractUseInline):
|
|
|
model = GoodUse
|
|
|
extra = 1
|