Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Django 2.2 #3873

Draft
wants to merge 17 commits into
base: ng
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 5 additions & 4 deletions contrib/dhcp_agent/dhcp_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,21 @@
import subprocess
import sys
import tempfile
from optparse import OptionParser
from logging import handlers as logging_handlers
from optparse import OptionParser

IS_PY3 = sys.version_info[0] == 3
if IS_PY3:
from dbm import gnu as cache_db
from urllib.request import urlopen, Request
from urllib.parse import urlencode
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.request import Request, urlopen
string_types = (str,)
else:
import dbm as cache_db
from urllib import urlencode
from urllib2 import urlopen, Request, HTTPError

from urllib2 import HTTPError, Request, urlopen
string_types = (basestring,)


Expand Down
8 changes: 4 additions & 4 deletions contrib/dhcp_agent/test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import unittest
import logging
from mock import patch, MagicMock, Mock
import unittest
from optparse import Values

from dhcp_agent import (
Cache,
DHCPConfigManager,
_check_params,
_get_cmd_params_from_parser,
Cache,
DHCPConfigManager
)
from mock import MagicMock, Mock, patch

logger = logging.getLogger(__file__)
mocked_parser = MagicMock()
Expand Down
1 change: 0 additions & 1 deletion docker/provision/createsuperuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

from django.contrib.auth import get_user_model


User = get_user_model()

username = os.getenv('RALPH_DEFAULT_SUPERUSER_NAME', 'ralph')
Expand Down
12 changes: 6 additions & 6 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
-r openstack.txt
-r hermes.txt
Django==2.1.15
Django==2.2.28
Faker==0.9.0
Markdown<3.0 # headerid extension removed in 3.0 - see #3313 for details
Markdown==3.0
Pillow==6.2.2
Unidecode==0.04.18
dj.choices==0.11.0
Expand All @@ -18,16 +18,16 @@ django-sitetree==1.13.0
django-taggit-serializer==0.1.7
django-taggit==0.22.2
django-threadlocals==0.8
djangorestframework==3.8.2
djangorestframework_xml==1.2.0
drf-nested-routers==0.11.1
djangorestframework==3.13.1
djangorestframework_xml==2.0.0
drf-nested-routers==0.92.5
factory-boy==2.11.1
mysqlclient==1.3.13
netaddr==0.7.18
openpyxl==2.4.0
py-moneyed==1.2
python-dateutil==2.4.2
pytz==2015.4
pytz==2024.2
redis==3.2.1
requests-oauthlib==1.3.0
requests==2.20.0
Expand Down
4 changes: 2 additions & 2 deletions requirements/code_style.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
flake8==3.0.4
flake8==3.7.9
isort==4.2.5
pyflakes==1.5.0
pyflakes==2.1.0
2 changes: 1 addition & 1 deletion requirements/prod_ldap.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-r prod.txt
django-auth-ldap==1.6.1
django-auth-ldap==2.1.0
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# -*- encoding: utf-8 -*-

import os
import sys
from setuptools import setup, find_packages
import subprocess
import sys

from setuptools import find_packages, setup

assert sys.version_info >= (3, 3), 'Python 3.3+ required.'

Expand Down
4 changes: 2 additions & 2 deletions src/ralph/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
from django.db.models.options import Options

__version__ = '3.0.0'
__version__ = "3.0.0"


def monkey_options_init(self, meta, app_label):
self._old__init__(meta, app_label)
self.default_permissions = ('add', 'change', 'delete', 'view')
self.default_permissions = ("add", "change", "delete", "view")


Options._old__init__ = Options.__init__
Expand Down
16 changes: 8 additions & 8 deletions src/ralph/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@
import sys


def main(settings_module='ralph.settings', force=False):
def main(settings_module="ralph.settings", force=False):
if force:
os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
os.environ["DJANGO_SETTINGS_MODULE"] = settings_module
else:
os.environ.setdefault('DJANGO_SETTINGS_MODULE', settings_module)
os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings_module)

from django.core.management import execute_from_command_line

execute_from_command_line(sys.argv)


def dev():
main('ralph.settings.dev')
main("ralph.settings.dev")


def test():
# test only with test settings, not local (or any set by environment
# variable DJANGO_SETTINGS_MODULE)
main('ralph.settings.test', force=True)
main("ralph.settings.test", force=True)


def prod():
main('ralph.settings.prod')
main("ralph.settings.prod")


