# Path: pendulum/models.py
# class PendulumConfiguration(models.Model):
#     """
#     This will hold a single record that maintains the configuration of the
#     application.  In the admin interface, if the configuration is marked as
#     "Is Monthly", that will take precedence over the "Install date" option (even
#     if the install_date and period_length fields have values).  If you wish to
#     use the fixed-length (install_date + period_length) setup, uncheck the
#     is_monthly field.
#     """
# 
#     # tie the configuration to one site in particular
#     site = models.OneToOneField(Site, help_text="""Please choose the site that these settings will apply to.""")
# 
#     """
#     this represents whether the application will look for all entries in a
#     month-long period
#     """
#     is_monthly = models.BooleanField(default=True, help_text="""If you check this box, you will be forced to use the monthly mode.  Uncheck it to use fixed-length period""")
# 
#     """
#     this is used in conjunction with the monthly setup; end date is assumed
#     to be month_start - 1.  For example, if the periods begin on the 16th of
#     each month, the end date would be assumed to be the 15th of each month
#     """
#     month_start = models.PositiveIntegerField(default=1, blank=True, null=True,
#                                               help_text="""Enter 1 for periods that begin on the 1st day of each month and end on the last day of each month.  Alternatively, enter any other number (between 2 and 31) for the day of the month that periods start.  For example, enter 16 for periods that begin on the 16th of each month and end on the 15th of the following month.""")
# 
#     """
#     install_date represents the date the software was installed and began
#     being used.  period_length represents the number of days in a period.  Week-
#     long periods would have a period_length of 7.  Two week-long periods would
#     be 14 days.  You get the idea.  These should be able to handle _most_
#     situations (maybe not all).
#     """
#     install_date = models.DateField(blank=True, null=True, help_text="""The date that Pendulum was installed.  Does not necessarily have to be the date, just a date to be used as a reference point for adding the number of days from period length below.  For example, if you have periods with a fixed length of 2 weeks, enter 14 days for period length and choose any Sunday to be the install date.""")
#     period_length = models.PositiveIntegerField(blank=True, null=True, help_text="""The number of days in the fixed-length period.  For example, enter 7 days for 1-week periods or 28 for 4-week long periods.""")
# 
#     def __unicode__(self):
#         return u'Pendulum Configuration for %s' % self.site
# 
#     def __current_mode(self):
#         if self.is_monthly:
#             return u'Month-long'
#         else:
#             return u'Fixed-length'
#     current_mode = property(__current_mode)


from django.contrib.auth.views import login
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.conf import settings
from pendulum.models import PendulumConfiguration

SITE = Site.objects.get_current()
admin_url = reverse('admin_pendulum_pendulumconfiguration_add')
login_url = getattr(settings, 'LOGIN_URL', '/accounts/login/')

class PendulumMiddleware:
    """
    This middleware ensures that anyone trying to access Pendulum must be
    logged in.  If Pendulum hasn't been configured for the current site, the
    staff users will be redirected to the page to configure it.
    """
    def process_request(self, request):
        try:
            SITE.pendulumconfiguration

# Path: pendulum/models.py
# class PendulumConfiguration(models.Model):
#     """
#     This will hold a single record that maintains the configuration of the
#     application.  In the admin interface, if the configuration is marked as
#     "Is Monthly", that will take precedence over the "Install date" option (even
#     if the install_date and period_length fields have values).  If you wish to
#     use the fixed-length (install_date + period_length) setup, uncheck the
#     is_monthly field.
#     """
# 
#     # tie the configuration to one site in particular
#     site = models.OneToOneField(Site, help_text="""Please choose the site that these settings will apply to.""")
# 
#     """
#     this represents whether the application will look for all entries in a
#     month-long period
#     """
#     is_monthly = models.BooleanField(default=True, help_text="""If you check this box, you will be forced to use the monthly mode.  Uncheck it to use fixed-length period""")
# 
#     """
#     this is used in conjunction with the monthly setup; end date is assumed
#     to be month_start - 1.  For example, if the periods begin on the 16th of
#     each month, the end date would be assumed to be the 15th of each month
#     """
#     month_start = models.PositiveIntegerField(default=1, blank=True, null=True,
#                                               help_text="""Enter 1 for periods that begin on the 1st day of each month and end on the last day of each month.  Alternatively, enter any other number (between 2 and 31) for the day of the month that periods start.  For example, enter 16 for periods that begin on the 16th of each month and end on the 15th of the following month.""")
# 
#     """
#     install_date represents the date the software was installed and began
#     being used.  period_length represents the number of days in a period.  Week-
#     long periods would have a period_length of 7.  Two week-long periods would
#     be 14 days.  You get the idea.  These should be able to handle _most_
#     situations (maybe not all).
#     """
#     install_date = models.DateField(blank=True, null=True, help_text="""The date that Pendulum was installed.  Does not necessarily have to be the date, just a date to be used as a reference point for adding the number of days from period length below.  For example, if you have periods with a fixed length of 2 weeks, enter 14 days for period length and choose any Sunday to be the install date.""")
#     period_length = models.PositiveIntegerField(blank=True, null=True, help_text="""The number of days in the fixed-length period.  For example, enter 7 days for 1-week periods or 28 for 4-week long periods.""")
# 
#     def __unicode__(self):
#         return u'Pendulum Configuration for %s' % self.site
# 
#     def __current_mode(self):
#         if self.is_monthly:
#             return u'Month-long'
#         else:
#             return u'Fixed-length'
#     current_mode = property(__current_mode)


# Path: pendulum/middleware.py
from django.contrib.auth.views import login
from django.contrib.sites.models import Site
from django.core.urlresolvers import reverse
from django.http import HttpResponseRedirect
from django.conf import settings
from pendulum.models import PendulumConfiguration


SITE = Site.objects.get_current()
admin_url = reverse('admin_pendulum_pendulumconfiguration_add')
login_url = getattr(settings, 'LOGIN_URL', '/accounts/login/')

class PendulumMiddleware:
    """
    This middleware ensures that anyone trying to access Pendulum must be
    logged in.  If Pendulum hasn't been configured for the current site, the
    staff users will be redirected to the page to configure it.
    """
    def process_request(self, request):
        try:
            SITE.pendulumconfiguration

        except PendulumConfiguration.DoesNotExist: