data_source_plugin: add DataSource.allow_redirects field to forbid redirection following when downloading the data source

This commit is contained in:
Benjamin Dauvergne 2014-01-27 11:16:06 +01:00
parent 8706d685c9
commit 904aa53b85
3 changed files with 81 additions and 1 deletions

View File

@ -57,7 +57,8 @@ class Data(object):
'Accept': self.data_source.mime_type,
}
request = requests.get(self.final_url, headers=headers,
verify=self.data_source.verify_certificate)
verify=self.data_source.verify_certificate,
allow_redirects=self.data_source.allow_redirects)
request.raise_for_status()
except HTTPError:
logger.warning('HTTP Error %s when loading datasource %s from'

View File

@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'DataSource.allow_redirects'
db.add_column(u'data_source_plugin_datasource', 'allow_redirects',
self.gf('django.db.models.fields.BooleanField')(default=True),
keep_default=False)
def backwards(self, orm):
# Deleting field 'DataSource.allow_redirects'
db.delete_column(u'data_source_plugin_datasource', 'allow_redirects')
models = {
'cms.cmsplugin': {
'Meta': {'object_name': 'CMSPlugin'},
'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}),
'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}),
'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}),
'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}),
'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}),
'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})
},
'cms.placeholder': {
'Meta': {'object_name': 'Placeholder'},
'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'})
},
u'data_source_plugin.datasource': {
'Meta': {'ordering': "('name',)", 'object_name': 'DataSource'},
'allow_redirects': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'hash_algo': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '16', 'blank': 'True'}),
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'mime_type': ('django.db.models.fields.CharField', [], {'max_length': '256'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '32'}),
'signature_key': ('django.db.models.fields.CharField', [], {'default': "''", 'max_length': '128', 'blank': 'True'}),
'url': ('django.db.models.fields.URLField', [], {'max_length': '1024'}),
'verify_certificate': ('django.db.models.fields.BooleanField', [], {'default': 'True'})
},
u'data_source_plugin.datasourceplugin': {
'Meta': {'object_name': 'DataSourcePlugin', 'db_table': "u'cmsplugin_datasourceplugin'"},
u'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
'limit': ('django.db.models.fields.IntegerField', [], {'default': '10'}),
'refresh': ('django.db.models.fields.IntegerField', [], {'default': '60'}),
'template_source': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'})
},
u'data_source_plugin.plugindatasource': {
'Meta': {'ordering': "('order', 'id')", 'object_name': 'PluginDataSource'},
u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'order': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'plugin': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'sources'", 'to': u"orm['data_source_plugin.DataSourcePlugin']"}),
'source': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'plugins'", 'to': u"orm['data_source_plugin.DataSource']"})
},
u'data_source_plugin.rawinlinetemplateplugin': {
'Meta': {'object_name': 'RawInlineTemplatePlugin', 'db_table': "u'cmsplugin_rawinlinetemplateplugin'"},
u'cmsplugin_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': "orm['cms.CMSPlugin']", 'unique': 'True', 'primary_key': 'True'}),
'template_source': ('django.db.models.fields.TextField', [], {'default': "''", 'blank': 'True'})
}
}
complete_apps = ['data_source_plugin']

View File

@ -45,6 +45,9 @@ class DataSource(models.Model):
max_length=128, default='', blank=True)
verify_certificate = models.BooleanField(verbose_name=_('verify '
'certificate'), default=True, blank=True)
allow_redirects = models.BooleanField(verbose_name=_('allows HTTP redirections'),
help_text=_('it can improve latencies to forbid redirection follow'),
default=True)
def clean(self):
if self.signature_key and not self.hash_algo: