Skip to content

Commit

Permalink
Basic Support for Python 3 (netbox-community#827)
Browse files Browse the repository at this point in the history
* Rudimentary python3 support

* update docs and trigger Travis

* fix some of the tests

* fix all python3 errors

* change env calls to just python

* add @python_2_unicode_compatible decorator to models for python2 compatibility

* switch netbox.configuration to from netbox import configuration
  • Loading branch information
BeryJu authored and jeremystretch committed Jan 23, 2017
1 parent 97b6ba5 commit 52b5c0f
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,5 +1,6 @@
*.pyc
/netbox/netbox/configuration.py
/netbox/netbox/ldap_config.py
/netbox/static
.idea
/*.sh
Expand Down
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -9,6 +9,9 @@ env:
language: python
python:
- "2.7"
- "3.4"
- "3.5"
- "3.6"
install:
- pip install -r requirements.txt
- pip install pep8
Expand Down
4 changes: 2 additions & 2 deletions docs/installation/netbox.md
Expand Up @@ -3,14 +3,14 @@
**Debian/Ubuntu**

```no-highlight
# apt-get install -y python2.7 python-dev python-pip libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev
# apt-get install -y python3 python3-dev python3-pip libxml2-dev libxslt1-dev libffi-dev graphviz libpq-dev libssl-dev
```

**CentOS/RHEL**

```no-highlight
# yum install -y epel-release
# yum install -y gcc python2 python-devel python-pip libxml2-devel libxslt-devel libffi-devel graphviz openssl-devel
# yum install -y gcc python3 python3-devel python3-pip libxml2-devel libxslt-devel libffi-devel graphviz openssl-devel
```

You may opt to install NetBox either from a numbered release or by cloning the master branch of its repository on GitHub.
Expand Down
13 changes: 9 additions & 4 deletions netbox/circuits/models.py
@@ -1,6 +1,7 @@
from django.contrib.contenttypes.fields import GenericRelation
from django.core.urlresolvers import reverse
from django.db import models
from django.utils.encoding import python_2_unicode_compatible

from dcim.fields import ASNField
from extras.models import CustomFieldModel, CustomFieldValue
Expand Down Expand Up @@ -33,6 +34,7 @@ def humanize_speed(speed):
return '{} Kbps'.format(speed)


@python_2_unicode_compatible
class Provider(CreatedUpdatedModel, CustomFieldModel):
"""
Each Circuit belongs to a Provider. This is usually a telecommunications company or similar organization. This model
Expand All @@ -51,7 +53,7 @@ class Provider(CreatedUpdatedModel, CustomFieldModel):
class Meta:
ordering = ['name']

def __unicode__(self):
def __str__(self):
return self.name

def get_absolute_url(self):
Expand All @@ -67,6 +69,7 @@ def to_csv(self):
])


@python_2_unicode_compatible
class CircuitType(models.Model):
"""
Circuits can be organized by their functional role. For example, a user might wish to define CircuitTypes named
Expand All @@ -78,13 +81,14 @@ class CircuitType(models.Model):
class Meta:
ordering = ['name']

def __unicode__(self):
def __str__(self):
return self.name

def get_absolute_url(self):
return "{}?type={}".format(reverse('circuits:circuit_list'), self.slug)


@python_2_unicode_compatible
class Circuit(CreatedUpdatedModel, CustomFieldModel):
"""
A communications circuit connects two points. Each Circuit belongs to a Provider; Providers may have multiple
Expand All @@ -105,7 +109,7 @@ class Meta:
ordering = ['provider', 'cid']
unique_together = ['provider', 'cid']

def __unicode__(self):
def __str__(self):
return u'{} {}'.format(self.provider, self.cid)

def get_absolute_url(self):
Expand Down Expand Up @@ -141,6 +145,7 @@ def commit_rate_human(self):
commit_rate_human.admin_order_field = 'commit_rate'


@python_2_unicode_compatible
class CircuitTermination(models.Model):
circuit = models.ForeignKey('Circuit', related_name='terminations', on_delete=models.CASCADE)
term_side = models.CharField(max_length=1, choices=TERM_SIDE_CHOICES, verbose_name='Termination')
Expand All @@ -156,7 +161,7 @@ class Meta:
ordering = ['circuit', 'term_side']
unique_together = ['circuit', 'term_side']

def __unicode__(self):
def __str__(self):
return u'{} (Side {})'.format(self.circuit, self.get_term_side_display())

def get_peer_termination(self):
Expand Down
2 changes: 1 addition & 1 deletion netbox/dcim/forms.py
Expand Up @@ -13,7 +13,7 @@
SlugField,
)

from formfields import MACAddressFormField
from .formfields import MACAddressFormField
from .models import (
DeviceBay, DeviceBayTemplate, CONNECTION_STATUS_CHOICES, CONNECTION_STATUS_PLANNED, CONNECTION_STATUS_CONNECTED,
ConsolePort, ConsolePortTemplate, ConsoleServerPort, ConsoleServerPortTemplate, Device, DeviceRole, DeviceType,
Expand Down

0 comments on commit 52b5c0f

Please sign in to comment.