Skip to content

Commit ecf9a0b

Browse files
committed
[qa] Switched to double quotes (black formatter)
1 parent 2cd66ed commit ecf9a0b

51 files changed

Lines changed: 1297 additions & 1297 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

openwisp_ipam/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
VERSION = (1, 2, 0, 'alpha')
1+
VERSION = (1, 2, 0, "alpha")
22
__version__ = VERSION # alias
33

44

55
def get_version():
6-
version = '%s.%s' % (VERSION[0], VERSION[1])
6+
version = "%s.%s" % (VERSION[0], VERSION[1])
77
if VERSION[2]:
8-
version = '%s.%s' % (version, VERSION[2])
9-
if VERSION[3:] == ('alpha', 0):
10-
version = '%s pre-alpha' % version
8+
version = "%s.%s" % (version, VERSION[2])
9+
if VERSION[3:] == ("alpha", 0):
10+
version = "%s pre-alpha" % version
1111
else:
12-
if VERSION[3] != 'final':
12+
if VERSION[3] != "final":
1313
try:
1414
rev = VERSION[4]
1515
except IndexError:
1616
rev = 0
17-
version = '%s%s%s' % (version, VERSION[3][0:1], rev)
17+
version = "%s%s%s" % (version, VERSION[3][0:1], rev)
1818
return version

openwisp_ipam/admin.py

Lines changed: 84 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from .base.models import CsvImportException
2525
from .filters import SubnetFilter, SubnetOrganizationFilter
2626

27-
Subnet = swapper.load_model('openwisp_ipam', 'Subnet')
28-
IpAddress = swapper.load_model('openwisp_ipam', 'IpAddress')
27+
Subnet = swapper.load_model("openwisp_ipam", "Subnet")
28+
IpAddress = swapper.load_model("openwisp_ipam", "IpAddress")
2929

3030

3131
@admin.register(Subnet)
@@ -36,24 +36,24 @@ class SubnetAdmin(
3636
ModelAdmin,
3737
AuthorizeCSVOrgManaged,
3838
):
39-
app_label = 'openwisp_ipam'
40-
change_form_template = 'admin/openwisp-ipam/subnet/change_form.html'
41-
change_list_template = 'admin/openwisp-ipam/subnet/change_list.html'
39+
app_label = "openwisp_ipam"
40+
change_form_template = "admin/openwisp-ipam/subnet/change_form.html"
41+
change_list_template = "admin/openwisp-ipam/subnet/change_list.html"
4242
list_display = [
43-
'name',
44-
'organization',
45-
'subnet',
46-
'master_subnet',
47-
'created',
48-
'modified',
43+
"name",
44+
"organization",
45+
"subnet",
46+
"master_subnet",
47+
"created",
48+
"modified",
4949
]
5050
list_filter = [MultitenantOrgFilter]
51-
autocomplete_fields = ['master_subnet']
52-
search_fields = ['subnet', 'name']
53-
list_select_related = ['organization', 'master_subnet']
51+
autocomplete_fields = ["master_subnet"]
52+
search_fields = ["subnet", "name"]
53+
list_select_related = ["organization", "master_subnet"]
5454
save_on_top = True
5555

56-
def change_view(self, request, object_id, form_url='', extra_context=None):
56+
def change_view(self, request, object_id, form_url="", extra_context=None):
5757
instance = self.get_object(request, object_id)
5858
if instance is None:
5959
# This is an internal Django method that redirects the
@@ -62,10 +62,10 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
6262
return self._get_obj_does_not_exist_redirect(
6363
request, self.model._meta, object_id
6464
)
65-
ipaddress_add_url = 'admin:{0}_ipaddress_add'.format(self.app_label)
66-
ipaddress_change_url = 'admin:{0}_ipaddress_change'.format(self.app_label)
67-
subnet_change_url = 'admin:{0}_subnet_change'.format(self.app_label)
68-
if request.GET.get('_popup'):
65+
ipaddress_add_url = "admin:{0}_ipaddress_add".format(self.app_label)
66+
ipaddress_change_url = "admin:{0}_ipaddress_change".format(self.app_label)
67+
subnet_change_url = "admin:{0}_subnet_change".format(self.app_label)
68+
if request.GET.get("_popup"):
6969
return super().change_view(request, object_id, form_url, extra_context)
7070
# Find root master_subnet for subnet tree
7171
instance_root = instance
@@ -74,16 +74,16 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
7474
# Get instances for all subnets for root master_subnet
7575
instance_subnets = Subnet.objects.filter(
7676
subnet=instance_root.subnet, organization=instance_root.organization
77-
).values('master_subnet', 'pk', 'name', 'subnet')
77+
).values("master_subnet", "pk", "name", "subnet")
7878
# Make subnet tree
7979
collection_depth = 0
8080
subnet_tree = [instance_subnets]
8181
while instance_subnets:
8282
instance_subnets = Subnet.objects.none()
8383
for slave_subnet in subnet_tree[collection_depth]:
8484
instance_subnets = instance_subnets | Subnet.objects.filter(
85-
master_subnet=slave_subnet['pk']
86-
).values('master_subnet', 'pk', 'name', 'subnet')
85+
master_subnet=slave_subnet["pk"]
86+
).values("master_subnet", "pk", "name", "subnet")
8787
subnet_tree.append(instance_subnets)
8888
collection_depth += 1
8989

