lino 24.11.1__py3-none-any.whl → 25.1.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. lino/__init__.py +1 -1
  2. lino/core/actors.py +33 -12
  3. lino/core/dbtables.py +0 -4
  4. lino/core/fields.py +26 -18
  5. lino/core/kernel.py +4 -6
  6. lino/core/model.py +5 -16
  7. lino/core/renderer.py +1 -7
  8. lino/core/requests.py +70 -47
  9. lino/core/site.py +1 -1
  10. lino/core/tables.py +0 -16
  11. lino/help_texts.py +4 -4
  12. lino/locale/bn/LC_MESSAGES/django.po +58 -45
  13. lino/locale/de/LC_MESSAGES/django.mo +0 -0
  14. lino/locale/de/LC_MESSAGES/django.po +79 -108
  15. lino/locale/django.pot +55 -44
  16. lino/locale/es/LC_MESSAGES/django.po +56 -44
  17. lino/locale/et/LC_MESSAGES/django.po +58 -45
  18. lino/locale/fr/LC_MESSAGES/django.mo +0 -0
  19. lino/locale/fr/LC_MESSAGES/django.po +60 -48
  20. lino/locale/nl/LC_MESSAGES/django.po +59 -45
  21. lino/locale/pt_BR/LC_MESSAGES/django.po +55 -44
  22. lino/locale/zh_Hant/LC_MESSAGES/django.po +55 -44
  23. lino/mixins/dupable.py +8 -7
  24. lino/mixins/periods.py +4 -4
  25. lino/modlib/checkdata/__init__.py +1 -1
  26. lino/modlib/comments/mixins.py +45 -44
  27. lino/modlib/comments/models.py +2 -2
  28. lino/modlib/comments/ui.py +9 -3
  29. lino/modlib/dupable/models.py +10 -14
  30. lino/modlib/gfks/mixins.py +8 -1
  31. lino/modlib/jinja/choicelists.py +3 -3
  32. lino/modlib/jinja/renderer.py +2 -0
  33. lino/modlib/languages/fixtures/all_languages.py +4 -6
  34. lino/modlib/memo/mixins.py +7 -7
  35. lino/modlib/memo/models.py +41 -12
  36. lino/modlib/memo/parser.py +7 -3
  37. lino/modlib/notify/mixins.py +8 -8
  38. lino/modlib/periods/choicelists.py +46 -0
  39. lino/modlib/periods/mixins.py +26 -0
  40. lino/modlib/periods/models.py +17 -45
  41. lino/modlib/publisher/choicelists.py +1 -4
  42. lino/modlib/system/__init__.py +0 -3
  43. lino/modlib/system/choicelists.py +0 -13
  44. lino/modlib/system/mixins.py +1 -0
  45. lino/modlib/system/models.py +0 -18
  46. lino/modlib/uploads/mixins.py +37 -37
  47. lino/modlib/uploads/models.py +68 -18
  48. lino/modlib/uploads/utils.py +6 -0
  49. lino/modlib/users/mixins.py +9 -6
  50. lino/modlib/users/models.py +0 -2
  51. lino/modlib/users/ui.py +1 -1
  52. lino/modlib/weasyprint/choicelists.py +17 -7
  53. lino/utils/choosers.py +21 -8
  54. lino/utils/instantiator.py +9 -0
  55. lino/utils/soup.py +5 -5
  56. {lino-24.11.1.dist-info → lino-25.1.1.dist-info}/METADATA +4 -2
  57. {lino-24.11.1.dist-info → lino-25.1.1.dist-info}/RECORD +60 -59
  58. {lino-24.11.1.dist-info → lino-25.1.1.dist-info}/WHEEL +1 -1
  59. {lino-24.11.1.dist-info → lino-25.1.1.dist-info}/licenses/AUTHORS.rst +0 -0
  60. {lino-24.11.1.dist-info → lino-25.1.1.dist-info}/licenses/COPYING +0 -0
@@ -171,24 +171,24 @@ class BasePreviewable(dd.Model):
171
171
  )
172
172
  short = truncate_comment(full, self.get_preview_length())
173
173
  if not full.startswith("<"):
174
- if markdown is not None:
174
+ if dd.get_plugin_setting("memo", "use_markup"):
175
175
  full = markdown.markdown(full, **MARKDOWNCFG)
