diff --git a/entries/static/entries/js/unification_entries_list.js b/entries/static/entries/js/unification_entries_list.js index 492c88be865adc6506f6331c7965a6c0b93337c5..8ef45fe958edee26d74ee6a6356879411c7cb5e8 100644 --- a/entries/static/entries/js/unification_entries_list.js +++ b/entries/static/entries/js/unification_entries_list.js @@ -96,7 +96,8 @@ function show_notes_form($container, pk, model, refreshFunction, type, title, bo dataType: 'json', data: { title: $('.note-form input[name=title]').val(), - note: $('.note-form textarea[name=note]').val() + note: $('.note-form textarea[name=note]').val(), + super: $('.note-form input[name=super]').val() }, timeout: 5000, success: function (response) { @@ -136,6 +137,7 @@ function setup_notes($container, $template, pk, model, refreshFunction, type, ti <tr role="button" data-toggle="collapse" data-target="#note-${note.pk}" class="cursor-pointer"> <td>${note.title}</td> <td>${note.owner_label}</td> + <td>${note.super}</td> <td> <a href="#" diff --git a/semantics/views.py b/semantics/views.py index 9b6f7cee0f0b8320fb300113238699eaf08a4f86..da49e6a191ad1da53c4dc6ee9bef47f8677fe582 100644 --- a/semantics/views.py +++ b/semantics/views.py @@ -19,6 +19,7 @@ def frame_mark_as_invalid(request, frame_pk): frame.save() return {} + @ajax(login_required=True, method='post') @transaction.atomic @permission_required('semantics.manage_invalid_lexical_units') diff --git a/users/forms.py b/users/forms.py index 26bc2e478f7a5275ccfb14a1d880e9491f16f6c6..6400b8c51347e4183957f02cc0ab7ccf812c5d91 100644 --- a/users/forms.py +++ b/users/forms.py @@ -109,4 +109,4 @@ password_reset_set_password_form_helper.layout = Layout( class NoteForm(forms.ModelForm): class Meta: model = Note - fields = ["title", "note"] + fields = ["title", "note", "super"] diff --git a/users/models.py b/users/models.py index 2fe93d375d97f6a5814cfde766f4d70b01070b45..d289bd9cfaf4d06f1b029ccf2545ef80435d5760 100644 --- a/users/models.py +++ b/users/models.py @@ -34,17 +34,22 @@ class Assignment(models.Model): class NoteQuerySet(models.QuerySet): def for_user(self, user): notes = ( - self.filter(author=user).annotate(owner_label=models.Value(_('własne'), output_field=models.CharField())) + self.filter(author=user) ) - if user.has_perm('user.view_all_notes'): + if user.has_perm('users.view_all_notes'): notes |= ( self.exclude(author=user).annotate(owner_label=models.F('author__username')) ) - else: + elif user.groups.filter(name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME).exists(): notes |= ( - self.exclude(author=user).filter(author__groups__name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME) - .annotate(owner_label=models.Value(_('Super'), output_field=models.CharField())) + self.exclude(author=user) + .filter(super=True) ) + # notes |= ( + # self.exclude(author=user).filter(author__groups__name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME) + # .annotate(owner_label=models.Value(_('Super'), output_field=models.CharField())) + # ) + return notes @@ -57,5 +62,6 @@ class Note(models.Model): note = models.TextField() created_at = models.DateTimeField(auto_now_add=True) type = models.CharField(max_length=100, default=None, blank=True, null=True) + super = models.BooleanField(default=False) objects = models.Manager.from_queryset(NoteQuerySet)() diff --git a/users/templates/notes.html b/users/templates/notes.html index 0b2ba2425daab3180a4691a00a5d030a903536bc..be44cca03fea418e5bb372246240b5dc6d54b147 100644 --- a/users/templates/notes.html +++ b/users/templates/notes.html @@ -9,6 +9,7 @@ </div> <div class="d-flex"> <div class="flex-grow-1 mr-3"> + Superleksykograf <input id="super" name="super" type="checkbox" title="{% trans 'Notatka widoczna dla superleksykografa' %}" /> <input id="title" name="title" class="form-control mb-2" placeholder="{% trans 'Tytuł notatki' %}" /> <textarea id="note" name="note" class="form-control" placeholder="{% trans 'Treść notatki' %}"></textarea> </div> @@ -23,7 +24,14 @@ <a href="#" class="show-note-form btn btn-xs btn-outline-dark ml-2">{% trans 'Dodaj' %}</a> </div> <table class="table table-sm table-striped border notes-table mb-0" data-url="{% url 'users:get_notes' model='MODEL' pk='PK' type='TYPE' %}"> - <tbody></tbody> + <tbody> + <tr style="font-weight: bold"> + <td>Tytuł</td> + <td>Właściciel</td> + <td>Czy widoczna dla superleksykografa</td> + <td></td> + </tr> + </tbody> </table> </div> </div> diff --git a/users/views.py b/users/views.py index 7be4819359d1165a5268da3fe6ab7a5d1a70dcc6..374106b6c276ff43354902bd1384828ce0a24407 100644 --- a/users/views.py +++ b/users/views.py @@ -68,11 +68,12 @@ def get_notes(request, model, pk, type): return JsonResponse({ "notes": [{ "pk": note.pk, - "owner_label": note.owner_label, + "owner_label": "własne" if note.author.pk is request.user.pk else note.author.username, "created_at": note.created_at, "title": note.title, "note": note.note, "type": note.type, + "super": "Tak" if note.super else "Nie" } for note in notes], })