Move comment user label extraction to the model
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -76,10 +76,7 @@ class DocumentCommentsApp(MayanAppConfig):
|
||||
)
|
||||
|
||||
SourceColumn(attribute='submit_date', source=Comment)
|
||||
SourceColumn(
|
||||
func=lambda context: context['object'].user.get_full_name() if context['object'].user.get_full_name() else context['object'].user,
|
||||
source=Comment
|
||||
)
|
||||
SourceColumn(attribute='get_user_label', source=Comment)
|
||||
SourceColumn(attribute='comment', source=Comment)
|
||||
|
||||
document_page_search.add_model_field(
|
||||
|
||||
@@ -60,6 +60,13 @@ class Comment(models.Model):
|
||||
viewname='comments:comment_details', kwargs={'pk': self.pk}
|
||||
)
|
||||
|
||||
def get_user_label(self):
|
||||
if self.user.get_full_name():
|
||||
return self.user.get_full_name()
|
||||
else:
|
||||
return self.user.username
|
||||
get_user_label.short_description = _('User')
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
_user = kwargs.pop('_user', None) or self.user
|
||||
created = not self.pk
|
||||
|
||||
Reference in New Issue
Block a user