Commits

Josh VanderLinden  committed d0f2ccf

Fixed a problem related to accessing Site.objects.get_current() in the models.py file. When Pendulum was installed on a site before a syncdb, the sites table didn't exist and syncdb wouldn't complete.

  • Participants
  • Parent commits 1bc0fbb

Comments (0)

Files changed (5)

+Copyright (c) 2008 Josh VanderLinden
+
+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.
+LICENSE
 README
 setup.py
 pendulum/__init__.py

File pendulum/models.py

 from datetime import datetime, date, timedelta
 from pendulum.utils import determine_period
 
+try:
+    """
+    if the app is installed from the start of a site, the sites table does
+    not exist and it causes problems.  This exception block seems to fix
+    the problem.
+    """
+    CURRENT_SITE = Site.objects.get_current()
+except:
+    CURRENT_SITE = Site.objects.all()
+
 class PendulumConfiguration(models.Model):
     """
     This will hold a single record that maintains the configuration of the
     Return all active projects.
     """
     def get_query_set(self):
-        return super(ProjectManager, self).get_query_set().filter(sites__exact=Site.objects.get_current())
+        return super(ProjectManager, self).get_query_set().filter(sites__exact=CURRENT_SITE)
 
     def active(self):
         return self.get_query_set().filter(is_active=True)
     Return all active activities.
     """
     def get_query_set(self):
-        return super(ActivityManager, self).get_query_set().filter(sites__exact=Site.objects.get_current())
+        return super(ActivityManager, self).get_query_set().filter(sites__exact=CURRENT_SITE)
 
 class Activity(models.Model):
     """
 
 class EntryManager(models.Manager):
     #def get_query_set(self):
-    #    return super(EntryManager, self).get_query_set().filter(site__exact=Site.objects.get_current())
+    #    return super(EntryManager, self).get_query_set().filter(site__exact=CURRENT_SITE)
 
     def current(self, user=None):
         """
     user = models.ForeignKey(User, related_name='pendulum_entries')
     project = models.ForeignKey(Project,
                                 limit_choices_to={'is_active': True,
-                                                  'sites': Site.objects.get_current()},
+                                                  'sites': CURRENT_SITE},
                                 related_name='entries')
     activity = models.ForeignKey(Activity, blank=True, null=True, related_name='entries')
     start_time = models.DateTimeField()
         if not self.is_closed:
             self.user = user
             self.project = project
-            self.site = Site.objects.get_current()
+            self.site = CURRENT_SITE
             self.start_time = datetime.now()
 
     def clock_out(self, activity, comments):

File pendulum/templates/pendulum/entry_list.html

     </tr>
     {% for entry in entries %}<tr class="{% cycle odd,even as rowclass %}">
         <td class="entry-date">
-            {% if entry.is_closed %}<a href="{% url pendulum-update entry.id %}" title="Update this entry">{% endif %}{{ entry.start_time|date:"d M Y" }}{% if entry.is_closed %}</a>{% endif %}
+            {% if entry.is_closed %}<a href="{% url pendulum-update entry.id %}" title="Update this entry">{% endif %}{{ entry.start_time|date:"j N Y" }}{% if entry.is_closed %}</a>{% endif %}
         </td>
         <td class="entry-start">{{ entry.start_time|date:"P" }}</td>
         <td class="entry-end">{% if entry.end_time %}
 
 setup(
     name='django-pendulum',
-    version='0.1.1',
+    version='0.1.2',
     url='http://code.google.com/p/django-pendulum/',
     author='Josh VanderLinden',
     author_email='codekoala@gmail.com',