Commit 01db05ba authored by Bryan  BRANCOTTE's avatar Bryan BRANCOTTE

Allowing moderator to change the color of the global responses

parent 5934a2d9
from basetheme_bootstrap.admin import ViewOnSiteModelAdmin
from django.apps import apps
from django.contrib import admin
from django.contrib.auth import get_permission_codename
from django.utils.translation import ugettext_lazy as _
from viralhostrangedb import models, business_process
......@@ -84,6 +85,28 @@ class ViralHostResponseValueInDataSourceAdmin(ViewOnSiteModelAdmin):
return o.host.name
@admin.register(models.GlobalViralHostResponseValue)
class GlobalViralHostResponseValueAdmin(ViewOnSiteModelAdmin):
list_display = (
'name',
'value',
'color',
)
def get_readonly_fields(self, request, obj=None):
readonly_fields = self.readonly_fields
if not request.user.has_perm("viralhostrangedb.change_globalviralhostresponsevalue"):
readonly_fields += ('name', 'value')
return readonly_fields
def has_change_permission(self, request, obj=None):
if super().has_change_permission(request=request, obj=obj):
return True
opts = self.opts
codename = get_permission_codename('change', opts) + "_color"
return request.user.has_perm("%s.%s" % (opts.app_label, codename))
for model in apps.get_app_config('viralhostrangedb').models.values():
try:
admin.site.register(model)
......
# Generated by Django 2.2.5 on 2019-10-16 12:00
from django.db import migrations
from django.db import models
class Migration(migrations.Migration):
dependencies = [
('viralhostrangedb', '0024_auto_20191016_1352'),
]
operations = [
migrations.AlterModelOptions(
name='globalviralhostresponsevalue',
options={'permissions': (
('change_globalviralhostresponsevalue_color', 'Can change Global Viral-Host response color'),),
'verbose_name': 'Global Viral-Host response values',
'verbose_name_plural': 'Global Viral-Host response values'},
),
migrations.AlterField(
model_name='userpreferences',
name='agreed_infection',
field=models.BooleanField(default=False,
help_text='By default we consider that there is an infection when in <i>at least one</i> data source an infection was observed.',
verbose_name='Consider that there is an infection only when <i>all data sources</i> documenting the interaction observed an infection'),
),
migrations.AlterField(
model_name='userpreferences',
name='display_all_at_once',
field=models.BooleanField(default=False,
help_text='Otherwise we fit the table to the screen and use scroll bar when needed.',
verbose_name='Display all the table at once, even if it does not fit on screen'),
),
migrations.AlterField(
model_name='userpreferences',
name='focus_disagreements_toggle',
field=models.BooleanField(default=False,
help_text='Responses where data sources disagree are highlighted, others are faded.',
verbose_name='Render table focusing on disagreements'),
),
migrations.AlterField(
model_name='userpreferences',
name='hide_cols_with_no_infection',
field=models.BooleanField(default=False, help_text='hide_cols_with_no_infection_help_text',
verbose_name='hide_cols_with_no_infection_label'),
),
migrations.AlterField(
model_name='userpreferences',
name='hide_rows_with_no_infection',
field=models.BooleanField(default=False, help_text='hide_rows_with_no_infection_help_text',
verbose_name='hide_rows_with_no_infection_label'),
),
migrations.AlterField(
model_name='userpreferences',
name='host_infection_ratio',
field=models.BooleanField(default=False,
help_text='Note that it can deteriorate the overall response time.',
verbose_name='Show the infection ratio for the hosts'),
),
migrations.AlterField(
model_name='userpreferences',
name='virus_infection_ratio',
field=models.BooleanField(default=False,
help_text='Note that it can deteriorate the overall response time.',
verbose_name='Show the infection ratio for the viruses'),
),
migrations.AlterField(
model_name='userpreferences',
name='weak_infection',
field=models.BooleanField(default=False,
help_text='By default we consider that there is an infection only when the highest response is observed.',
verbose_name='Consider all positive response as a infection'),
),
]
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib.auth import get_permission_codename
from django.contrib.auth.models import Permission, Group
from django.contrib.contenttypes.models import ContentType
from django.db import migrations
def migration_code(apps, schema_editor):
moderator, _ = Group.objects.get_or_create(name="Moderator")
GlobalViralHostResponseValue = apps.get_model("viralhostrangedb", "GlobalViralHostResponseValue")
ct = ContentType.objects.get_for_model(GlobalViralHostResponseValue)
opts = GlobalViralHostResponseValue._meta
for codename in [
get_permission_codename('change', opts) + "_color",
get_permission_codename('view', opts),
]:
for perm in Permission.objects.filter(codename=codename, content_type=ct):
moderator.permissions.add(perm)
class Migration(migrations.Migration):
dependencies = [
('viralhostrangedb', '0025_auto_20191016_1400'),
]
operations = [
migrations.RunPython(migration_code, reverse_code=migrations.RunPython.noop),
]
......@@ -23,6 +23,10 @@ class GlobalViralHostResponseValue(models.Model):
verbose_name = _("Global Viral-Host response values")
verbose_name_plural = _("Global Viral-Host response values")
permissions = (
("change_globalviralhostresponsevalue_color", "Can change Global Viral-Host response color"),
)
name = models.CharField(
verbose_name=_("response__name__verbose_name"),
help_text=_("response__name__help_text"),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment