Skip to content
Snippets Groups Projects
Commit 8bd53479 authored by dcz's avatar dcz
Browse files

Notes visible for superleksykografs

parent 170b022d
No related branches found
No related tags found
No related merge requests found
......@@ -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="#"
......
......@@ -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')
......
......@@ -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"]
......@@ -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)()
......@@ -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>
......@@ -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],
})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment