Commit d4025da8 authored by guglielmo's avatar guglielmo

timeout added to Content model

parent 63ae5f92
......@@ -19,11 +19,11 @@ class ContentAdmin(DjangoObjectActions, AdminRowActionsMixin, admin.ModelAdmin):
list_display = ('_linked_title',
'verified_at',
'_status_and_message')
search_fields = ('title', 'notes')
search_fields = ('title', 'notes', 'verification_error', 'verification_status', 'url')
list_filter = ('verification_status', 'organisation_type')
fieldsets = (
(None, {
'fields': ('title', 'organisation_type', 'notes', 'op_url', 'url', 'xpath', 'use_cleaner',
'fields': ('title', 'organisation_type', 'timeout', 'notes', 'op_url', 'url', 'xpath', 'use_cleaner',
'content'),
}),
('Verification', {
......
# Generated by Django 2.2.1 on 2019-06-11 15:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('webapp', '0014_auto_20190507_1349'),
]
operations = [
migrations.AlterField(
model_name='content',
name='title',
field=models.CharField(help_text="Indicare l'istituzione (es. Cons. Reg. Lazio)", max_length=512, verbose_name='Denominazione della fonte'),
),
migrations.AlterField(
model_name='content',
name='xpath',
field=models.CharField(blank=True, max_length=512),
),
]
# Generated by Django 2.2.1 on 2019-06-11 15:16
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('webapp', '0015_auto_20190611_1710'),
]
operations = [
migrations.AlterField(
model_name='content',
name='verification_error',
field=models.CharField(blank=True, max_length=1024, null=True, verbose_name='Errore'),
),
]
# Generated by Django 2.2.1 on 2019-06-17 09:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('webapp', '0016_auto_20190611_1716'),
]
operations = [
migrations.AddField(
model_name='content',
name='timeout',
field=models.PositiveSmallIntegerField(default=10),
),
]
......@@ -55,7 +55,7 @@ class Content(models.Model):
)
title = models.CharField(
max_length=250,
max_length=512,
verbose_name=_("Denominazione della fonte"),
help_text="""Indicare l'istituzione (es. Cons. Reg. Lazio)"""
)
......@@ -69,11 +69,14 @@ class Content(models.Model):
blank=True, null=True,
help_text="URL della pagina OP contenente le istituzioni"
)
xpath = models.CharField(blank=True, max_length=250)
xpath = models.CharField(blank=True, max_length=512)
content = models.TextField(
blank=True, null=True,
verbose_name=_("Contenuto significativo")
)
timeout = models.PositiveSmallIntegerField(
default=config.REQUESTS_MAX_TIMEOUT
)
notes = models.TextField(
blank=True, null=True,
verbose_name=_("Note")
......@@ -88,7 +91,7 @@ class Content(models.Model):
verbose_name=_("Stato")
)
verification_error = models.CharField(
blank=True, null=True, max_length=250,
blank=True, null=True, max_length=1024,
verbose_name=_("Errore")
)
use_cleaner = models.BooleanField(
......@@ -118,7 +121,7 @@ class Content(models.Model):
headers['User-Agent'] = config.REQUESTS_UA
try:
res = requests.get(self.url, timeout=config.REQUESTS_MAX_TIMEOUT, headers=headers)
res = requests.get(self.url, timeout=self.timeout, headers=headers)
if not res.ok:
if res.status_code and res.reason:
return res.status_code, res.reason
......@@ -126,7 +129,7 @@ class Content(models.Model):
return 990, "Generic error"
except SSLError:
try:
res = requests.get(self.url, timeout=config.REQUESTS_MAX_TIMEOUT, headers=headers, verify=False)
res = requests.get(self.url, timeout=self.timeout, headers=headers, verify=False)
except Exception as e:
return 990, e
except ConnectionError as e:
......
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