summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrédéric Péters <fpeters@entrouvert.com>2019-04-18 09:18:17 (GMT)
committerFrédéric Péters <fpeters@entrouvert.com>2019-04-18 09:18:17 (GMT)
commitc281c34b7dbc5e22be41315fbb3c3bda4fcc366d (patch)
treef6507f3e15f72267cbab9f6e0b6e4c077a192f3b
parent93f2b20a2af5798d78d1f13e70a797f9d633ab01 (diff)
downloadpasserelle-grandlyon-cartads-cs-c281c34b7dbc5e22be41315fbb3c3bda4fcc366d.zip
passerelle-grandlyon-cartads-cs-c281c34b7dbc5e22be41315fbb3c3bda4fcc366d.tar.gz
passerelle-grandlyon-cartads-cs-c281c34b7dbc5e22be41315fbb3c3bda4fcc366d.tar.bz2
add support for custom zip upload webservice (#32141)
-rw-r--r--grandlyon_cartads_cs/migrations/0002_auto_20190418_1118.py25
-rw-r--r--grandlyon_cartads_cs/models.py21
2 files changed, 46 insertions, 0 deletions
diff --git a/grandlyon_cartads_cs/migrations/0002_auto_20190418_1118.py b/grandlyon_cartads_cs/migrations/0002_auto_20190418_1118.py
new file mode 100644
index 0000000..9de0772
--- /dev/null
+++ b/grandlyon_cartads_cs/migrations/0002_auto_20190418_1118.py
@@ -0,0 +1,25 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.11.12 on 2019-04-18 09:18
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('grandlyon_cartads_cs', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='glcartadscs',
+ name='sendfile_ws_dirname',
+ field=models.CharField(blank=True, max_length=256, verbose_name='Sendfile Webservice Directory Name'),
+ ),
+ migrations.AddField(
+ model_name='glcartadscs',
+ name='sendfile_ws_url',
+ field=models.URLField(blank=True, max_length=256, verbose_name='Sendfile Webservice URL'),
+ ),
+ ]
diff --git a/grandlyon_cartads_cs/models.py b/grandlyon_cartads_cs/models.py
index f513065..a029318 100644
--- a/grandlyon_cartads_cs/models.py
+++ b/grandlyon_cartads_cs/models.py
@@ -16,6 +16,9 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+import base64
+import os
+
from django.core.cache import cache
from django.db import models
from django.utils.translation import ugettext_lazy as _
@@ -40,6 +43,12 @@ class GLCartaDSCS(AbstractCartaDSCS):
token_url = models.URLField(_('Token URL'), max_length=256)
token_authorization = models.CharField(_('Token Authorization'), max_length=128)
+ sendfile_ws_url = models.URLField(
+ _('Sendfile Webservice URL'),
+ max_length=256, blank=True)
+ sendfile_ws_dirname = models.CharField(
+ _('Sendfile Webservice Directory Name'),
+ max_length=256, blank=True)
verify_cert = models.BooleanField(default=True,
verbose_name=_('Check HTTPS Certificate validity'))
@@ -68,3 +77,15 @@ class GLCartaDSCS(AbstractCartaDSCS):
cache.set(cache_key, token, timeout)
self.logger.debug('new token: %s (timeout %ss)', token, timeout)
return token
+
+ def upload_zip(self, zip_filename):
+ b64_zip = base64.b64encode(open(zip_filename).read())
+ chunk_size = 16777216 # 16MB
+ for n in range(0, len(b64_zip), chunk_size):
+ resp = self.requests.post(self.sendfile_ws_url,
+ data={
+ 'fileName': self.sendfile_ws_dirname + os.path.basename(zip_filename),
+ 'b64_fileContent': b64_zip[n:n+chunk_size],
+ }
+ )
+ resp.raise_for_status()