Commits

Owen Nelson committed 34b36e6

initial checkin

Comments (0)

Files changed (8)

+^.project$
+^.pydevproject$
+^.settings/
+^build/
+^dist/
+^test_proj/local_settings.py$
+^test_proj/uploads
+.*\.db$
+.*\.pyc$
+.*\.egg-info$
+^docs/_build
+Copyright (c) 2011 Owen Nelson
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+include LICENSE
+include README
+

Empty file added.

ipyfield/__init__.py

+__version__ = '0.1'
+

ipyfield/models.py

+from django.db import models
+from IPy import IP
+
+class IPyField(models.Field):
+    """
+    Handles conversion between int db column and IPy.IP instance.
+    """
+    
+    __metaclass__ = models.SubfieldBase
+    def __init__(self, default=None, *args, **kwargs):
+        super(IPyField, self).__init__(default=default, *args, **kwargs)
+
+    def to_python(self, value):
+        if isinstance(value, IP) or value is None:
+            return value
+        else:
+            return IP(value)
+
+    def get_prep_value(self, value):
+        value = self.to_python(value)
+        if value == None:
+            return value
+        return value.int()
+
+    def get_internal_type(self):
+        return 'BigIntegerField'
+

ipyfield/tests.py

+from django.test import TestCase
+from django.db.models import Model
+from ipyfield.models import IPyField
+
+class IPyFieldTests(TestCase):
+
+    def setUp(self):
+        class Obj(Model):
+            '''Some kind of model'''
+            field = IPyField()
+
+        self.obj = Obj()
+
+    def test_something(self):
+        self.obj.field = '127.0.0.1'
+        self.obj.field.strNormal()
+
+from setuptools import setup, find_packages
+import sys, os
+
+sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
+
+import ipyfield
+
+setup(
+    name="django-ipyfield",
+    version=ipyfield.__version__,
+    url="https://bitbucket.org/onelson/django-ipyfield/",
+    author="Owen Nelson",
+    author_email="onelson@gmail.com",
+    license="MIT",
+    description="IPy.IP instances with BigInt storage for django models",
+    long_description=open('README').read(),
+    keywords="ip, models, django",
+    packages=find_packages(),
+    setup_requires=("setuptools"),
+    install_requires=("setuptools", "IPy", "django",),
+    classifiers=(
+        "Development Status :: 2 - Pre-Alpha",
+        "Environment :: Web Environment",
+        "Framework :: Django",
+        "Intended Audience :: Developers",
+        "License :: OSI Approved :: MIT License",
+        "Operating System :: OS Independent",
+        "Programming Language :: Python",
+        "Topic :: Internet :: WWW/HTTP",
+        "Topic :: Internet :: WWW/HTTP :: Dynamic Content",
+        "Topic :: Internet :: WWW/HTTP :: WSGI",
+        "Topic :: Software Development :: Libraries :: "
+                              "Application Frameworks",
+        "Topic :: Software Development :: Libraries :: Python Modules",),
+)
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.