| 1 |
Metadata-Version: 2.4 |
| 2 |
Name: django-macaddress |
| 3 |
Version: 1.9.0 |
| 4 |
Summary: MAC address model and form fields for Django apps. |
| 5 |
Home-page: http://github.com/tubaman/django-macaddress |
| 6 |
Author: Ryan Nowakowski |
| 7 |
Author-email: [email protected] |
| 8 |
Maintainer: Arun Karunagath |
| 9 |
Maintainer-email: [email protected] |
| 10 |
License: BSD |
| 11 |
Classifier: Development Status :: 5 - Production/Stable |
| 12 |
Classifier: Framework :: Django |
| 13 |
Classifier: Intended Audience :: Developers |
| 14 |
Classifier: License :: OSI Approved :: BSD License |
| 15 |
Classifier: Operating System :: OS Independent |
| 16 |
Classifier: Programming Language :: Python |
| 17 |
Classifier: Programming Language :: Python :: 3 |
| 18 |
Classifier: Programming Language :: Python :: 3 :: Only |
| 19 |
Classifier: Programming Language :: Python :: 3.9 |
| 20 |
Classifier: Programming Language :: Python :: 3.10 |
| 21 |
Classifier: Programming Language :: Python :: 3.11 |
| 22 |
Classifier: Programming Language :: Python :: 3.12 |
| 23 |
Classifier: Programming Language :: Python :: 3.13 |
| 24 |
Classifier: Topic :: Internet :: WWW/HTTP |
| 25 |
License-File: LICENSE |
| 26 |
Requires-Dist: netaddr |
| 27 |
Dynamic: author |
| 28 |
Dynamic: author-email |
| 29 |
Dynamic: classifier |
| 30 |
Dynamic: description |
| 31 |
Dynamic: home-page |
| 32 |
Dynamic: license |
| 33 |
Dynamic: license-file |
| 34 |
Dynamic: maintainer |
| 35 |
Dynamic: maintainer-email |
| 36 |
Dynamic: requires-dist |
| 37 |
Dynamic: summary |
| 38 |
|
| 39 |
django-macaddress |
| 40 |
================== |
| 41 |
|
| 42 |
.. image:: https://travis-ci.org/django-macaddress/django-macaddress.svg?branch=master |
| 43 |
:alt: Build Status |
| 44 |
:target: https://travis-ci.org/django-macaddress/django-macaddress |
| 45 |
.. image:: https://img.shields.io/pypi/v/django-macaddress.svg |
| 46 |
:target: https://crate.io/packages/django-macaddress |
| 47 |
|
| 48 |
MAC Address model and form fields for Django |
| 49 |
|
| 50 |
We use netaddr to parse and validate the MAC address. The tests aren't |
| 51 |
complete yet. |
| 52 |
|
| 53 |
Patches welcome: http://github.com/django-macaddress/django-macaddress |
| 54 |
|
| 55 |
Release Notes: |
| 56 |
************** |
| 57 |
|
| 58 |
For release info: https://github.com/django-macaddress/django-macaddress/releases |
| 59 |
|
| 60 |
|
| 61 |
Getting Started |
| 62 |
*************** |
| 63 |
|
| 64 |
settings.MACADDRESS_DEFAULT_DIALECT |
| 65 |
----------------------------------- |
| 66 |
To specify a default dialect for presentation (and storage, see below), specify:: |
| 67 |
|
| 68 |
settings.MACADDRESS_DEFAULT_DIALECT = 'module.dialect_class' |
| 69 |
|
| 70 |
where the specified value is a string composed of a parent python module name |
| 71 |
and the child dialect class name. For example:: |
| 72 |
|
| 73 |
settings.MACADDRESS_DEFAULT_DIALECT = 'netaddr.mac_eui48' |
| 74 |
|
| 75 |
PS: old default of macaddress.mac_linux (uppercase and divided by ':' ) will be used by default. |
| 76 |
|
| 77 |
If the custom dialect is defined in a package module, you will need to define the |
| 78 |
class in or import into the package's ``__init__.py``. |
| 79 |
|
| 80 |
``default_dialect`` and ``format_mac`` |
| 81 |
-------------------------------------- |
| 82 |
To get the default dialect for your project, import and call the ``default_dialect`` function:: |
| 83 |
|
| 84 |
>>> from macaddress import default_dialect |
| 85 |
|
| 86 |
>>> dialect = default_dialect() |
| 87 |
|
| 88 |
This function may, optionally, be called with an ``netaddr.EUI`` class instance as its argument. If no |
| 89 |
default is defined in ``settings``, it will return the dialect of the provided ``EUI`` object. |
| 90 |
|
| 91 |
The ``format_mac`` function takes an ``EUI`` instance and a dialect class (``netaddr.mac_eui48`` or a |
| 92 |
subclass) as its arguments. The dialect class may be specified as a string in the same manner as |
| 93 |
``settings.MACADDRESS_DEFAULT_DIALECT``:: |
| 94 |
|
| 95 |
>>> from netaddr import EUI, mac_bare |
| 96 |
>>> from macaddress import format_mac |
| 97 |
|
| 98 |
>>> mac = EUI('00:12:3c:37:64:8f') |
| 99 |
>>> format_mac(mac, mac_bare) |
| 100 |
'00123C37648F' |
| 101 |
>>> format_mac(mac, 'netaddr.mac_cisco') |
| 102 |
'0012.3c37.648f' |
| 103 |
|
| 104 |
MACAddressField (ModelField) |
| 105 |
---------------------------- |
| 106 |
This is an example model using MACAddressField:: |
| 107 |
|
| 108 |
from macaddress.fields import MACAddressField |
| 109 |
|
| 110 |
class Computer(models.Model): |
| 111 |
name = models.CharField(max_length=32) |
| 112 |
eth0 = MACAddressField(null=True, blank=True) |
| 113 |
... |
| 114 |
|
| 115 |
The default behavior is to store the MAC Address in the database is a BigInteger. |
| 116 |
If you would, rather, store the value as a string (to, for instance, facilitate |
| 117 |
sub-string searches), you can specify ``integer=False`` and the value will be stored |
| 118 |
as a string:: |
| 119 |
|
| 120 |
class Computer(models.Model): |
| 121 |
name = models.CharField(max_length=32) |
| 122 |
eth0 = MACAddressField(blank=True, integer=False) |
| 123 |
... |
| 124 |
|
| 125 |
If you want to set ``unique=True`` on a MACAddressField that is stored as a string, you will need |
| 126 |
to set ``null=True`` and create custom ``clean_<foo>`` methods on your ``forms.ModelForm`` class for |
| 127 |
each MACAddressField that return ``None`` when the value provided is an ``''`` (empty string):: |
| 128 |
|
| 129 |
from .models import Computer |
| 130 |
|
| 131 |
class ComputerForm(forms.ModelForm): |
| 132 |
class Meta: |
| 133 |
model = Computer |
| 134 |
|
| 135 |
def clean_eth0(self): |
| 136 |
return self.cleaned_data['eth0'] or None |
| 137 |
|
| 138 |
You should avoid changing the value of ``integer`` after running ``managy.py syncdb``, |
| 139 |
unless you are using a schema migration solution like South or Django's built-in migrations. |
| 140 |
|
| 141 |
|
| 142 |
To Do |
| 143 |
***** |
| 144 |
|
| 145 |
+ Add greater support for partial string queries when storing MACs as strings in the database. |
| 146 |
+ Add custom validator to check for duplicate MACs when mixing string and integer storage types. |
| 147 |
+ Add deprecation warning and timeline for changeover to default string storage. |