|
1 | | -import json |
2 | 1 | import logging |
3 | 2 |
|
4 | | -import requests |
5 | | - |
6 | | -from django.conf import settings |
7 | 3 | from django.contrib.auth.models import Group |
8 | 4 | from django.core.exceptions import ValidationError |
9 | 5 | from django.db import models |
@@ -186,26 +182,6 @@ def aggregated_stats_query(self): |
186 | 182 | """, |
187 | 183 | ) |
188 | 184 |
|
189 | | - # Fields used by optional SYSTRAN services |
190 | | - systran_translate_code = models.CharField( |
191 | | - max_length=20, |
192 | | - blank=True, |
193 | | - help_text=""" |
194 | | - SYSTRAN maintains its own list of |
195 | | - <a href="https://platform.systran.net/index">supported locales</a>. |
196 | | - Choose a matching locale from the list or leave blank to disable |
197 | | - support for SYSTRAN machine translation service. |
198 | | - """, |
199 | | - ) |
200 | | - systran_translate_profile = models.CharField( |
201 | | - max_length=128, |
202 | | - blank=True, |
203 | | - help_text=""" |
204 | | - SYSTRAN Profile UUID to specify the engine trained on the en-locale language pair. |
205 | | - The field is updated automatically after the systran_translate_code field changes. |
206 | | - """, |
207 | | - ) |
208 | | - |
209 | 185 | db_collation = models.CharField( |
210 | 186 | max_length=20, |
211 | 187 | blank=True, |
@@ -336,7 +312,6 @@ def serialize(self): |
336 | 312 | "script": self.script, |
337 | 313 | "google_translate_code": self.google_translate_code, |
338 | 314 | "ms_translator_code": self.ms_translator_code, |
339 | | - "systran_translate_code": self.systran_translate_code, |
340 | 315 | "ms_terminology_code": self.ms_terminology_code, |
341 | 316 | } |
342 | 317 |
|
@@ -369,50 +344,3 @@ def get_latest_activity(self): |
369 | 344 | return ( |
370 | 345 | self.latest_translation.latest_activity if self.latest_translation else None |
371 | 346 | ) |
372 | | - |
373 | | - def save(self, *args, **kwargs): |
374 | | - old = Locale.objects.get(pk=self.pk) if self.pk else None |
375 | | - super().save(*args, **kwargs) |
376 | | - |
377 | | - # If SYSTRAN Translate code changes, update SYSTRAN Profile UUID. |
378 | | - if old is None or old.systran_translate_code == self.systran_translate_code: |
379 | | - return |
380 | | - |
381 | | - if not self.systran_translate_code: |
382 | | - return |
383 | | - |
384 | | - api_key = settings.SYSTRAN_TRANSLATE_API_KEY |
385 | | - server = settings.SYSTRAN_TRANSLATE_SERVER |
386 | | - profile_owner = settings.SYSTRAN_TRANSLATE_PROFILE_OWNER |
387 | | - if not (api_key or server or profile_owner): |
388 | | - return |
389 | | - |
390 | | - url = f"{server}/translation/supportedLanguages" |
391 | | - |
392 | | - payload = { |
393 | | - "key": api_key, |
394 | | - "source": "en", |
395 | | - "target": self.systran_translate_code, |
396 | | - } |
397 | | - |
398 | | - try: |
399 | | - r = requests.post(url, params=payload) |
400 | | - root = json.loads(r.content) |
401 | | - |
402 | | - if "error" in root: |
403 | | - log.error( |
404 | | - "Unable to retrieve SYSTRAN Profile UUID: {error}".format( |
405 | | - error=root |
406 | | - ) |
407 | | - ) |
408 | | - return |
409 | | - |
410 | | - for languagePair in root["languagePairs"]: |
411 | | - for profile in languagePair["profiles"]: |
412 | | - if profile["selectors"]["owner"] == profile_owner: |
413 | | - self.systran_translate_profile = profile["id"] |
414 | | - self.save(update_fields=["systran_translate_profile"]) |
415 | | - return |
416 | | - |
417 | | - except requests.exceptions.RequestException as e: |
418 | | - log.error(f"Unable to retrieve SYSTRAN Profile UUID: {e}") |
0 commit comments