@@ -92,37 +92,37 @@ def change_view(self, request, object_id, form_url='', extra_context=None):
9292
# Storing UUID corresponding to respective IP address in a dictionary
9393
ip_id_list = (
9494
IpAddress.objects.filter(subnet=instance)
95-
.annotate(str_id=Cast('id', output_field=TextField()))
96-
.values_list('ip_address', 'str_id')
95+
.annotate(str_id=Cast("id", output_field=TextField()))
96+
.values_list("ip_address", "str_id")
9797
)
9898

9999
# Converting UUIdField to String and then modifying to convert back to uuid form
100100
ip_id_list = OrderedDict(ip_id_list)
101101
ip_uuid = {}
102102
for ip_addr, Ip in ip_id_list.items():
103-
ip_uuid[ip_addr] = f'{Ip[0:8]}-{Ip[8:12]}-{Ip[12:16]}-{Ip[16:20]}-{Ip[20:]}'
103+
ip_uuid[ip_addr] = f"{Ip[0:8]}-{Ip[8:12]}-{Ip[12:16]}-{Ip[16:20]}-{Ip[20:]}"
104104
available = HostsSet(instance).count() - used
105-
labels = ['Used', 'Available']
105+
labels = ["Used", "Available"]
106106
values = [used, available]
107107
extra_context = {
108-
'labels': labels,
109-
'values': values,
110-
'original': instance,
111-
'ip_uuid': ip_uuid,
112-
'ipaddress_add_url': ipaddress_add_url,
113-
'ipaddress_change_url': ipaddress_change_url,
114-
'subnet_change_url': subnet_change_url,
115-
'subnet_tree': subnet_tree,
108+
"labels": labels,
109+
"values": values,
110+
"original": instance,
111+
"ip_uuid": ip_uuid,
112+
"ipaddress_add_url": ipaddress_add_url,
113+
"ipaddress_change_url": ipaddress_change_url,
114+
"subnet_change_url": subnet_change_url,
115+
"subnet_tree": subnet_tree,
116116
}
117117
return super().change_view(request, object_id, form_url, extra_context)
118118

119119
def _check_perm(self, view, perm):
120120
admin_site = self.admin_site
121121

122122
def inner(request, *args, **kwargs):
123-
if not request.user.has_perm(f'{self.app_label}.{perm}'):
123+
if not request.user.has_perm(f"{self.app_label}.{perm}"):
124124
return redirect(
125-
reverse('admin:index', current_app=admin_site.name),
125+
reverse("admin:index", current_app=admin_site.name),
126126
)
127127
return view(request, *args, **kwargs)
128128

@@ -132,82 +132,82 @@ def get_urls(self):
132132
urls = super().get_urls()
133133
custom_urls = [
134134
re_path(
135-
r'^(?P<subnet_id>[^/]+)/export-subnet/',
136-
self._check_perm(self.export_view, 'change_subnet'),
137-
name='ipam_export_subnet',
135+
r"^(?P<subnet_id>[^/]+)/export-subnet/",
136+
self._check_perm(self.export_view, "change_subnet"),
137+
name="ipam_export_subnet",
138138
),
139139
path(
140-
'import-subnet/',
141-
self._check_perm(self.import_view, 'add_subnet'),
142-
name='ipam_import_subnet',
140+
"import-subnet/",
141+
self._check_perm(self.import_view, "add_subnet"),
142+
name="ipam_import_subnet",
143143
),
144144
]
145145
return custom_urls + urls
146146

