# Path: breezeminder/models/reminder.py
# class ReminderType(BaseDocument):
#     key = app.db.StringField(required=True)
#     name = app.db.StringField(required=True)
#     description = app.db.StringField()
#     order = app.db.IntField(required=True, default=0)
# 
#     meta = {
#         'collection': 'reminder_types',
#         'queryset_class': ReminderTypeQuerySet,
#         'ordering': ['+order'],
#         'indexes': [
#             {
#                 'fields': ['key'],
#                 'unique': True
#             }
#         ]
#     }
# 
#     def __str__(self):
#         return self.key
# 
#     def __eq__(self, obj):
#         if isinstance(obj, basestring):
#             return self.key == obj
#         else:
#             return self == obj
# 
# Path: breezeminder/forms/validators.py
# class ActiveStateOptional(Optional, ActiveStateValidator):
#     """ Allows disabling """
#     
#     def __call__(self, form, field):
#         if not self.active:
#             return
# 
#         super(ActiveStateOptional, self).__call__(form, field)
# 
# class Conditional(ActiveStateValidator):
#     """
#     Conditionally apply a validator if the value of another field if
#     that field's value matches the one we're looking for. Specify the
#     form field name as a string and the value that should invoke a passed
#     list of validators. The validators kwarg could be either a list or single
#     validator.
# 
#     There's also an expectation that conditional validators will completely
#     override any optional validator.
#     """
#     active = True
# 
#     def __init__(self, field, value, validators=[], not_equals=False):
#         self.field = field
#         self.value = value
#         self.not_equals = not_equals
#         if not isinstance(validators, list):
#             validators = [validators]
#         self.validators = validators
# 
#     def __call__(self, form, field):
#         if not self.active:
#             return
# 
#         field_data = getattr(form, self.field).data.strip()
# 
#         # Don't invoke validators if 
#         # 1) We want non-equal values and the values are equal
#         # 2) We want equal values and the values are not equal
#         if (self.not_equals and field_data == self.value) or \
#                 ((not self.not_equals) and field_data != self.value):
#             return
# 
#         for validator in self.validators:
#             validator(form, field)
# 
# class PositiveNumber(ActiveStateValidator):
#     """ Checks that a value is positive. Expects an integer or float field """
#     def __init__(self, message=None):
#         if message is None:
#             message = 'This value must be greater than 0'
#         self.message = message
# 
#     def __call__(self, form, field):
#         if not self.active:
#             return
# 
#         try:
#             if int(field.data) < 0:
#                 raise ValidationError(self.message)
#         except:
#             raise ValidationError(self.message)
# 
# Path: breezeminder/forms/fields.py
# class BootstrapSelectMultipleField(fields.SelectMultipleField):
#     """
#     A specific implementation of `wtforms.fields.SelectMultipleField` that
#     uses a `breezeminder.forms.widgets.BootstrapButtonWidget` as its
#     widget implementation.
#     """
# 
#     widget = widgets.BootstrapButtonWidget(multiple=True)
# 
#     def __init__(self, *args, **kwargs):
#         if 'btn_class' in kwargs:
#             self.widget.btn_class = kwargs.pop('btn_class')
#         super(BootstrapSelectMultipleField, self).__init__(*args, **kwargs)


from datetime import datetime
from wtforms import (Form,
                     IntegerField,
                     DecimalField,
                     FormField,
                     SelectField)
from wtforms.validators import Required, Optional
from werkzeug.datastructures import MultiDict
from breezeminder.models.reminder import ReminderType
from breezeminder.forms.validators import (ActiveStateOptional,
                                           Conditional,
                                           PositiveNumber)
from breezeminder.forms.fields import BootstrapSelectMultipleField



def _create_tuple_range(start, stop):
    return [(int(x), str(x)) for x in xrange(start, stop)]


DATE_QUANTIFIERS = ['Days', 'Weeks', 'Months']
DATE_RANGE_CHOICES = [(x, x) for x in DATE_QUANTIFIERS]
DATE_THRESHOLD_CHOICES = _create_tuple_range(1, 11)

# For Date Selects, allow empties
MONTH_CHOICES = [(-1, 'Month')]
DAY_CHOICES = [(-1, 'Day')]
YEAR_CHOICES = [(-1, 'Year')]

# Extend all valid ranges
MONTH_CHOICES.extend(_create_tuple_range(1, 13))
DAY_CHOICES.extend(_create_tuple_range(1, 32))
YEAR_CHOICES.extend(_create_tuple_range(datetime.now().year,
                                        datetime.now().year + 10))