if __name__ == '__main__':
main('ralph.settings.prod')
if __name__ == "__main__":
main("ralph.settings.prod")
94 changes: 53 additions & 41 deletions src/ralph/access_cards/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,81 @@
@register(AccessCard)
class AccessCardAdmin(TransitionAdminMixin, RalphAdmin):
show_transition_history = True
list_display = ['status', 'visual_number', 'system_number', 'user',
'owner', 'get_employee_id', 'get_employee_company']
list_select_related = ['user', 'owner']
raw_id_fields = ['user', 'owner', 'region']
list_filter = ['status', 'issue_date', 'visual_number',
'system_number', 'user', 'owner', 'user__segment',
'user__company', 'user__department', 'user__employee_id',
'access_zones', 'notes']
search_fields = ['visual_number', 'system_number', 'user__first_name',
'user__last_name', 'user__username']
readonly_fields = ['get_employee_id', 'get_employee_company']
list_display = [
"status",
"visual_number",
"system_number",
"user",
"owner",
"get_employee_id",
"get_employee_company",
]
list_select_related = ["user", "owner"]
raw_id_fields = ["user", "owner", "region"]
list_filter = [
"status",
"issue_date",
"visual_number",
"system_number",
"user",
"owner",
"user__segment",
"user__company",
"user__department",
"user__employee_id",
"access_zones",
"notes",
]
search_fields = [
"visual_number",
"system_number",
"user__first_name",
"user__last_name",
"user__username",
]
readonly_fields = ["get_employee_id", "get_employee_company"]

fieldsets = (
(
_('Access Card Info'),
_("Access Card Info"),
{
'fields': ('visual_number', 'system_number',
'status', 'region', 'issue_date', 'notes')
}
"fields": (
"visual_number",
"system_number",
"status",
"region",
"issue_date",
"notes",
)
},
),
(
_('User Info'),
{
'fields': ('user', 'owner', 'get_employee_id',
'get_employee_company')
}
_("User Info"),
{"fields": ("user", "owner", "get_employee_id", "get_employee_company")},
),
(
_('Access Zones'),
{
'fields': ('access_zones',)
}
),

(_("Access Zones"), {"fields": ("access_zones",)}),
)

def get_employee_id(self, obj):
if obj.user is not None:
return obj.user.employee_id
else:
return '-'
return "-"

get_employee_id.short_description = _('Employee ID')
get_employee_id.short_description = _("Employee ID")

def get_employee_company(self, obj):
if obj.user is not None:
return obj.user.company
else:
return '-'
return "-"

get_employee_company.short_description = _('Employee Company')
get_employee_company.short_description = _("Employee Company")


@register(AccessZone)
class AccessZoneAdmin(RalphMPTTAdmin):
list_display = ['name', 'parent', 'description']
search_fields = ['name', 'description']
list_display = ["name", "parent", "description"]
search_fields = ["name", "description"]

fieldsets = (
(
_('Access Zone'),
{
'fields': ('parent', 'name', 'description')
}
),
)
fieldsets = ((_("Access Zone"), {"fields": ("parent", "name", "description")}),)
33 changes: 22 additions & 11 deletions src/ralph/access_cards/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AccessZoneSimpleSerializer(RalphAPISerializer):
class Meta:
model = AccessZone
depth = 0
fields = ['id', 'name', 'parent', 'description']
fields = ["id", "name", "parent", "description"]


class AccessZoneSerializer(RalphAPISerializer):
Expand All @@ -25,19 +25,30 @@ class AccessCardSerializer(RalphAPISerializer):

class Meta:
model = AccessCard
fields = ['id', 'status', 'user', 'owner', 'created', 'modified',
'visual_number', 'system_number', 'issue_date', 'notes',
'region', 'access_zones']
fields = [
"id",
"status",
"user",
"owner",
"created",
"modified",
"visual_number",
"system_number",
"issue_date",
"notes",
"region",
"access_zones",
]


class AccessCardViewSet(RalphAPIViewSet):
queryset = AccessCard.objects.order_by('id').all()
select_related = ['user', 'owner', 'region']
queryset = AccessCard.objects.order_by("id").all()
select_related = ["user", "owner", "region"]
serializer_class = AccessCardSerializer
prefetch_related = ['access_zones']
prefetch_related = ["access_zones"]
extended_filter_fields = {
'access_zones__name': ['access_zones__name__icontains'],
'access_zones__id': ['access_zones__id']
"access_zones__name": ["access_zones__name__icontains"],
"access_zones__id": ["access_zones__id"],
}


Expand All @@ -46,6 +57,6 @@ class AccessZoneViewSet(RalphAPIViewSet):
serializer_class = AccessZoneSerializer


router.register(r'access-card', AccessCardViewSet)
router.register(r'access-zone', AccessZoneViewSet)
router.register(r"access-card", AccessCardViewSet)
router.register(r"access-zone", AccessZoneViewSet)
urlpatterns = []
Loading
Loading