...
 
Commits (2)
......@@ -17,17 +17,17 @@ class ContentForm(forms.ModelForm):
class ContentAdmin(DjangoObjectActions, AdminRowActionsMixin, admin.ModelAdmin):
form = ContentForm
list_display = ('_linked_title',
'verified_at',
'is_verification_enabled', 'verified_at',
'_status_and_message')
search_fields = ('title', 'notes', 'verification_error', 'verification_status', 'url')
list_filter = ('verification_status', 'organisation_type')
list_filter = ('verification_status', 'organisation_type', 'is_verification_enabled',)
fieldsets = (
(None, {
'fields': ('title', 'organisation_type', 'timeout', 'notes', 'op_url', 'url', 'xpath', 'use_cleaner',
'content'),
}),
('Verification', {
'fields': ('verified_at', 'verification_status', 'verification_error')
'fields': ('is_verification_enabled', 'verified_at', 'verification_status', 'verification_error')
})
)
readonly_fields = (
......@@ -57,7 +57,6 @@ class ContentAdmin(DjangoObjectActions, AdminRowActionsMixin, admin.ModelAdmin):
msg = obj.verification_error
return mark_safe(f"{status} - {msg}")
_status_and_message.short_description = 'Status'
# list actions on many objects (checkbox)
......@@ -67,7 +66,19 @@ class ContentAdmin(DjangoObjectActions, AdminRowActionsMixin, admin.ModelAdmin):
obj.verify()
verify_queryset.short_description = "Verifica differenze sui siti live"
actions = [verify_queryset, ]
def disable_objects(self, request, objects):
for obj in objects:
obj.is_verification_enabled = False
obj.save()
disable_objects.short_description = "Disabilita verifica"
def enable_objects(self, request, objects):
for obj in objects:
obj.is_verification_enabled = True
obj.save()
enable_objects.short_description = "Abilita verifica"
actions = [verify_queryset, disable_objects, enable_objects]
def get_row_actions(self, obj):
row_actions = [
......@@ -77,6 +88,12 @@ class ContentAdmin(DjangoObjectActions, AdminRowActionsMixin, admin.ModelAdmin):
'tooltip': 'Verifica il contenuto della fonte',
'enabled': True
},
{
'label': 'Abilita/Disabilita verifica',
'action': 'is_verification_enabled_switch',
'tooltip': 'Abilita o disabilita la verifica',
'enabled': True
},
{
'label': 'OP Aggiornato',
'action': 'update',
......@@ -96,6 +113,7 @@ class ContentAdmin(DjangoObjectActions, AdminRowActionsMixin, admin.ModelAdmin):
'tooltip': 'Svuota il contenuto, si riparte da zero',
'enabled': True
},
]
row_actions += super(ContentAdmin, self).get_row_actions(obj)
return row_actions
......
......@@ -77,6 +77,8 @@ class Command(LoggingBaseCommand):
else:
contents = Content.objects.filter(id__in=ids)
contents = contents.filter(is_verification_enabled=True)
if len(contents) == 0:
self.logger.info("no content to check this time")
......
# Generated by Django 2.2.1 on 2019-08-24 16:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('webapp', '0018_auto_20190703_1651'),
]
operations = [
migrations.AddField(
model_name='content',
name='is_verification_enabled',
field=models.BooleanField(default=True, help_text='Unset checkbox to disable verification', verbose_name='Enable verification'),
),
]
......@@ -82,9 +82,14 @@ class Content(models.Model):
blank=True, null=True,
verbose_name=_("Note")
)
is_verification_enabled = models.BooleanField(
default=True,
verbose_name=_("Verification enabled"),
help_text=_("Unset checkbox to disable verification")
)
verified_at = models.DateTimeField(
blank=True, null=True,
verbose_name=_("Timestamp")
verbose_name=_("Last verification")
)
verification_status = models.IntegerField(
null=True,
......@@ -107,7 +112,7 @@ class Content(models.Model):
def __str__(self):
return self.title
def get_live_content(self):
def get_live_content(self): # noqa:C901
"""
requests content from URI, using XPATH,
......@@ -123,7 +128,7 @@ class Content(models.Model):
timeout = config.REQUESTS_MAX_TIMEOUT
if config.REQUESTS_UA:
ua = config.REQUESTS_UA
except Exception as e:
except Exception as e: # noqa:F841
timeout = 10
if ua:
......@@ -240,6 +245,11 @@ class Content(models.Model):
self.verified_at = None
self.save()
def is_verification_enabled_switch(self):
"""change the status of the is_verification_enabled flag"""
self.is_verification_enabled = not self.is_verification_enabled
self.save()
def get_inhabitants(self):
"""
search number of inhabitants in api3.openpolis.it/locations
......
......@@ -21,8 +21,7 @@ slackclient==2.0.0
# App requirements
psycopg2-binary==2.8.3
# django-uwsgi-taskmanager
-e git+https://gitlab.depp.it/openpolis/op-task-manager-project.git@master#egg=django-uwsgi-taskmanager
django-uwsgi-taskmanager
django-uwsgi==0.2.2
file_read_backwards
......