# Path: breezeminder/models/reminder.py
# class ReminderType(BaseDocument):
#     key = app.db.StringField(required=True)
#     name = app.db.StringField(required=True)
#     description = app.db.StringField()
#     order = app.db.IntField(required=True, default=0)
# 
#     meta = {
#         'collection': 'reminder_types',
#         'queryset_class': ReminderTypeQuerySet,
#         'ordering': ['+order'],
#         'indexes': [
#             {
#                 'fields': ['key'],
#                 'unique': True
#             }
#         ]
#     }
# 
#     def __str__(self):
#         return self.key
# 
#     def __eq__(self, obj):
#         if isinstance(obj, basestring):
#             return self.key == obj
#         else:
#             return self == obj
# 
# Path: breezeminder/forms/validators.py
# class ActiveStateOptional(Optional, ActiveStateValidator):
#     """ Allows disabling """
#     
#     def __call__(self, form, field):
#         if not self.active:
#             return
# 
#         super(ActiveStateOptional, self).__call__(form, field)
# 
# class Conditional(ActiveStateValidator):
#     """
#     Conditionally apply a validator if the value of another field if
#     that field's value matches the one we're looking for. Specify the
#     form field name as a string and the value that should invoke a passed
#     list of validators. The validators kwarg could be either a list or single
#     validator.
# 
#     There's also an expectation that conditional validators will completely
#     override any optional validator.
#     """
#     active = True
# 
#     def __init__(self, field, value, validators=[], not_equals=False):
#         self.field = field
#         self.value = value
#         self.not_equals = not_equals
#         if not isinstance(validators, list):
#             validators = [validators]
#         self.validators = validators
# 
#     def __call__(self, form, field):
#         if not self.active:
#             return
# 
#         field_data = getattr(form, self.field).data.strip()
# 
#         # Don't invoke validators if 
#         # 1) We want non-equal values and the values are equal
#         # 2) We want equal values and the values are not equal
#         if (self.not_equals and field_data == self.value) or \
#                 ((not self.not_equals) and field_data != self.value):
#             return
# 
#         for validator in self.validators:
#             validator(form, field)
# 
# class PositiveNumber(ActiveStateValidator):
#     """ Checks that a value is positive. Expects an integer or float field """
#     def __init__(self, message=None):
#         if message is None:
#             message = 'This value must be greater than 0'
#         self.message = message
# 
#     def __call__(self, form, field):
#         if not self.active:
#             return
# 
#         try:
#             if int(field.data) < 0:
#                 raise ValidationError(self.message)
#         except:
#             raise ValidationError(self.message)
# 
# Path: breezeminder/forms/fields.py
# class BootstrapSelectMultipleField(fields.SelectMultipleField):
#     """
#     A specific implementation of `wtforms.fields.SelectMultipleField` that
#     uses a `breezeminder.forms.widgets.BootstrapButtonWidget` as its
#     widget implementation.
#     """
# 
#     widget = widgets.BootstrapButtonWidget(multiple=True)
# 
#     def __init__(self, *args, **kwargs):
#         if 'btn_class' in kwargs:
#             self.widget.btn_class = kwargs.pop('btn_class')
#         super(BootstrapSelectMultipleField, self).__init__(*args, **kwargs)


# Path: breezeminder/forms/reminder.py
from datetime import datetime
from wtforms import (Form,
                     IntegerField,
                     DecimalField,
                     FormField,
                     SelectField)
from wtforms.validators import Required, Optional
from werkzeug.datastructures import MultiDict
from breezeminder.models.reminder import ReminderType
from breezeminder.forms.validators import (ActiveStateOptional,
                                           Conditional,
                                           PositiveNumber)
from breezeminder.forms.fields import BootstrapSelectMultipleField




def _create_tuple_range(start, stop):
    return [(int(x), str(x)) for x in xrange(start, stop)]


DATE_QUANTIFIERS = ['Days', 'Weeks', 'Months']
DATE_RANGE_CHOICES = [(x, x) for x in DATE_QUANTIFIERS]
DATE_THRESHOLD_CHOICES = _create_tuple_range(1, 11)

# For Date Selects, allow empties
MONTH_CHOICES = [(-1, 'Month')]
DAY_CHOICES = [(-1, 'Day')]
YEAR_CHOICES = [(-1, 'Year')]

# Extend all valid ranges
MONTH_CHOICES.extend(_create_tuple_range(1, 13))
DAY_CHOICES.extend(_create_tuple_range(1, 32))
YEAR_CHOICES.extend(_create_tuple_range(datetime.now().year,
                                        datetime.now().year + 10))


REMINDER_TYPES = ReminderType.objects.all_tuples()