diff --git a/dictionary_statistics/views.py b/dictionary_statistics/views.py index c681d40d2780f4d54d3ea4d93799b69557b42dde..2a86731dbc42270c6d57977ee4900226cab6d787 100644 --- a/dictionary_statistics/views.py +++ b/dictionary_statistics/views.py @@ -8,34 +8,42 @@ from semantics.models import Frame, FrameOpinion from entries.polish_strings import POS as POS_names, STATUS, SCHEMA_OPINION, FRAME_OPINION + @login_required def dictionary_statistics(request): ALL = _('wszystkie') - + # ENTRIES entries = Entry.objects.filter(import_error=False) pos_names = POS_names() status_names = STATUS() entry_statuses = list(Status.objects.all()) all_pos = ['verb', 'noun', 'adj', 'adv'] - entry_stats = { ALL : [entries.count()] + [entries.filter(pos__tag=pos).count() for pos in all_pos] } + entry_stats = {ALL: [entries.count()] + [entries.filter(pos__tag=pos).count() for pos in all_pos]} used_statuses = set() for status in entry_statuses: c = entries.filter(status=status).count() if c: used_statuses.add(status) - entry_stats[status_names[status.key]] = [entries.filter(status=status).count()] + [entries.filter(status=status, pos__tag=pos).count() for pos in all_pos] + entry_stats[status_names[status.key]] = [entries.filter(status=status).count()] + [ + entries.filter(status=status, pos__tag=pos).count() for pos in all_pos] all_statuses = [ALL] + [status_names[status.key] for status in entry_statuses if status in used_statuses] all_pos = [ALL] + [pos_names[pos] for pos in all_pos] - + # SCHEMATA schemata = Schema.objects.filter(subentries__entry__import_error=False) schema_opinions = SCHEMA_OPINION() - schema_stats = [(ALL, 'all', schemata.count())] + [(schema_opinions[opinion.key], opinion.key, schemata.filter(opinion=opinion).count()) for opinion in SchemaOpinion.objects.all()] - + schema_stats = [(ALL, 'all', schemata.count())] + [ + (schema_opinions[opinion.key], opinion.key, schemata.filter(opinion=opinion).count()) for opinion in + SchemaOpinion.objects.all()] + # FRAMES - frames = Frame.objects.all() #filter(arguments__argument_connections__schema_connections__subentry__entry__import_error=False) + frames = Frame.objects.all() # filter(arguments__argument_connections__schema_connections__subentry__entry__import_error=False) frame_opinions = FRAME_OPINION() - frame_stats = [(ALL, 'all', frames.count())] + [(frame_opinions[opinion.key], opinion.key, frames.filter(opinion=opinion).count()) for opinion in FrameOpinion.objects.all()] - - return render(request, 'dictionary_statistics.html', { 'all_statuses' : all_statuses, 'all_pos' : all_pos, 'entry_stats' : entry_stats, 'schema_stats' : schema_stats, 'frame_stats' : frame_stats }) + frame_stats = [(ALL, 'all', frames.count())] + [ + (frame_opinions[opinion.key], opinion.key, frames.filter(opinion=opinion).count()) for opinion in + FrameOpinion.objects.all()] + + return render(request, 'dictionary_statistics.html', + {'all_statuses': all_statuses, 'all_pos': all_pos, 'entry_stats': entry_stats, + 'schema_stats': schema_stats, 'frame_stats': frame_stats}) diff --git a/entries/views.py b/entries/views.py index 7823586f6262aa92d34820f1d617d917abe278a8..a6bacc6aff15636ec6580b4504976145370b4998 100644 --- a/entries/views.py +++ b/entries/views.py @@ -25,7 +25,7 @@ from semantics.models import Frame, PredefinedSelectionalPreference, SelectivePr from common.decorators import ajax_required, ajax from unifier.models import UnifiedFrame -from users.models import Assignment +from django.conf import settings from .forms import ( EntryForm, @@ -73,6 +73,7 @@ def entries(request): @login_required def unification(request): + user = request.user return render( request, 'unification.html', @@ -83,6 +84,7 @@ def unification(request): 'frames_form': FrameFormFactory.get_form(as_subform=False), 'schemata_form': SchemaFormFactory.get_form(as_subform=False), 'unified_frames_form': UnifiedFrameFormFactory.get_form(as_subform=False), + 'is_superlexicograf': user.groups.filter(name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME).exists() }, ) diff --git a/users/templates/notes.html b/users/templates/notes.html index be44cca03fea418e5bb372246240b5dc6d54b147..40276a51c4e49d848d825b805e6f41e812d3dc1d 100644 --- a/users/templates/notes.html +++ b/users/templates/notes.html @@ -9,7 +9,12 @@ </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' %}" /> + {% if is_superlexicograf %} + Użytkownik + {% else %} + Superleksykograf + {% endif %} + <input id="super" name="super" type="checkbox" title="{% if is_superlexicograf %} {% trans 'Notatka widoczna dla użytkownika' %} {% else %} {% trans 'Notatka widoczna dla superleksykografa' %} {% endif %}" /> <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> diff --git a/users/views.py b/users/views.py index 374106b6c276ff43354902bd1384828ce0a24407..6631c4a9044d2fffbf81b686239d4f64e3549561 100644 --- a/users/views.py +++ b/users/views.py @@ -12,6 +12,7 @@ from common.decorators import ajax from users.forms import UserForm, UserProfileForm, NoteForm from users.models import Note from users.utils import send_new_user_email +from django.conf import settings @permission_required('users.view_user') @@ -83,7 +84,11 @@ def get_notes(request, model, pk, type): def add_note(request, model, pk, type=None): model = apps.get_model(*model.split('.')) subject = get_object_or_404(model, pk=pk) - note = Note(author=request.user, subject=subject) + user = request.user + if request.POST.get('super', 'off') == 'on' \ + and user.groups.filter(name=settings.SUPER_LEXICOGRAPHS_GROUP_NAME).exists(): + user = subject.assignments.first().user + note = Note(author=user, subject=subject) if type: note.type = type form = NoteForm(instance=note, data=request.POST)