147147
def export_view(self, request, subnet_id):
148-
response = HttpResponse(content_type='text/csv')
149-
response['Content-Disposition'] = 'attachment; filename="ip_address.csv"'
148+
response = HttpResponse(content_type="text/csv")
149+
response["Content-Disposition"] = 'attachment; filename="ip_address.csv"'
150150
writer = csv.writer(response)
151151
Subnet().export_csv(subnet_id, writer)
152152
return response
153153

154154
def import_view(self, request):
155155
form = IpAddressImportForm()
156-
form_template = 'admin/openwisp-ipam/subnet/import.html'
157-
subnet_list_url = f'admin:{self.app_label}_{Subnet._meta.model_name}_changelist'
156+
form_template = "admin/openwisp-ipam/subnet/import.html"
157+
subnet_list_url = f"admin:{self.app_label}_{Subnet._meta.model_name}_changelist"
158158
context = {
159-
'form': form,
160-
'subnet_list_url': subnet_list_url,
161-
'has_permission': True,
159+
"form": form,
160+
"subnet_list_url": subnet_list_url,
161+
"has_permission": True,
162162
}
163-
if request.method == 'POST':
163+
if request.method == "POST":
164164
form = IpAddressImportForm(request.POST, request.FILES)
165-
context['form'] = form
165+
context["form"] = form
166166
if form.is_valid():
167-
file = request.FILES['csvfile']
167+
file = request.FILES["csvfile"]
168168
try:
169169
self.assert_organization_permissions(request)
170170
except (PermissionDenied, CsvImportAPIException) as e:
171171
messages.error(request, str(e))
172-
return redirect(reverse(context['subnet_list_url']))
173-
if not file.name.endswith(('.csv', '.xls', '.xlsx')):
174-
messages.error(request, _('File type not supported.'))
172+
return redirect(reverse(context["subnet_list_url"]))
173+
if not file.name.endswith((".csv", ".xls", ".xlsx")):
174+
messages.error(request, _("File type not supported."))
175175
return render(request, form_template, context)
176176
try:
177177
Subnet().import_csv(file)
178178
except CsvImportException as e:
179179
messages.error(request, str(e))
180180
return render(request, form_template, context)
181-
messages.success(request, _('Successfully imported data.'))
182-
return redirect(reverse(context['subnet_list_url']))
181+
messages.success(request, _("Successfully imported data."))
182+
return redirect(reverse(context["subnet_list_url"]))
183183
return render(request, form_template, context)
184184

185185
def get_csv_organization(self, request):
186-
data = Subnet._get_csv_reader(self, deepcopy(request.FILES['csvfile']))
186+
data = Subnet._get_csv_reader(self, deepcopy(request.FILES["csvfile"]))
187187
return Subnet._get_org(self, org_slug=list(data)[2][0].strip())
188188

