Commits

Matthew Schinckel committed 00a9004

Initial import

  • Participants

Comments (0)

Files changed (5)

+from distutils.core import setup
+
+setup(
+    name = "django-weekday-field",
+    version = "0.1",
+    description = "Weekday field for django models",
+    url = "http://bitbucket.org/schinckel/django-weekday-field/",
+    author = "Matthew Schinckel",
+    author_email = "matt@schinckel.net",
+    packages = [
+        "weekday_field",
+    ],
+    classifiers = [
+        'Programming Language :: Python',
+        'License :: OSI Approved :: BSD License',
+        'Operating System :: OS Independent',
+        'Framework :: Django',
+    ],
+)

File weekday_field/__init__.py

Empty file added.

File weekday_field/fields.py

+from django.db import models
+
+from forms import WeekdayFormField
+
+class WeekdayField(models.CommaSeparatedIntegerField):
+
+    __metaclass__ = models.SubfieldBase
+    
+    description = "CSV Weekday Field"
+    
+    def __init__(self, *args, **kwargs):
+        kwargs['max_length'] = 14
+        super(WeekdayField, self).__init__(*args, **kwargs)
+    
+    def formfield(self, **kwargs):
+        return super(WeekdayField, self).formfield(form_class=WeekdayFormField, **kwargs)
+    
+try:
+    from south.modelsinspector import add_introspection_rules
+    add_introspection_rules([], ['^weekday_fields\.fields\.WeekdayField'])
+except ImportError:
+    pass

File weekday_field/forms.py

+from django import forms
+
+import utils
+
+class WeekdayFormField(forms.TypedMultipleChoiceField):
+    def __init__(self, *args, **kwargs):
+        kwargs['choices'] = utils.DAY_CHOICES
+        super(WeekdayFormField, self).__init__(*args, **kwargs)

File weekday_field/utils.py

+DAY_CHOICES = (
+    (0, "Monday"),
+    (1, "Tuesday"),
+    (2, "Wednesday"),
+    (3, "Thursday"),
+    (4, "Friday"),
+    (5, "Saturday"),
+    (6, "Sunday")
+)
+