Josh VanderLinden avatar Josh VanderLinden committed 9bbb7e6

Added a command for creating a user group

Comments (0)

Files changed (7)

+README
+setup.py
+pendulum/__init__.py
+pendulum/admin.py
+pendulum/forms.py
+pendulum/middleware.py
+pendulum/models.py
+pendulum/tests.py
+pendulum/urls.py
+pendulum/utils.py
+pendulum/views.py
+pendulum/management/__init__.py
+pendulum/management/commands/__init__.py
+pendulum/management/commands/create_pendulum_group.py
+pendulum/templates/pendulum/add_update_entry.html
+pendulum/templates/pendulum/clock_in.html
+pendulum/templates/pendulum/clock_out.html
+pendulum/templates/pendulum/delete_entry.html
+pendulum/templates/pendulum/entry_list.html
+pendulum/templates/pendulum/pendulum_base.html
+include README pendulum/templates/pendulum/add_update_entry.html pendulum/templates/pendulum/clock_in.html pendulum/templates/pendulum/clock_out.html pendulum/templates/pendulum/delete_entry.html pendulum/templates/pendulum/entry_list.html pendulum/templates/pendulum/pendulum_base.html
+recursive-include pendulum/*
+This application will allow users of Django-powered websites keep track of the time they spend on different projects.  It's a work in process.
+
+==Features==
+
+  * Configurable: Pendulum can be configured to operate on several Django-powered sites.  The period lengths can be configured as monthly or as a fixed-length period.
+  * Projects: You can have an unlimited number of projects to be able to categorize hours spent working on certain tasks.  Each project can be activated/deactivated as necessary via the Django admin.
+  * Activities: Activities allow you to further categorize work done on particular tasks for each project.
+
+==Requirements==
+
+`django-pendulum` requires a modern version of the Django framework.  By modern I simply mean a version with the `newforms-admin` functionality.  If you're running on Django 1.0 or later, you're good.
+
+`django-pendulum` also relies upon the `django.contrib.auth` and `django.contrib.sites` frameworks.
+
+==Installation==
+
+Download `django-pendulum` using *one* of the following methods:
+
+===Checkout from Subversion===
+
+{{{
+svn co http://django-pendulum.googlecode.com/svn/trunk/pendulum pendulum
+}}}
+
+===Package Download===
+
+Download the latest `.tar.gz` file from the downloads section and extract it somewhere you'll remember.  Use `python setup.py install` to install it.
+
+==Configuration==
+
+First of all, you must add this project to your list of `INSTALLED_APPS` in `settings.py`:
+
+{{{
+INSTALLED_APPS = (
+    'django.contrib.admin',
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    ...
+    'pendulum',
+    ...
+)
+}}}
+
+Run `manage.py syncdb`.  This creates a few tables in your database that are necessary for operation.
+
+Next, you should add an entry to your main `urls.py` file.  For example:
+
+{{{
+from django.conf.urls.defaults import *
+
+from django.contrib import admin
+admin.autodiscover()
+
+urlpatterns = patterns('',
+    (r'^admin/(.*)', admin.site.root),
+    (r'^pendulum/', include('pendulum.urls')),
+)
+}}}
+
+The next thing you will want to do is configure Pendulum for the active Django sites.  Do this by going into the Django admin and clicking the "add" link next to Pendulum Configurations.
+
+The first step in the configuration is to choose which site this particular configuration will apply to.  The decision is easy if you only have one site :)
+
+Next, you must choose what kind of "accounting period" you wish to use.  If you want month-long periods, ensure the "Is monthly" check box is selected.  Then enter the day of the month that the periods begin.  Periods that begin on the first of the month will always range from midnight on the first of each month to 11:59:59 PM on the last day of each month.  Periods that begin on the 16th of the month will range from midnight on the 16th of each month to 11:59:59 PM on the 15th of the following month.  Be wise about choosing start days such as the 31st of the month--it's not a wise choice no matter what situation you're in.
+
+Alternatively, you may choose fixed-length accounting periods.  The installation date does not necessarily have to be the actual installation date.  This field is used as a reference point for creating periods.  For example, if you have 2-week long accounting periods that begin on Sundays and end two Saturdays later, you would select _any_ Sunday from any month from any year.  Then you would enter 14 for the period length.  Periods will automatically be constructed that will begin at midnight each Sunday and end at 11:59:59 PM two Saturdays in the future.
+
+If you fail to configure Pendulum for a given site, you will likely receive HTTP 500 errors if you try to access Pendulum via the front-end.
+
+===Add Projects===
+
+Next, you should add at least one project to Pendulum.  This can easily be accomplished via the Django admin.  The same goes for activities, but these are not required.
+
+===Permissions===
+
+Finally, be sure set people up with the appropriate permissions using Django's Auth framework.  The front end side of Pendulum respects these permissions.  That means that if a user doesn't have the permission to clock in, the will be presented with a login screen (even if they're logged in already) when they try to clock in on the front end site.
+
+An easy way to assign the same Pendulum permissions to several users is to create a Group using the Auth framework.  There is a custom command for creating a group with all of the permissions necessary for the front end, including the ability to:
+
+  * add entries
+  * update entries
+  * delete entries
+  * clock in
+  * clock out
+  * pause/unpause entries
+
+To use this command, simply run `./manage.py create_pendulum_group`.  You may run `./manage.py help create_pendulum_group` to learn about options for this command.
Add a comment to this file

pendulum/management/__init__.py

Empty file added.

Add a comment to this file

pendulum/management/commands/__init__.py

Empty file added.

pendulum/management/commands/create_pendulum_group.py

+from django.core.management.base import BaseCommand
+from optparse import make_option
+
+class Command(BaseCommand):
+    option_list = BaseCommand.option_list + (
+        make_option('--name',
+                    default='Pendulum',
+                    dest='name',
+                    help='Specifies the name for the Pendulum user group.'),
+        make_option('--reset',
+                    default=False,
+                    dest='reset',
+                    help='Use this to revert the Pendulum user group to have all permission.'),
+    )
+    help = """Creates a default Pendulum user group with all permissions for entries,
+including the ability to:
+
+    - add entries
+    - update entries
+    - delete entries
+    - clock in
+    - clock out
+    - pause/unpause entries"""
+    args = '[--name="Pendulum Group"] [--reset=True]'
+
+    def handle(self, **options):
+        # grab some values from the parameter list
+        reset = options.get('reset', False)
+        name = options.get('name', 'Pendulum')
+
+        self.validate(display_num_errors=False)
+
+        # determine the content type for the Pendulum.Entry model
+        from django.contrib.contenttypes.models import ContentType
+        content_type = ContentType.objects.get(app_label='pendulum',
+                                               model='entry')
+
+        # find all permissions for the Entry model
+        from django.contrib.auth.models import Permission, Group
+        permissions = Permission.objects.filter(content_type=content_type)
+
+        try:
+            # remove the existing group if necessary
+            if reset:
+                Group.objects.filter(name=name).delete()
+
+            # attempt to create a user group called "Pendulum" with all of the
+            # available permissions for Entry objects
+            group = Group.objects.create(name=name)
+            group.permissions = permissions
+            group.save()
+        except Exception, e:
+            print 'Failed to create default Pendulum user group.'
+            print 'Do you already have a group called "%s"?' % name
+        else:
+            print 'Default user group "%s" created successfully.' % name
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from distutils.core import setup
+import sys, os
+
+def fullsplit(path, result=None):
+    """
+    Split a pathname into components (the opposite of os.path.join) in a
+    platform-neutral way.
+    """
+    if result is None:
+        result = []
+    head, tail = os.path.split(path)
+    if head == '':
+        return [tail] + result
+    if head == path:
+        return result
+    return fullsplit(head, [tail] + result)
+
+packages, data_files = [], []
+root_dir = os.path.dirname(__file__)
+if root_dir != '':
+    os.chdir(root_dir)
+pendulum_dir = 'pendulum'
+
+for path, dirs, files in os.walk(pendulum_dir):
+    # ignore hidden directories and files
+    for i, d in enumerate(dirs):
+        if d.startswith('.'): del dirs[i]
+
+    if '__init__.py' in files:
+        packages.append('.'.join(fullsplit(path)))
+    elif files:
+        data_files.append((path, [os.path.join(path, f) for f in files]))
+
+setup(
+    name='django-pendulum',
+    version='0.1',
+    url='http://code.google.com/p/django-pendulum/',
+    author='Josh VanderLinden',
+    author_email='codekoala@gmail.com',
+    license='MIT',
+    packages=packages,
+    data_files=data_files,
+    description="A simple timeclock/timecard application for use in Django-powered Web sites.",
+    long_description="""
+django-pendulum is a basic timeclock/timecard/time logging application that
+can easily be plugged into a Django-powered Web site.
+
+Features include:
+    - Configuration: Pendulum can be configured to operate on several Django-
+        powered sites.  The period lengths can be configured as monthly or as
+        a fixed-length period.
+    - Projects: You can have an unlimited number of projects to be able to
+        categorize hours spent working on certain tasks.  Each project can be
+        activated/deactivated as necessary via the Django admin.
+    - Activities: Activities allow you to further categorize work done on
+        particular tasks for each project.
+"""
+)
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.