189189
class Media:
190190
js = (
191-
'admin/js/jquery.init.js',
192-
'admin/js/SelectBox.js',
193-
'openwisp-ipam/js/subnet.js',
194-
'openwisp-ipam/js/minified/jstree.min.js',
195-
'openwisp-ipam/js/minified/plotly.min.js',
191+
"admin/js/jquery.init.js",
192+
"admin/js/SelectBox.js",
193+
"openwisp-ipam/js/subnet.js",
194+
"openwisp-ipam/js/minified/jstree.min.js",
195+
"openwisp-ipam/js/minified/plotly.min.js",
196196
)
197197
css = {
198-
'all': (
199-
'openwisp-ipam/css/admin.css',
200-
'openwisp-ipam/css/minified/jstree.min.css',
198+
"all": (
199+
"openwisp-ipam/css/admin.css",
200+
"openwisp-ipam/css/minified/jstree.min.css",
201201
)
202202
}
203203

204204

205205
class IpAddressAdminForm(forms.ModelForm):
206206
class Meta:
207207
help_texts = {
208-
'subnet': _(
209-
'Select a subnet and the first available IP address '
210-
'will be automatically suggested in the ip address field'
208+
"subnet": _(
209+
"Select a subnet and the first available IP address "
210+
"will be automatically suggested in the ip address field"
211211
)
212212
}
213213

@@ -217,34 +217,34 @@ class IpAddressAdmin(
217217
VersionAdmin, MultitenantAdminMixin, TimeReadonlyAdminMixin, ModelAdmin
218218
):
219219
form = IpAddressAdminForm
220-
change_form_template = 'admin/openwisp-ipam/ip_address/change_form.html'
221-
list_display = ['ip_address', 'subnet', 'organization', 'created', 'modified']
220+
change_form_template = "admin/openwisp-ipam/ip_address/change_form.html"
221+
list_display = ["ip_address", "subnet", "organization", "created", "modified"]
222222
list_filter = [SubnetOrganizationFilter, SubnetFilter]
223-
search_fields = ['ip_address']
224-
autocomplete_fields = ['subnet']
225-
multitenant_parent = 'subnet'
226-
list_select_related = ['subnet', 'subnet__organization']
223+
search_fields = ["ip_address"]
224+
autocomplete_fields = ["subnet"]
225+
multitenant_parent = "subnet"
226+
list_select_related = ["subnet", "subnet__organization"]
227227
save_on_top = True
228228

229229
class Media:
230230
js = (
231-
'admin/js/jquery.init.js',
232-
'openwisp-ipam/js/ip-request.js',
231+
"admin/js/jquery.init.js",
232+
"openwisp-ipam/js/ip-request.js",
233233
)
234234

235235
def organization(self, obj):
236236
return obj.subnet.organization
237237

238-
organization.short_description = _('organization')
238+
organization.short_description = _("organization")
239239

240240
def get_extra_context(self):
241-
url = reverse('ipam:get_next_available_ip', args=['0000'])
242-
return {'get_next_available_ip_url': url}
241+
url = reverse("ipam:get_next_available_ip", args=["0000"])
242+
return {"get_next_available_ip_url": url}
243243

244-
def add_view(self, request, form_url='', extra_context=None):
244+
def add_view(self, request, form_url="", extra_context=None):
245245
return super().add_view(request, form_url, self.get_extra_context())
246246

247-
def change_view(self, request, object_id, form_url='', extra_context=None):
247+
def change_view(self, request, object_id, form_url="", extra_context=None):
248248
return super().change_view(
249249
request, object_id, form_url, self.get_extra_context()
250250
)
@@ -254,7 +254,7 @@ def response_add(self, request, *args, **kwargs):
254254
Custom reponse to dismiss an add form popup for IP address.
255255
"""
256256
response = super().response_add(request, *args, **kwargs)
257-
if request.POST.get('_popup'):
257+
if request.POST.get("_popup"):
258258
return HttpResponse(
259259
f"""
260260
<script type='text/javascript'>
@@ -269,7 +269,7 @@ def response_change(self, request, *args, **kwargs):
269269
Custom reponse to dismiss a change form popup for IP address.
270270
"""
271271
response = super().response_change(request, *args, **kwargs)
272-
if request.POST.get('_popup'):
272+
if request.POST.get("_popup"):
273273
return HttpResponse(
274274
"""
275275
<script type='text/javascript'>

openwisp_ipam/api/serializers.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,29 @@
33
from rest_framework import serializers
44
from swapper import load_model
55

6-
IpAddress = load_model('openwisp_ipam', 'IpAddress')
7-
Subnet = load_model('openwisp_ipam', 'Subnet')
6+
IpAddress = load_model("openwisp_ipam", "IpAddress")
7+
Subnet = load_model("openwisp_ipam", "Subnet")
88

99

1010
class IpRequestSerializer(ValidatedModelSerializer):
1111
class Meta:
1212
model = IpAddress
13-
fields = ('subnet', 'description')
14-
read_only_fields = ('created', 'modified')
13+
fields = ("subnet", "description")
14+
read_only_fields = ("created", "modified")
1515

1616

1717
class IpAddressSerializer(FilterSerializerByOrgManaged, ValidatedModelSerializer):
1818
class Meta:
1919
model = IpAddress
20-
fields = '__all__'
21-
read_only_fields = ('created', 'modified')
20+
fields = "__all__"
21+
read_only_fields = ("created", "modified")
2222

2323

2424
class SubnetSerializer(FilterSerializerByOrgManaged, ValidatedModelSerializer):
2525
class Meta:
2626
model = Subnet
27-
fields = '__all__'
28-
read_only_fields = ('created', 'modified')
27+
fields = "__all__"
28+
read_only_fields = ("created", "modified")
2929

3030

3131
class ImportSubnetSerializer(serializers.Serializer):

0 commit comments

Comments
 (0)