The topic this comment is about. This field is a Generic Foreign Key,
i.e. users can basically comment on any database object. It is however
the application developer who decides where comments can be
created and how they are being displayed.
The owner of a comment is always an instance of a subclass of
Commentable.
Return a HTML formatted string with the description of this
Commentable as it should be displayed by the slave summary of
CommentsByOwner.
It must be a string and not an etree element. That's because
it usually includes the content of RichTextField. If the API
required an element, it would require us to parse this content
just in order to generate HTML from it.
Return either None or a database object that represents the commenting group
where this comment is being done.
If not None, the object must have a field ref which will be
shown in the summary of RecentComments.
get_comments_filter(cls,user):
Return the filter to be added when a given user requests comments about
commentables of this type.
Return None to not add any filter. Otherwise the return value should
be a django.db.models.Q object.
Default behaviour is that public comments are visible even to anonymous
while private comments are visible only to their author and to
PrivateCommentsReader.
You can override this class method to define your own privacy settings.
If you override this method, you probably want to define a
django.contrib.contenttypes.fields.GenericRelation on your Commentable
in order to write filter conditions based on the owner of the comment.
>>> print(truncate_comment('<h1 style="color: #5e9ca0;">Styled comment <span style="color: #2b2301;">pasted from word!</span> </h1>'))... Styled comment pasted from word!
>>> print(truncate_comment('<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>',30))Lorem ipsum dolor sit amet, co...
>>> print(truncate_comment('<p>Lorem ipsum dolor sit amet</p><p>consectetur adipiscing elit.</p>',30))Lorem ipsum dolor sit ametco...
>>> print(truncate_comment('<p>A short paragraph</p><p><ul><li>first</li><li>second</li></ul></p>'))A short paragraphfirstsecond
>>> html='<p>Ich habe Hirn, ich will hier raus! – Wie im Netz der Flachsinn regiert.</p>\\n<ul>\\n<li>Veröffentlicht: 6. Mai 2017</li>\\n<li>Vorgestellt in: <a href="https://www.linkedin.com/pulse/feed/channel/deutsch"><span>Favoriten der Redaktion</span></a>, <a href="https://www.linkedin.com/pulse/feed/channel/jobs"><span>Job & Karriere</span></a>, <a href="https://www.linkedin.com/pulse/feed/channel/verkauf"><span>Marketing & Verkauf</span></a>, <a href="https://www.linkedin.com/pulse/feed/channel/technologie"><span>Technologie & Internet</span></a>, <a href="https://www.linkedin.com/pulse/feed/channel/wochenendLekture"><span>Wochenend-Lektüre</span></a></li>\\n</ul>\\n<ul>\\n<li><span><span>Gefällt mir</span></span><span>Ich habe Hirn, ich will hier raus! – Wie im Netz der Flachsinn regiert</span>\\n<p> </p>\\n<a href="https://www.linkedin.com/pulse/ich-habe-hirn-hier-raus-wie-im-netz-der-flachsinn-regiert-dueck"><span>806</span></a></li>\\n<li><span>Kommentar</span>\\n<p> </p>\\n<a href="https://www.linkedin.com/pulse/ich-habe-hirn-hier-raus-wie-im-netz-der-flachsinn-regiert-dueck#comments"><span>42</span></a></li>\\n<li><span>Teilen</span><span>Ich habe Hirn, ich will hier raus! – Wie im Netz der Flachsinn regiert teilen</span>\\n<p> </p>\\n<span>131</span></li>\\n</ul>\\n<p><a href="https://www.linkedin.com/in/gunterdueck"><span>Gunter Dueck</span></a> <span>Folgen</span><span>Gunter Dueck</span> Philosopher, Writer, Keynote Speaker</p>\\n<p>Das Smartphone vibriert, klingelt oder surrt. Zing! Das ist der Messenger. Eine Melodie von eBay zeigt an, dass eine Auktion in den nächsten Minuten endet. Freunde schicken Fotos, News versprechen uns "Drei Minuten, nach denen du bestimmt lange weinen musst" oder "Wenn du dieses Bild siehst, wird sich dein Leben auf der Stelle für immer verändern".</p>\\n<p>Politiker betreiben statt ihrer eigentlichen Arbeit nun simples Selbstmarketing und fordern uns auf, mal schnell unser Verhalten zu ändern – am besten natürlich "langfristig" und "nachhaltig". Manager fordern harsch immer mehr Extrameilen von uns ein, die alle ihre (!) Probleme beseitigen, und es gibt für jede Schieflage in unserem Leben Rat von allerlei Coaches und Therapeuten, es gibt Heilslehren und Globuli.</p>'>>> print(truncate_comment(html))Ich habe Hirn, ich will hier raus! – Wie im Netz der Flachsinn regiert.
<BLANKLINE>
<BLANKLINE>
<BLANKLINE>
<a href="https://www.linkedin.com/in/gunterdueck"><span>Gunter Dueck</span></a> FolgenGunter Dueck Philosopher, Writer, Keynote Speaker
<BLANKLINE>
Das Smartphone vibriert, klingelt oder surrt. Zing! Das ist der Messenger. Eine Melodie von eBay zeigt an, dass eine Auktion in den nächsten Minuten...
>>> print(truncate_comment('Two paragraphs of plain text.\n\n\nHere is the second paragraph.'))Two paragraphs of plain text.Here is the second paragraph.
comments
: The comments framework¶The
lino.modlib.comments
plugin adds a framework for handling comments.This is a tested document. The following instructions are used for initialization:
Comments¶
Django model to represent a comment.
The author of the comment.
The topic this comment is about. This field is a Generic Foreign Key, i.e. users can basically comment on any database object. It is however the application developer who decides where comments can be created and how they are being displayed.
The
owner
of a comment is always an instance of a subclass ofCommentable
.The full body text of your comment.
The first paragraph of your
body
.The emotion of this comment.
When this comment has been published. A timestamp.
Whether to show only (un)published comments, independently of the publication date.
The date range to filter.
Which event (created, modified or published) to consider when applying the date range given by
start_date
andend_date
.Return this comment for usage in a list item as a string with HTML tags.
The
summary view
for this table.Shows the comments for a given database object.
The
summary view
for this table.The choicelist with selections for
Comments.observed_event
.Emotions¶
The list of available values for the
Comment.emotion
field.Comment types¶
The
CommentType
model is not being used in production, one day we will probably remove it.The table with all existing comment types.
This usually is accessible via the Configure menu.
Commentable¶
Mixin for models whose instances can be discussion topic of comments.
The template to use for the comment that gets generated automatically when an end user creates an instance of this.
Set this to None if you don't want Lino to generate any comment when an instance gets created.
Return a HTML formatted string with the description of this Commentable as it should be displayed by the slave summary of CommentsByOwner.
It must be a string and not an etree element. That's because it usually includes the content of RichTextField. If the API required an element, it would require us to parse this content just in order to generate HTML from it.
This is automatically called when a comment has been created or modified.
Return either None or a database object that represents the commenting group where this comment is being done.
If not None, the object must have a field
ref
which will be shown in the summary ofRecentComments
.Return the filter to be added when a given user requests comments about commentables of this type.
Return None to not add any filter. Otherwise the return value should be a
django.db.models.Q
object.Default behaviour is that public comments are visible even to anonymous while private comments are visible only to their author and to
PrivateCommentsReader
.You can override this class method to define your own privacy settings.
Usage example in
lino_xl.lib.groups.Group
andlino_xl.lib.tickets.Ticket
.If you override this method, you probably want to define a
django.contrib.contenttypes.fields.GenericRelation
on your Commentable in order to write filter conditions based on the owner of the comment.Utilities¶
The preview of a comment¶
Usage examples:
<BLANKLINE>
<BLANKLINE>
<BLANKLINE> <a href="https://www.linkedin.com/in/gunterdueck"><span>Gunter Dueck</span></a> FolgenGunter Dueck Philosopher, Writer, Keynote Speaker <BLANKLINE> Das Smartphone vibriert, klingelt oder surrt. Zing! Das ist der Messenger. Eine Melodie von eBay zeigt an, dass eine Auktion in den nächsten Minuten...