mirror of
https://github.com/ansible/awx.git
synced 2026-03-26 21:35:01 -02:30
Merge pull request #3900 from AlanCoding/fewer_type_methods
Remove duplicated type methods and old Django logic Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -97,12 +97,4 @@ class ActivityStream(models.Model):
|
||||
if 'update_fields' in kwargs and 'deleted_actor' not in kwargs['update_fields']:
|
||||
kwargs['update_fields'].append('deleted_actor')
|
||||
|
||||
# For compatibility with Django 1.4.x, attempt to handle any calls to
|
||||
# save that pass update_fields.
|
||||
try:
|
||||
super(ActivityStream, self).save(*args, **kwargs)
|
||||
except TypeError:
|
||||
if 'update_fields' not in kwargs:
|
||||
raise
|
||||
kwargs.pop('update_fields')
|
||||
super(ActivityStream, self).save(*args, **kwargs)
|
||||
super(ActivityStream, self).save(*args, **kwargs)
|
||||
|
||||
@@ -20,7 +20,6 @@ from django.core.exceptions import NON_FIELD_ERRORS
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from django.utils.timezone import now
|
||||
from django.utils.encoding import smart_text
|
||||
from django.apps import apps
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
|
||||
# REST Framework
|
||||
@@ -40,6 +39,7 @@ from awx.main.dispatch.control import Control as ControlDispatcher
|
||||
from awx.main.registrar import activity_stream_registrar
|
||||
from awx.main.models.mixins import ResourceMixin, TaskManagerUnifiedJobMixin
|
||||
from awx.main.utils import (
|
||||
camelcase_to_underscore, get_model_for_type,
|
||||
encrypt_dict, decrypt_field, _inventory_updates,
|
||||
copy_model_by_class, copy_m2m_relationships,
|
||||
get_type_for_model, parse_yaml_or_json, getattr_dne
|
||||
@@ -487,34 +487,15 @@ class UnifiedJobTemplate(PolymorphicModel, CommonModelNameNotUnique, Notificatio
|
||||
|
||||
|
||||
class UnifiedJobTypeStringMixin(object):
|
||||
@classmethod
|
||||
def _underscore_to_camel(cls, word):
|
||||
return ''.join(x.capitalize() or '_' for x in word.split('_'))
|
||||
|
||||
@classmethod
|
||||
def _camel_to_underscore(cls, word):
|
||||
return re.sub('(?!^)([A-Z]+)', r'_\1', word).lower()
|
||||
|
||||
@classmethod
|
||||
def _model_type(cls, job_type):
|
||||
# Django >= 1.9
|
||||
#app = apps.get_app_config('main')
|
||||
model_str = cls._underscore_to_camel(job_type)
|
||||
try:
|
||||
return apps.get_model('main', model_str)
|
||||
except LookupError:
|
||||
print("Lookup model error")
|
||||
return None
|
||||
|
||||
@classmethod
|
||||
def get_instance_by_type(cls, job_type, job_id):
|
||||
model = cls._model_type(job_type)
|
||||
model = get_model_for_type(job_type)
|
||||
if not model:
|
||||
return None
|
||||
return model.objects.get(id=job_id)
|
||||
|
||||
def model_to_str(self):
|
||||
return UnifiedJobTypeStringMixin._camel_to_underscore(self.__class__.__name__)
|
||||
return camelcase_to_underscore(self.__class__.__name__)
|
||||
|
||||
|
||||
class UnifiedJobDeprecatedStdout(models.Model):
|
||||
|
||||
Reference in New Issue
Block a user