176
176
  return (short, full)
177
177
 
178
178
  def get_saved_mentions(self):
179
179
  Mention = rt.models.memo.Mention
180
180
  flt = gfk2lookup(Mention.owner, self)
181
- return Mention.objects.filter(**flt).order_by("source_type", "source_id")
181
+ return Mention.objects.filter(**flt).order_by("target_type", "target_id")
182
182
 
183
183
  def synchronize_mentions(self, mentions):
184
184
  Mention = rt.models.memo.Mention
185
185
  for obj in self.get_saved_mentions():
186
- if obj.source in mentions:
187
- mentions.remove(obj.source)
186
+ if obj.target in mentions:
187
+ mentions.remove(obj.target)
188
188
  else:
189
189
  obj.delete()
190
- for source in mentions:
191
- obj = Mention(owner=self, source=source)
190
+ for target in mentions:
191
+ obj = Mention(owner=self, target=target)
192
192
  # source_id=source.pk,
193
193
  # source_type=ContentType.objects.get_for_model(source.__class__))
194
194
  obj.full_clean()
@@ -274,7 +274,7 @@ class PreviewableChecker(Checker):
274
274
  ):
275
275
  yield (True, _("Preview differs from source."))
276
276
  is_broken = True
277
- found_mentions = set([obj.source for obj in obj.get_saved_mentions()])
277
+ found_mentions = set([obj.target for obj in obj.get_saved_mentions()])
278
278
  if expected_mentions != found_mentions:
279
279
  yield (True, _("Mentions differ from expected mentions."))
280
280
  is_broken = True
@@ -9,6 +9,7 @@ from django.utils.text import format_lazy
9
9
 
10
10
  # from rstgen.sphinxconf.sigal_image import line2html
11
11
  from lino.api import dd, rt, _
12
+ from lino.core import constants
12
13
  from lino.core.roles import SiteStaff
13
14
  from lino.core.gfks import gfk2lookup
14
15
  from lino.modlib.gfks.mixins import Controllable
@@ -17,7 +18,7 @@ from .parser import split_name_rest
17
18
  # from .mixins import *
18
19
 
19
20
  # Translators: will also be concatenated with '(type)' '(object)'
20
- source_label = _("Source")
21
+ target_label = _("Target")
21
22
 
22
23
 
23
24
  class Mention(Controllable):
@@ -27,36 +28,64 @@ class Mention(Controllable):
27
28
  verbose_name = _("Mention")
28
29
  verbose_name_plural = _("Mentions")
29
30
 
30
- source_type = dd.ForeignKey(
31
+ target_type = dd.ForeignKey(
31
32
  ContentType,
32
33
  editable=True,
33
34
  blank=True,
34
35
  null=True,
35
- related_name="%(app_label)s_%(class)s_source_set",
36
- verbose_name=format_lazy("{} {}", source_label, _("(type)")),
36
+ related_name="%(app_label)s_%(class)s_target_set",
37
+ verbose_name=format_lazy("{} {}", target_label, _("(type)")),
37
38
  )
38
39
 
39
- source_id = GenericForeignKeyIdField(
40
- source_type,
40
+ target_id = GenericForeignKeyIdField(
41
+ target_type,
41
42
  editable=True,
42
43
  blank=True,
43
44
  null=True,
44
- verbose_name=format_lazy("{} {}", source_label, _("(object)")),
45
+ verbose_name=format_lazy("{} {}", target_label, _("(object)")),
45
46
  )
46
47
 
47
- source = GenericForeignKey("source_type", "source_id", verbose_name=source_label)
48
+ target = GenericForeignKey("target_type", "target_id", verbose_name=target_label)
48
49
 
50
+ @classmethod
51
+ def get_simple_parameters(cls):
52
+ for p in super().get_simple_parameters():
53
+ yield p
54
+ yield "target_type"
55
+ yield "target_id"
56
+
57
+ def as_summary_item(self, ar, text=None, **kwargs):
58
+ # raise Exception("20240613")
59
+ if ar is None:
60
+ obj = super()
61
+ elif ar.is_obvious_field('target'):
62
+ obj = self.owner
63
+ elif ar.is_obvious_field('owner'):
64
+ obj = self.target
65
+ else:
66
+ obj = super()
67
+ return obj.as_summary_item(ar, text, **kwargs)
68
+
69
+ dd.update_field(Mention, 'owner', verbose_name=_("Referrer"))
49
70
 
50
71
  class Mentions(dd.Table):
51
72
  required_roles = dd.login_required(SiteStaff)
52
73
  editable = False
53
74
  model = "memo.Mention"
54
- column_names = "source owner *"
75
+ column_names = "owner target *"
55
76
  # detail_layout = """
56
77
  # id comment owner created
57
78
  # """
58
79
 
80
+ # Not used because when you are on the owner, you can see the mentions in the memo text
81
+ # class MentionsByOwner(Mentions):
82
+ # label = _("Mentions")
83
+ # master_key = "owner"
84
+ # column_names = "target *"
85
+ # default_display_modes = {None: constants.DISPLAY_MODE_SUMMARY}
59
86
 
60
- class MentionsByOwner(Mentions):
61
- master_key = "owner"
62
- column_names = "source *"
87
+ class MentionsByTarget(Mentions):
88
+ label = _("Mentioned by")
89
+ master_key = "target"
90
+ column_names = "owner *"
91
+ default_display_modes = {None: constants.DISPLAY_MODE_SUMMARY}
@@ -159,7 +159,7 @@ class Parser:
159
159
  )
160
160
  self.commands[cmdname] = func
161
161
 
162
- def register_django_model(self, name, model, cmd=None):
162
+ def register_django_model(self, name, model, cmd=None, rnd=None):
163
163
  """
164
164
  Register the given string `name` as command for referring to
165
165
  database rows of the given Django database model `model`.
@@ -172,6 +172,8 @@ class Parser:
172
172
  # if rnd is None:
173
173
  # def rnd(obj):
174
174
  # return "[{} {}] ({})".format(name, obj.id, title(obj))
175
+ if rnd is None:
176
+ rnd = model.memo2html
175
177
  if cmd is None:
176
178
 
177
179
  def cmd(ar, s, cmdname, mentions, context):
@@ -200,7 +202,8 @@ class Parser:
200
202
  # caption = obj.get_memo_title()
201
203
  # txt = "#{0}".format(obj.id)
202
204
  # kw.update(title=title(obj))
203
- return obj.memo2html(ar, text)
205
+ # return obj.memo2html(ar, text)
206
+ return rnd(obj, ar, text)
204
207
  # e = ar.obj2html(obj, txt, **kw)
205
208
  # # return str(ar)
206
209
  # return etree.tostring(e)
@@ -210,7 +213,8 @@ class Parser:
210
213
  # pass
211
214
 
212
215
  cmd._for_model = model
213
- cmd.__doc__ = """
216
+ if cmd.__doc__ is None:
217
+ cmd.__doc__ = rnd.__doc__ or """
214
218
  Insert a reference to the specified {}.
215
219
 
216
220
  The first argument is mandatory and specifies the primary key.
@@ -1,7 +1,7 @@
1
- # Copyright 2016-2022 Rumma & Ko Ltd
1
+ # Copyright 2016-2024 Rumma & Ko Ltd
2
2
  # License: GNU Affero General Public License v3 (see file COPYING for details)
3
3
 
4
- from lino.utils.html import E, tostring
4
+ from lino.utils.html import E, tostring, format_html, mark_safe
5
5
  from lino.api import dd, rt, _
6
6
 
7
7
  # PUBLIC_GROUP = "all_users_channel"
@@ -27,21 +27,21 @@ class ChangeNotifier(dd.Model):
27
27
  def get_change_body(self, ar, cw):
28
28
  ctx = dict(user=ar.user, what=ar.obj2htmls(self))
29
29
  if cw is None:
30
- html = _("{user} created {what}").format(**ctx)
30
+ html = format_html(_("{user} created {what}"), **ctx)
31
31
  html += self.get_change_info(ar, cw)
32
- html = "<p>{}</p>.".format(html)
32
+ html = format_html("<p>{}</p>.", html)
33
33
  else:
34
34
  items = list(cw.get_updates_html(["_user_cache"]))
35
35
  if len(items) == 0:
36
36
  return
37
- html = _("{user} modified {what}").format(**ctx)
38
- html = "<p>{}:</p>".format(html)
37
+ txt = format_html(_("{user} modified {what}"), **ctx)
38
+ html = format_html("<p>{}:</p>", txt)
39
39
  html += tostring(E.ul(*items))
40
40
  html += self.get_change_info(ar, cw)
41
- return "<div>{}</div>".format(html)
41
+ return format_html("<div>{}</div>", html)
42
42
 
43
43
  def get_change_info(self, ar, cw):
44
- return ""
44
+ return mark_safe("")
45
45
 
46
46
  if dd.is_installed("notify"):
47
47
 
@@ -0,0 +1,46 @@
1
+ # -*- coding: UTF-8 -*-
2
+ # Copyright 2008-2024 Rumma & Ko Ltd
3
+ # License: GNU Affero General Public License v3 (see file COPYING for details)
4
+
5
+ from django.utils.translation import gettext_lazy as _
6
+
7
+ from lino.api import dd
8
+ from lino.utils import ONE_DAY
9
+
10
+
11
+ class PeriodType(dd.Choice):
12
+ ref_template = None
13
+
14
+ def __init__(self, value, text, duration, ref_template):
15
+ super().__init__(value, text, value)
16
+ self.ref_template = ref_template
17
+ self.duration = duration
18
+
19
+ class PeriodTypes(dd.ChoiceList):
20
+ item_class = PeriodType
21
+ verbose_name = _("Period type")
22
+ verbose_name_plural = _("Period types")
23
+ column_names = "value text duration ref_template"
24
+
25
+ @dd.displayfield(_("Duration"))
26
+ def duration(cls, p, ar):
27
+ return str(p.duration)
28
+
29
+ @dd.displayfield(_("Template for reference"))
30
+ def ref_template(cls, p, ar):
31
+ return p.ref_template
32
+
33
+ add = PeriodTypes.add_item
34
+ # value/names, text, duration, ref_template
35
+ add("month", _("Month"), 1, "{month:0>2}")
36
+ add("quarter", _("Quarter"), 3, "Q{period}")
37
+ add("trimester", _("Trimester"), 4, "T{period}")
38
+ add("semester", _("Semester"), 6, "S{period}")
39
+
40
+
41
+ class PeriodStates(dd.Workflow):
42
+ pass
43
+
44
+ add = PeriodStates.add_item
45
+ add('10', _("Open"), 'open')
46
+ add('20', _("Closed"), 'closed')
@@ -2,14 +2,40 @@
2
2
  # Copyright 2008-2024 Rumma & Ko Ltd
3
3
  # License: GNU Affero General Public License v3 (see file COPYING for details)
4
4
 
5
+ import datetime
5
6
  from django.db import models
6
7
  from django.utils.translation import gettext_lazy as _
7
8
 
8
9
  from lino.api import dd, rt
9
10
  from lino import mixins
10
11
  from lino.mixins import Referrable
12
+ from lino.utils import ONE_DAY
11
13
 
12
14
  from lino.modlib.office.roles import OfficeStaff
15
+ from lino.modlib.system.choicelists import DurationUnits
16
+
17
+
18
+ def get_range_for_date(date):
19
+ """
20
+ Return the default start and end date of the period to create for the given
21
+ date.
22
+ """
23
+ pt = dd.plugins.periods.period_type
24
+ month = date.month
25
+ year = date.year
26
+ month -= dd.plugins.periods.start_month
27
+ if month < 0:
28
+ month += 12
29
+ year -= 1
30
+ period = int(month / pt.duration)
31
+ month = dd.plugins.periods.start_month + period * pt.duration
32
+ if month > 12:
33
+ month -= 12
34
+ year += 1
35
+ sd = datetime.date(year, month, 1)
36
+ # ed = sd.replace(month=sd.month + pt.duration + 1, 1) - ONE_DAY
37
+ ed = DurationUnits.months.add_duration(sd, pt.duration) - ONE_DAY
38
+ return (sd, ed)
13
39
 
14
40
 
15
41
  class PeriodRange(dd.Model):
@@ -8,52 +8,17 @@ from django.utils.translation import gettext_lazy as _
8
8
 
9
9
  from lino.api import dd
10
10
  from lino import mixins
11
- from lino.utils import last_day_of_month, ONE_DAY
11
+ from lino.utils import ONE_DAY
12
12
  from lino.mixins.periods import DateRange
13
13
  from lino.mixins import Referrable
14
14
 
15
15
  from lino.modlib.office.roles import OfficeStaff
16
+ from .mixins import get_range_for_date
17
+ from .choicelists import PeriodTypes, PeriodStates
16
18
 
17
19
  NEXT_YEAR_SEP = "/"
18
20
  YEAR_PERIOD_SEP = "-"
19
21
 
20
- class PeriodType(dd.Choice):
21
- ref_template = None
22
- ref_template = None
23
-
24
- def __init__(self, value, text, duration, ref_template):
25
- super().__init__(value, text, value)
26
- self.ref_template = ref_template
27
- self.duration = duration
28
-
29
- class PeriodTypes(dd.ChoiceList):
30
- item_class = PeriodType
31
- verbose_name = _("Period type")
32
- verbose_name_plural = _("Period types")
33
- column_names = "value text duration ref_template"
34
-
35
- @dd.displayfield(_("Duration"))
36
- def duration(cls, p, ar):
37
- return str(p.duration)
38
-
39
- @dd.displayfield(_("Template for reference"))
40
- def ref_template(cls, p, ar):
41
- return p.ref_template
42
-
43
- add = PeriodTypes.add_item
44
- # value/names, text, duration, ref_template
45
- add("month", _("Month"), 1, "{month:0>2}")
46
- add("quarter", _("Quarter"), 3, "Q{period}")
47
- add("trimester", _("Trimester"), 4, "T{period}")
48
- add("semester", _("Semester"), 6, "S{period}")
49
-
50
-
51
- class PeriodStates(dd.Workflow):
52
- pass
53
-
54
- add = PeriodStates.add_item
55
- add('10', _("Open"), 'open')
56
- add('20', _("Closed"), 'closed')
57
22
 
58
23
 
59
24
  class StoredYear(DateRange, Referrable):
@@ -120,7 +85,7 @@ class StoredPeriod(DateRange, Referrable):
120
85
  preferred_foreignkey_width = 10
121
86
 
122
87
  state = PeriodStates.field(default='open')
123
- year = dd.ForeignKey('periods.StoredYear', blank=True, null=True)
88
+ year = dd.ForeignKey('periods.StoredYear', blank=True, null=True, related_name="periods")
124
89
  remark = models.CharField(_("Remark"), max_length=250, blank=True)
125
90
 
126
91
  @classmethod
@@ -197,10 +162,8 @@ class StoredPeriod(DateRange, Referrable):
197
162
  ref = date2ref(date)
198
163
  obj = cls.get_by_ref(ref, None)
199
164
  if obj is None:
200
- obj = cls(
201
- ref=ref,
202
- start_date=date.replace(day=1),
203
- end_date=last_day_of_month(date))
165
+ sd, ed = get_range_for_date(date)
166
+ obj = cls(ref=ref, start_date=sd, end_date=ed)
204
167
  obj.full_clean()
205
168
  obj.save()
206
169
  return obj
@@ -208,7 +171,7 @@ class StoredPeriod(DateRange, Referrable):
208
171
  def full_clean(self, *args, **kwargs):
209
172
  if self.start_date is None:
210
173
  self.start_date = dd.today().replace(day=1)
211
- if not self.year:
174
+ if not self.year_id:
212
175
  self.year = StoredYear.get_or_create_from_date(self.start_date)
213
176
  super().full_clean(*args, **kwargs)
214
177
 
@@ -218,10 +181,19 @@ class StoredPeriod(DateRange, Referrable):
218
181
  # "{0} {1} (#{0})".format(self.pk, self.year)
219
182
  return self.ref
220
183
 
184
+ # def get_str_words(self, ar):
185
+ # # if ar.is_obvious_field("year"):
186
+ # if self.year.covers_date(dd.today()):
187
+ # # yield self.nickname
188
+ # yield f"{dd.plugins.periods.period_name} {self.nickname}"
189
+ # else:
190
+ # yield str(self)
191
+
221
192
  @property
222
193
  def nickname(self):
223
194
  if self.year.covers_date(dd.today()):
224
- if len(parts := self.ref.split(YEAR_PERIOD_SEP)) == 2:
195
+ if self.ref and len(parts := self.ref.split(YEAR_PERIOD_SEP)) == 2:
196
+ # return "{} {}".format(dd.plugins.periods.period_name, parts[1])
225
197
  return parts[1]
226
198
  return self.ref
227
199
 
@@ -51,12 +51,9 @@ class PublisherBuildMethod(JinjaBuildMethod):
51
51
  )
52
52
  context = elem.get_printable_context(ar)
53
53
  html = tpl.render(context)
54
- self.html2file(html, filename)
54
+ self.html2file(html, filename, context)
55
55
  return os.path.getmtime(filename)
56
56
 
57
- def html2file(self, html, filename):
58
- raise NotImplementedError()
59
-
60
57
 
61
58
  BuildMethods.add_item_instance(PublisherBuildMethod())
62
59
 
@@ -15,9 +15,6 @@ class Plugin(ad.Plugin):
15
15
 
16
16
  verbose_name = _("System")
17
17
  needs_plugins = ["lino.modlib.printing"]
18
- use_dashboard_layouts = False
19
- """Whether to use system.DashboardLayouts. This feature is broken.
20
- """
21
18
 
22
19
  def setup_config_menu(self, site, user_type, m, ar=None):
23
20
  system = m.add_menu(self.app_label, self.verbose_name)
@@ -113,19 +113,6 @@ PeriodEvents.add_item_instance(PeriodEnded("30", "ended"))
113
113
  # add('30', _("Ends"), 'ended')
114
114
 
115
115
 
116
- class DashboardLayout(Choice):
117
- main = None
118
-
119
- def __init__(self, value, text, main, **kwargs):
120
- self.main = main
121
- # kwargs.update(text=value)
122
- super(DashboardLayout, self).__init__(value, text, value, **kwargs)
123
-
124
-
125
- class DashboardLayouts(ChoiceList):
126
- item_class = DashboardLayout
127
-
128
-
129
116
  class DurationUnit(Choice):
130
117
  du_freq = None # dateutils frequency
131
118
 
@@ -79,6 +79,7 @@ class Lockable(EditSafe):
79
79
 
80
80
  locked_by = dd.ForeignKey(
81
81
  rt.settings.SITE.user_model,
82
+ verbose_name=_("Locked by"),
82
83
  null=True,
83
84
  default=None,
84
85
  blank=True,
@@ -29,7 +29,6 @@ from .choicelists import (
29
29
  YesNo,
30
30
  Genders,
31
31
  PeriodEvents,
32
- DashboardLayouts,
33
32
  DurationUnits,
34
33
  Recurrences,
35
34
  Weekdays,
@@ -221,12 +220,6 @@ testcase_setup.connect(my_handler)
221
220
  dd.connection_created.connect(my_handler)
222
221
  models.signals.post_migrate.connect(my_handler)
223
222
 
224
- # def dashboard_layouts(cls, k, layout_class, **options):
225
- # assert k == "detail_layout"
226
- # yield cls.detail_layout
227
- # for i in DashboardLayouts.get_list_items():
228
- # yield i.main
229
-
230
223
 
231
224
  class SiteConfigs(dd.Table):
232
225
  model = "system.SiteConfig"
@@ -266,15 +259,6 @@ class Dashboard(EmptyTable):
266
259
  # notify.MyMessages
267
260
  # """
268
261
 
269
- @classmethod
270
- def get_extra_layouts(cls):
271
- # count = 0
272
- for i in DashboardLayouts.get_list_items():
273
- yield i.value, i.main
274
- # print("20210530", i.value, repr(i.main))
275
- # count += 1
276
- # assert count > 0
277
-
278
262
  @classmethod
279
263
  def get_default_action(cls):
280
264
  # raise Exception("20210530")
@@ -288,8 +272,6 @@ class Dashboard(EmptyTable):
288
272
  @classmethod
289
273
  def get_detail_action(self, ar):
290
274
  u = ar.get_user()
291
- if u.dashboard_layout:
292
- return cls.get_action_by_name("extra_" + u.dashboard_layout.name)
293
275
  return cls.get_action_by_name("extra_default")
294
276
 
295
277
  @dd.htmlbox()
@@ -7,10 +7,10 @@ import shutil
7
7
  import uuid
8
8
  from pathlib import Path
9
9
 
10
- from rstgen.sphinxconf.sigal_image import parse_image_spec
11
- from rstgen.sphinxconf.sigal_image import Standard, Thumb, Tiny, Wide, Solo, Duo, Trio
12
- SMALL_FORMATS = (Thumb, Tiny, Duo, Trio)
13
-
10
+ # from rstgen.sphinxconf.sigal_image import parse_image_spec
11
+ # from rstgen.sphinxconf.sigal_image import Standard, Thumb, Tiny, Wide, Solo, Duo, Trio
12
+ # SMALL_FORMATS = (Thumb, Tiny, Duo, Trio)
13
+ #
14
14
  from django.db import models
15
15
  from django.conf import settings
16
16
  from django.core.files.storage import default_storage
@@ -198,36 +198,36 @@ class UploadBase(Commentable, GalleryViewable):
198
198
  return text
199
199
  return E.a(text, href=mf.get_download_url(), target="_blank")
200
200
 
201
- def memo2html(self, ar, text, **ctx):
202
- mf = self.get_media_file()
203
- if mf is None:
204
- return format_html("<em>{}</em>", text or str(self))
205
- ctx.update(src=mf.get_download_url())
206
- ctx.update(href=ar.renderer.obj2url(ar, self))
207
- small_url = mf.get_image_url()
208
- if small_url is None or small_url == mf.url: # non-previewable mimetype
209
- if not text:
210
- text = str(self)
211
- ctx.update(text=text)
212
- tpl = '(<a href="{src}" target="_blank">{text}</a>'
213
- tpl += '| <a href="{href}">detail</a>)'
214
- return format_html(tpl, **ctx)
215
-
216
- fmt = parse_image_spec(text, **ctx)
217
- if isinstance(fmt, SMALL_FORMATS):
218
- fmt.context.update(src=small_url)
219
-
220
- if not fmt.context["caption"]:
221
- fmt.context["caption"] = self.description or str(self)
222
-
223
- rv = format_html(
224
- '<a href="{href}" target="_blank"><img src="{src}"'
225
- + ' style="{style}" title="{caption}"/></a>', **fmt.context)
226
- # if ar.renderer.front_end.media_name == 'react':
227
- # return ('<figure class="lino-memo-image"><img src="{src}" ' +
228
- # 'style="{style}" title="{caption}"/><figcaption' +
229
- # ' style="text-align: center;">{caption}</figcaption>' +
230
- # '</figure>').format(**kwargs)
231
-
232
- # print("20230325", rv)
233
- return rv
201
+ # def memo2html(self, ar, text, **ctx):
202
+ # mf = self.get_media_file()
203
+ # if mf is None:
204
+ # return format_html("<em>{}</em>", text or str(self))
205
+ # ctx.update(src=mf.get_download_url())
206
+ # ctx.update(href=ar.renderer.obj2url(ar, self))
207
+ # small_url = mf.get_image_url()
208
+ # if small_url is None or small_url == mf.url: # non-previewable mimetype
209
+ # if not text:
210
+ # text = str(self)
211
+ # ctx.update(text=text)
212
+ # tpl = '(<a href="{src}" target="_blank">{text}</a>'
213
+ # tpl += '| <a href="{href}">detail</a>)'
214
+ # return format_html(tpl, **ctx)
215
+ #
216
+ # fmt = parse_image_spec(text, **ctx)
217
+ # if isinstance(fmt, SMALL_FORMATS):
218
+ # fmt.context.update(src=small_url)
219
+ #
220
+ # if not fmt.context["caption"]:
221
+ # fmt.context["caption"] = self.description or str(self)
222
+ #
223
+ # rv = format_html(
224
+ # '<a href="{href}" target="_blank"><img src="{src}"'
225
+ # + ' style="{style}" title="{caption}"/></a>', **fmt.context)
226
+ # # if ar.renderer.front_end.media_name == 'react':
227
+ # # return ('<figure class="lino-memo-image"><img src="{src}" ' +
228
+ # # 'style="{style}" title="{caption}"/><figcaption' +
229
+ # # ' style="text-align: center;">{caption}</figcaption>' +
230
+ # # '</figure>').format(**kwargs)
231
+ #
232
+ # # print("20230325", rv)
233
+ # return rv