mirror of
https://github.com/ansible/awx.git
synced 2026-03-17 17:07:33 -02:30
Fixing up some pep8 issues
This commit is contained in:
@@ -20,7 +20,7 @@ class TokenAuthentication(authentication.TokenAuthentication):
|
||||
|
||||
def _get_x_auth_token_header(self, request):
|
||||
auth = request.META.get('HTTP_X_AUTH_TOKEN', '')
|
||||
if type(auth) == type(''):
|
||||
if isinstance(auth, type('')):
|
||||
# Work around django test client oddness
|
||||
auth = auth.encode(HTTP_HEADER_ENCODING)
|
||||
return auth
|
||||
|
||||
@@ -176,7 +176,7 @@ class GenericAPIView(generics.GenericAPIView, APIView):
|
||||
# Override when called from browsable API to generate raw data form;
|
||||
# always remove read only fields from sample raw data.
|
||||
if hasattr(self, '_raw_data_form_marker'):
|
||||
for name, field in serializer.fields.items():
|
||||
for name, field in serializer.fields.items():
|
||||
if getattr(field, 'read_only', None):
|
||||
del serializer.fields[name]
|
||||
return serializer
|
||||
@@ -476,9 +476,9 @@ class RetrieveDestroyAPIView(RetrieveAPIView, generics.RetrieveDestroyAPIView):
|
||||
# somewhat lame that delete has to call it's own permissions check
|
||||
obj = self.get_object()
|
||||
# FIXME: Why isn't the active check being caught earlier by RBAC?
|
||||
if getattr(obj, 'active', True) == False:
|
||||
if not getattr(obj, 'active', True):
|
||||
raise Http404()
|
||||
if getattr(obj, 'is_active', True) == False:
|
||||
if not getattr(obj, 'is_active', True):
|
||||
raise Http404()
|
||||
if not request.user.can_access(self.model, 'delete', obj):
|
||||
raise PermissionDenied()
|
||||
|
||||
@@ -107,8 +107,7 @@ class ModelAccessPermission(permissions.BasePermission):
|
||||
|
||||
# Check permissions for the given view and object, based on the request
|
||||
# method used.
|
||||
check_method = getattr(self, 'check_%s_permissions' % \
|
||||
request.method.lower(), None)
|
||||
check_method = getattr(self, 'check_%s_permissions' % request.method.lower(), None)
|
||||
result = check_method and check_method(request, view, obj)
|
||||
if not result:
|
||||
raise PermissionDenied()
|
||||
|
||||
@@ -30,9 +30,9 @@ class BrowsableAPIRenderer(renderers.BrowsableAPIRenderer):
|
||||
'''Never show auto-generated form (only raw form).'''
|
||||
obj = getattr(view, 'object', None)
|
||||
if not self.show_form_for_method(view, method, request, obj):
|
||||
return
|
||||
return
|
||||
if method in ('DELETE', 'OPTIONS'):
|
||||
return True # Don't actually need to return a form
|
||||
return True # Don't actually need to return a form
|
||||
|
||||
def get_context(self, data, accepted_media_type, renderer_context):
|
||||
context = super(BrowsableAPIRenderer, self).get_context(data, accepted_media_type, renderer_context)
|
||||
|
||||
@@ -42,7 +42,7 @@ from awx.main.utils import update_scm_url, get_type_for_model, get_model_for_typ
|
||||
logger = logging.getLogger('awx.api.serializers')
|
||||
|
||||
# Fields that should be summarized regardless of object type.
|
||||
DEFAULT_SUMMARY_FIELDS = ('name', 'description')#, 'created_by', 'modified_by')#, 'type')
|
||||
DEFAULT_SUMMARY_FIELDS = ('name', 'description')# , 'created_by', 'modified_by')#, 'type')
|
||||
|
||||
# Keys are fields (foreign keys) where, if found on an instance, summary info
|
||||
# should be added to the serialized data. Values are a tuple of field names on
|
||||
@@ -93,7 +93,7 @@ class ChoiceField(fields.ChoiceField):
|
||||
# Remove extra blank option if one is already present (for writable
|
||||
# field) or if present at all for read-only fields.
|
||||
if ([x[0] for x in self.choices].count(u'') > 1 or self.read_only) \
|
||||
and BLANK_CHOICE_DASH[0] in self.choices:
|
||||
and BLANK_CHOICE_DASH[0] in self.choices:
|
||||
self.choices = [x for x in self.choices
|
||||
if x != BLANK_CHOICE_DASH[0]]
|
||||
|
||||
@@ -450,10 +450,10 @@ class UnifiedJobListSerializer(UnifiedJobSerializer):
|
||||
'result_stdout')
|
||||
|
||||
def get_types(self):
|
||||
if type(self) is UnifiedJobListSerializer:
|
||||
return ['project_update', 'inventory_update', 'job', 'system_job']
|
||||
else:
|
||||
return super(UnifiedJobListSerializer, self).get_types()
|
||||
if type(self) is UnifiedJobListSerializer:
|
||||
return ['project_update', 'inventory_update', 'job', 'system_job']
|
||||
else:
|
||||
return super(UnifiedJobListSerializer, self).get_types()
|
||||
|
||||
def to_native(self, obj):
|
||||
serializer_class = None
|
||||
@@ -495,7 +495,7 @@ class UnifiedJobStdoutSerializer(UnifiedJobSerializer):
|
||||
class UserSerializer(BaseSerializer):
|
||||
|
||||
password = serializers.WritableField(required=False, default='',
|
||||
help_text='Write-only field used to change the password.')
|
||||
help_text='Write-only field used to change the password.')
|
||||
ldap_dn = serializers.Field(source='profile.ldap_dn')
|
||||
|
||||
class Meta:
|
||||
@@ -805,8 +805,7 @@ class HostSerializer(BaseSerializerWithVariables):
|
||||
pass
|
||||
d.update({'recent_jobs': [{
|
||||
'id': j.job.id,
|
||||
'name': j.job.job_template.name if j.job.job_template is not None
|
||||
else "",
|
||||
'name': j.job.job_template.name if j.job.job_template is not None else "",
|
||||
'status': j.job.status,
|
||||
'finished': j.job.finished,
|
||||
} for j in obj.job_host_summaries.filter(job__active=True).select_related('job__job_template').order_by('-created')[:5]]})
|
||||
|
||||
@@ -23,6 +23,7 @@ class PaginatedDecoratorTests(TestCase):
|
||||
# that the paginator wraps in the way we expect.
|
||||
class View(APIView):
|
||||
permission_classes = (AllowAny,)
|
||||
|
||||
@paginated
|
||||
def get(self, request, limit, ordering, offset):
|
||||
return ['a', 'b', 'c', 'd', 'e'], 26, None
|
||||
|
||||
@@ -82,11 +82,11 @@ class ApiRootView(APIView):
|
||||
|
||||
current = reverse('api:api_v1_root_view', args=[])
|
||||
data = dict(
|
||||
description = 'Ansible Tower REST API',
|
||||
current_version = current,
|
||||
available_versions = dict(
|
||||
v1 = current
|
||||
)
|
||||
description = 'Ansible Tower REST API',
|
||||
current_version = current,
|
||||
available_versions = dict(
|
||||
v1 = current
|
||||
)
|
||||
)
|
||||
return Response(data)
|
||||
|
||||
@@ -335,7 +335,7 @@ class DashboardView(APIView):
|
||||
data['organizations'] = {'url': reverse('api:organization_list'),
|
||||
'total': organization_list.count()}
|
||||
data['teams'] = {'url': reverse('api:team_list'),
|
||||
'total': team_list.count()}
|
||||
'total': team_list.count()}
|
||||
data['credentials'] = {'url': reverse('api:credential_list'),
|
||||
'total': credential_list.count()}
|
||||
data['job_templates'] = {'url': reverse('api:job_template_list'),
|
||||
@@ -421,7 +421,7 @@ class DashboardInventoryGraphView(APIView):
|
||||
host_data = []
|
||||
for element in created_hosts.time_series(end_date, start_date, interval=interval)[::-1]:
|
||||
host_data.append([time.mktime(element[0].timetuple()),
|
||||
count_hosts - last_delta])
|
||||
count_hosts - last_delta])
|
||||
count_hosts -= last_delta
|
||||
last_delta = element[1]
|
||||
|
||||
@@ -1068,9 +1068,9 @@ class GroupHostsList(SubListCreateAPIView):
|
||||
def create(self, request, *args, **kwargs):
|
||||
parent_group = Group.objects.get(id=self.kwargs['pk'])
|
||||
existing_hosts = Host.objects.filter(inventory=parent_group.inventory, name=request.DATA['name'])
|
||||
if existing_hosts.count() > 0 and ('variables' not in request.DATA or \
|
||||
request.DATA['variables'] == '' or \
|
||||
request.DATA['variables'] == '{}' or \
|
||||
if existing_hosts.count() > 0 and ('variables' not in request.DATA or
|
||||
request.DATA['variables'] == '' or
|
||||
request.DATA['variables'] == '{}' or
|
||||
request.DATA['variables'] == '---'):
|
||||
request.DATA['id'] = existing_hosts[0].id
|
||||
return self.attach(request, *args, **kwargs)
|
||||
@@ -1121,9 +1121,9 @@ class GroupDetail(RetrieveUpdateDestroyAPIView):
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
obj = self.get_object()
|
||||
# FIXME: Why isn't the active check being caught earlier by RBAC?
|
||||
if getattr(obj, 'active', True) == False:
|
||||
if not getattr(obj, 'active', True):
|
||||
raise Http404()
|
||||
if getattr(obj, 'is_active', True) == False:
|
||||
if not getattr(obj, 'is_active', True):
|
||||
raise Http404()
|
||||
if not request.user.can_access(self.model, 'delete', obj):
|
||||
raise PermissionDenied()
|
||||
@@ -1178,8 +1178,7 @@ class InventoryScriptView(RetrieveAPIView):
|
||||
|
||||
model = Inventory
|
||||
serializer_class = InventoryScriptSerializer
|
||||
authentication_classes = [JobTaskAuthentication] + \
|
||||
api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||
authentication_classes = [JobTaskAuthentication] + api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||
permission_classes = (JobTaskPermission,)
|
||||
filter_backends = ()
|
||||
|
||||
@@ -1319,9 +1318,9 @@ class InventoryInventorySourcesList(SubListAPIView):
|
||||
|
||||
class InventorySourceList(ListAPIView):
|
||||
|
||||
model = InventorySource
|
||||
serializer_class = InventorySourceSerializer
|
||||
new_in_14 = True
|
||||
model = InventorySource
|
||||
serializer_class = InventorySourceSerializer
|
||||
new_in_14 = True
|
||||
|
||||
class InventorySourceDetail(RetrieveUpdateAPIView):
|
||||
|
||||
@@ -1950,8 +1949,7 @@ class GroupJobEventsList(BaseJobEventsList):
|
||||
class JobJobEventsList(BaseJobEventsList):
|
||||
|
||||
parent_model = Job
|
||||
authentication_classes = [JobTaskAuthentication] + \
|
||||
api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||
authentication_classes = [JobTaskAuthentication] + api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||
permission_classes = (JobTaskPermission,)
|
||||
|
||||
# Post allowed for job event callback only.
|
||||
@@ -1973,8 +1971,7 @@ class JobJobPlaysList(BaseJobEventsList):
|
||||
|
||||
parent_model = Job
|
||||
view_name = 'Job Plays List'
|
||||
authentication_classes = [JobTaskAuthentication] + \
|
||||
api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||
authentication_classes = [JobTaskAuthentication] + api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||
permission_classes = (JobTaskPermission,)
|
||||
new_in_200 = True
|
||||
|
||||
@@ -2028,7 +2025,7 @@ class JobJobPlaysList(BaseJobEventsList):
|
||||
elif event_aggregate['event'] == 'runner_on_unreachable':
|
||||
unreachable_count = event_aggregate['id__count']
|
||||
for change_aggregate in change_aggregates:
|
||||
if change_aggregate['changed'] == False:
|
||||
if not change_aggregate['changed']:
|
||||
ok_count = change_aggregate['id__count']
|
||||
else:
|
||||
changed_count = change_aggregate['id__count']
|
||||
@@ -2050,8 +2047,7 @@ class JobJobTasksList(BaseJobEventsList):
|
||||
and their completion status.
|
||||
"""
|
||||
parent_model = Job
|
||||
authentication_classes = [JobTaskAuthentication] + \
|
||||
api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||
authentication_classes = [JobTaskAuthentication] + api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
||||
permission_classes = (JobTaskPermission,)
|
||||
view_name = 'Job Play Tasks List'
|
||||
new_in_200 = True
|
||||
@@ -2141,9 +2137,7 @@ class JobJobTasksList(BaseJobEventsList):
|
||||
'host_count': 0,
|
||||
'id': task_start_event.id,
|
||||
'modified': task_start_event.modified,
|
||||
'name': 'Gathering Facts' if
|
||||
task_start_event.event == 'playbook_on_setup' else
|
||||
task_start_event.task,
|
||||
'name': 'Gathering Facts' if task_start_event.event == 'playbook_on_setup' else task_start_event.task,
|
||||
'reported_hosts': 0,
|
||||
'skipped_count': 0,
|
||||
'unreachable_count': 0,
|
||||
|
||||
Reference in New Issue
Block a user