From c0121b9b7f5041f6434a2e2dd24d3c68ed84b582 Mon Sep 17 00:00:00 2001 From: Filipp Lepalaan Date: Thu, 31 Jan 2013 20:08:20 +0200 Subject: Initial commit --- .gitignore | 1 + README.md | 5 +- manage.py | 10 +++ notes/__init__.py | 0 notes/models.py | 63 ++++++++++++++++ notes/templates/edit.html | 31 ++++++++ notes/templates/index.html | 27 +++++++ notes/templates/view.html | 15 ++++ notes/tests.py | 16 ++++ notes/views.py | 51 +++++++++++++ opus/__init__.py | 0 opus/settings.py | 153 ++++++++++++++++++++++++++++++++++++++ opus/templates/blank.html | 3 + opus/templates/default.html | 69 +++++++++++++++++ opus/urls.py | 32 ++++++++ opus/wsgi.py | 28 +++++++ timer/__init__.py | 0 timer/models.py | 44 +++++++++++ timer/static/js/backbone-min.js | 42 +++++++++++ timer/static/js/underscore-min.js | 1 + timer/templates/alarm.html | 68 +++++++++++++++++ timer/templates/default.html | 62 +++++++++++++++ timer/templates/event_detail.html | 13 ++++ timer/templates/event_grid.html | 30 ++++++++ timer/templates/event_list.html | 5 ++ timer/templates/label_list.html | 3 + timer/templates/labels.html | 31 ++++++++ timer/templates/timer.html | 59 +++++++++++++++ timer/tests.py | 16 ++++ timer/views.py | 102 +++++++++++++++++++++++++ 30 files changed, 979 insertions(+), 1 deletion(-) create mode 100755 manage.py create mode 100644 notes/__init__.py create mode 100644 notes/models.py create mode 100644 notes/templates/edit.html create mode 100644 notes/templates/index.html create mode 100644 notes/templates/view.html create mode 100644 notes/tests.py create mode 100644 notes/views.py create mode 100644 opus/__init__.py create mode 100644 opus/settings.py create mode 100644 opus/templates/blank.html create mode 100644 opus/templates/default.html create mode 100644 opus/urls.py create mode 100644 opus/wsgi.py create mode 100644 timer/__init__.py create mode 100644 timer/models.py create mode 100644 timer/static/js/backbone-min.js create mode 100644 timer/static/js/underscore-min.js create mode 100644 timer/templates/alarm.html create mode 100644 timer/templates/default.html create mode 100644 timer/templates/event_detail.html create mode 100644 timer/templates/event_grid.html create mode 100644 timer/templates/event_list.html create mode 100644 timer/templates/label_list.html create mode 100644 timer/templates/labels.html create mode 100644 timer/templates/timer.html create mode 100644 timer/tests.py create mode 100644 timer/views.py diff --git a/.gitignore b/.gitignore index d9437c3..da292ce 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ *.pot *.pyc local_settings.py +*.db diff --git a/README.md b/README.md index 7db1e06..9ba8500 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ opus ==== -Tools that every office needs \ No newline at end of file +Tools that every office needs: + +- Shared notes +- Time tracking diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..9391588 --- /dev/null +++ b/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "opus.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/notes/__init__.py b/notes/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/notes/models.py b/notes/models.py new file mode 100644 index 0000000..2cd5ca6 --- /dev/null +++ b/notes/models.py @@ -0,0 +1,63 @@ +import re +from datetime import datetime +from django.db import models +from django.contrib.auth.models import User +from django.db.models.signals import post_save +from django.dispatch import receiver + +class Tag(models.Model): + title = models.CharField(max_length=128) + + class Meta: + ordering = ['title'] + +class Note(models.Model): + user = models.ForeignKey(User) + shared = models.BooleanField(default=True) + title = models.CharField(max_length=140, null=True) + tags = models.ManyToManyField(Tag, null=True, blank=True) + + def get_date(self): + return self.version_set.all()[0].created_at + + def get_user(self): + pass + + def content(self): + try: + return self.version_set.latest().content + except Version.DoesNotExist: + return '' + + def updated_at(self): + return self.version_set.latest().created_at + + def get_absolute_url(self): + return '/notes/%d/' % self.pk + + class Meta: + ordering = ['-id'] + +class Version(models.Model): + note = models.ForeignKey(Note) + user = models.ForeignKey(User) + content = models.TextField() + created_at = models.DateTimeField(default=datetime.now()) + + class Meta: + get_latest_by = 'created_at' + +class Attachment(models.Model): + content = models.FileField(upload_to='uploads') + note = models.ForeignKey(Note) + +@receiver(post_save, sender=Version) +def version_saved(sender, instance, created, **kwargs): + + tags = re.findall('#(\w+)', instance.content) + + for t in tags: + tag = Tag.objects.get_or_create(title=t)[0] + instance.note.tags.add(tag) + + instance.note.save() diff --git a/notes/templates/edit.html b/notes/templates/edit.html new file mode 100644 index 0000000..6d2ec1e --- /dev/null +++ b/notes/templates/edit.html @@ -0,0 +1,31 @@ +{% extends request.is_ajax|yesno:"blank.html,index.html" %} + +{% block content %} +
+
+ Notes +

New Note

+ Done +
+
+
+ {% csrf_token %} + {{ form }} + + {% if form.is_bound %} + Delete + {% endif %} +
+
+
+ + +{% endblock content %} diff --git a/notes/templates/index.html b/notes/templates/index.html new file mode 100644 index 0000000..c996511 --- /dev/null +++ b/notes/templates/index.html @@ -0,0 +1,27 @@ +{% extends request.is_ajax|yesno:"blank.html,default.html" %} + +{% block content %} +
+
+ Tags +

Notes

+ New +
+
+ + +
+ +
+
+
+ +{% endblock content %} diff --git a/notes/templates/view.html b/notes/templates/view.html new file mode 100644 index 0000000..a6d3473 --- /dev/null +++ b/notes/templates/view.html @@ -0,0 +1,15 @@ +{% extends request.is_ajax|yesno:"blank.html,index.html" %} +{% load markup %} + +{% block content %} +
+
+ Notes +

{{ note.title }}

+ Edit +
+
+

{{ version.content|restructuredtext }}

+
+
+{% endblock content %} diff --git a/notes/tests.py b/notes/tests.py new file mode 100644 index 0000000..501deb7 --- /dev/null +++ b/notes/tests.py @@ -0,0 +1,16 @@ +""" +This file demonstrates writing tests using the unittest module. These will pass +when you run "manage.py test". + +Replace this with more appropriate tests for your application. +""" + +from django.test import TestCase + + +class SimpleTest(TestCase): + def test_basic_addition(self): + """ + Tests that 1 + 1 always equals 2. + """ + self.assertEqual(1 + 1, 2) diff --git a/notes/views.py b/notes/views.py new file mode 100644 index 0000000..386b0c0 --- /dev/null +++ b/notes/views.py @@ -0,0 +1,51 @@ +from django import forms +from django.shortcuts import render, redirect +from notes.models import Note, Attachment, Tag, Version + +class NoteForm(forms.Form): + title = forms.CharField() + content = forms.CharField(widget=forms.Textarea(attrs={'rows': 20, + 'style': 'width:100%;height:100%'})) + shared = forms.BooleanField() + attachment = forms.FileField(required=False) + +def edit(request, note_id=None): + + note = Note(user_id=1) + + if note_id: + note = Note.objects.get(pk=note_id) + + if request.method == 'POST': + form = NoteForm(request.POST, request.FILES) + + if not form.is_valid(): + return render(request, 'edit.html', {'form': form}) + + note.title = form.cleaned_data.get('title') + note.save() + + version = Version(note=note, user_id=1) + version.content = form.cleaned_data.get('content') + version.shared = form.cleaned_data.get('shared') + version.save() + + return render(request, 'view.html', {'note': note, 'version': version}) + + form = NoteForm(initial={'content': note.content, 'shared': note.shared}) + + return render(request, 'edit.html', {'form': form}) + +def index(request, tag_id=None): + notes = Note.objects.filter(user_id=1) + + if tag_id: + notes = notes.filter(tags__pk=tag_id) + + tags = Tag.objects.distinct() + return render(request, 'index.html', {'notes': notes, 'tags': tags}) + +def view(request, note_id): + note = Note.objects.get(pk=note_id) + version = note.version_set.latest() + return render(request, 'view.html', {'note': note, 'version': version}) diff --git a/opus/__init__.py b/opus/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/opus/settings.py b/opus/settings.py new file mode 100644 index 0000000..2567e1b --- /dev/null +++ b/opus/settings.py @@ -0,0 +1,153 @@ +# Django settings for opus project. + +DEBUG = True +TEMPLATE_DEBUG = DEBUG + +ADMINS = ( + # ('Your Name', 'your_email@example.com'), +) + +MANAGERS = ADMINS + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. + 'NAME': 'opus.db', # Or path to database file if using sqlite3. + 'USER': '', # Not used with sqlite3. + 'PASSWORD': '', # Not used with sqlite3. + 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. + 'PORT': '', # Set to empty string for default. Not used with sqlite3. + } +} + +# Local time zone for this installation. Choices can be found here: +# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name +# although not all choices may be available on all operating systems. +# In a Windows environment this must be set to your system time zone. +TIME_ZONE = 'America/Chicago' + +# Language code for this installation. All choices can be found here: +# http://www.i18nguy.com/unicode/language-identifiers.html +LANGUAGE_CODE = 'en-us' + +SITE_ID = 1 + +# If you set this to False, Django will make some optimizations so as not +# to load the internationalization machinery. +USE_I18N = True + +# If you set this to False, Django will not format dates, numbers and +# calendars according to the current locale. +USE_L10N = True + +# If you set this to False, Django will not use timezone-aware datetimes. +USE_TZ = False + +# Absolute filesystem path to the directory that will hold user-uploaded files. +# Example: "/home/media/media.lawrence.com/media/" +MEDIA_ROOT = '' + +# URL that handles the media served from MEDIA_ROOT. Make sure to use a +# trailing slash. +# Examples: "http://media.lawrence.com/media/", "http://example.com/media/" +MEDIA_URL = '' + +# Absolute path to the directory static files should be collected to. +# Don't put anything in this directory yourself; store your static files +# in apps' "static/" subdirectories and in STATICFILES_DIRS. +# Example: "/home/media/media.lawrence.com/static/" +STATIC_ROOT = '' + +# URL prefix for static files. +# Example: "http://media.lawrence.com/static/" +STATIC_URL = '/static/' + +# Additional locations of static files +STATICFILES_DIRS = ( + # Put strings here, like "/home/html/static" or "C:/www/django/static". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +# List of finder classes that know how to find static files in +# various locations. +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', +# 'django.contrib.staticfiles.finders.DefaultStorageFinder', +) + +# Make this unique, and don't share it with anybody. +SECRET_KEY = 'p3bkcgfs4bv5+0moy8^w^njqxqc#fn9(&s^a7_=2r&f750@0c#' + +# List of callables that know how to import templates from various sources. +TEMPLATE_LOADERS = ( + 'django.template.loaders.filesystem.Loader', + 'django.template.loaders.app_directories.Loader', +# 'django.template.loaders.eggs.Loader', +) + +MIDDLEWARE_CLASSES = ( + 'django.middleware.common.CommonMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + # Uncomment the next line for simple clickjacking protection: + # 'django.middleware.clickjacking.XFrameOptionsMiddleware', +) + +ROOT_URLCONF = 'opus.urls' + +# Python dotted path to the WSGI application used by Django's runserver. +WSGI_APPLICATION = 'opus.wsgi.application' + +TEMPLATE_DIRS = ( + # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". + # Always use forward slashes, even on Windows. + # Don't forget to use absolute paths, not relative paths. +) + +INSTALLED_APPS = ( + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + #'django.contrib.sites', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'django.contrib.markup', + 'timer', 'notes' + # Uncomment the next line to enable the admin: + # 'django.contrib.admin', + # Uncomment the next line to enable admin documentation: + # 'django.contrib.admindocs', +) + +# A sample logging configuration. The only tangible logging +# performed by this configuration is to send an email to +# the site admins on every HTTP 500 error when DEBUG=False. +# See http://docs.djangoproject.com/en/dev/topics/logging for +# more details on how to customize your logging configuration. +LOGGING = { + 'version': 1, + 'disable_existing_loggers': False, + 'filters': { + 'require_debug_false': { + '()': 'django.utils.log.RequireDebugFalse' + } + }, + 'handlers': { + 'mail_admins': { + 'level': 'ERROR', + 'filters': ['require_debug_false'], + 'class': 'django.utils.log.AdminEmailHandler' + } + }, + 'loggers': { + 'django.request': { + 'handlers': ['mail_admins'], + 'level': 'ERROR', + 'propagate': True, + }, + } +} diff --git a/opus/templates/blank.html b/opus/templates/blank.html new file mode 100644 index 0000000..e7f8a7b --- /dev/null +++ b/opus/templates/blank.html @@ -0,0 +1,3 @@ +{% block content %} + +{% endblock content %} diff --git a/opus/templates/default.html b/opus/templates/default.html new file mode 100644 index 0000000..c970b6b --- /dev/null +++ b/opus/templates/default.html @@ -0,0 +1,69 @@ +{% load staticfiles %} + + + + opus v0.01 + + + + + + + + {% block content %} + + {% endblock content %} + + diff --git a/opus/urls.py b/opus/urls.py new file mode 100644 index 0000000..75e20ee --- /dev/null +++ b/opus/urls.py @@ -0,0 +1,32 @@ +from django.conf.urls import patterns, include, url + +# Uncomment the next two lines to enable the admin: +# from django.contrib import admin +# admin.autodiscover() + +urlpatterns = patterns('', + # Examples: + # url(r'^$', 'opus2.views.home', name='home'), + # url(r'^opus2/', include('opus2.foo.urls')), + + # Uncomment the admin/doc line below to enable admin documentation: + # url(r'^admin/doc/', include('django.contrib.admindocs.urls')), + + # Uncomment the next line to enable the admin: + # url(r'^admin/', include(admin.site.urls)), + url(r'^timer/$', 'timer.views.labels'), + url(r'^timer/events/(\d+)/$', 'timer.views.view_event'), + url(r'^timer/events/(\d+)/delete/$', 'timer.views.delete_event'), + url(r'^timer/label/(\d+)/events/$', 'timer.views.events'), + url(r'^timer/labels/$', 'timer.views.labels'), + url(r'^timer/labels/new/$', 'timer.views.edit_label'), + + url(r'^alarm/$', 'timer.views.alarm'), + + url(r'^notes/$', 'notes.views.index'), + url(r'^notes/tag/(\d+)/$', 'notes.views.index'), + + url(r'^notes/(\d+)/$', 'notes.views.view'), + url(r'^notes/new/$', 'notes.views.edit'), + url(r'^notes/(\d+)/edit/$', 'notes.views.edit'), +) diff --git a/opus/wsgi.py b/opus/wsgi.py new file mode 100644 index 0000000..f323b3a --- /dev/null +++ b/opus/wsgi.py @@ -0,0 +1,28 @@ +""" +WSGI config for opus2 project. + +This module contains the WSGI application used by Django's development server +and any production WSGI deployments. It should expose a module-level variable +named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover +this application via the ``WSGI_APPLICATION`` setting. + +Usually you will have the standard Django WSGI application here, but it also +might make sense to replace the whole Django WSGI application with a custom one +that later delegates to the Django one. For example, you could introduce WSGI +middleware here, or combine a Django application with an application of another +framework. + +""" +import os + +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "opus2.settings") + +# This application object is used by any WSGI server configured to use this +# file. This includes Django's development server, if the WSGI_APPLICATION +# setting points here. +from django.core.wsgi import get_wsgi_application +application = get_wsgi_application() + +# Apply WSGI middleware here. +# from helloworld.wsgi import HelloWorldApplication +# application = HelloWorldApplication(application) diff --git a/timer/__init__.py b/timer/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/timer/models.py b/timer/models.py new file mode 100644 index 0000000..1052eca --- /dev/null +++ b/timer/models.py @@ -0,0 +1,44 @@ +from datetime import datetime + +from django.db import models +from django.contrib.auth.models import User + +class Label(models.Model): + user = models.ForeignKey(User, editable=False) + title = models.CharField(max_length=128) + color = models.CharField(max_length=6, default="red") + + def get_absolute_url(self): + return "/timer/label/%d/events/" % self.pk + + def __unicode__(self): + return self.title + + class Meta: + ordering = ['-id'] + +class Event(models.Model): + user = models.ForeignKey(User, editable=False) + started_at = models.DateTimeField(default=datetime.now()) + duration = models.IntegerField(null=True, blank=True) + finished_at = models.DateTimeField(null=True, blank=True) # in seconds + labels = models.ManyToManyField(Label, null=True, blank=True) + notes = models.TextField(null=True, blank=True) + + def hours(self): + return self.duration/3600 + + def title(self): + if self.notes: + return '%s: %s' % (self.notes, self.duration()) + + return self.started_at + + def as_json(self): + return {'started_at': int(self.started_at.strftime('%s'))*1000} + + def get_absolute_url(self): + return "/timer/events/%d/" % self.pk + + class Meta: + ordering = ['-started_at'] diff --git a/timer/static/js/backbone-min.js b/timer/static/js/backbone-min.js new file mode 100644 index 0000000..d4b0314 --- /dev/null +++ b/timer/static/js/backbone-min.js @@ -0,0 +1,42 @@ +// Backbone.js 0.9.10 + +// (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc. +// Backbone may be freely distributed under the MIT license. +// For all details and documentation: +// http://backbonejs.org +(function(){var n=this,B=n.Backbone,h=[],C=h.push,u=h.slice,D=h.splice,g;g="undefined"!==typeof exports?exports:n.Backbone={};g.VERSION="0.9.10";var f=n._;!f&&"undefined"!==typeof require&&(f=require("underscore"));g.$=n.jQuery||n.Zepto||n.ender;g.noConflict=function(){n.Backbone=B;return this};g.emulateHTTP=!1;g.emulateJSON=!1;var v=/\s+/,q=function(a,b,c,d){if(!c)return!0;if("object"===typeof c)for(var e in c)a[b].apply(a,[e,c[e]].concat(d));else if(v.test(c)){c=c.split(v);e=0;for(var f=c.length;e< +f;e++)a[b].apply(a,[c[e]].concat(d))}else return!0},w=function(a,b){var c,d=-1,e=a.length;switch(b.length){case 0:for(;++d=b);this.root=("/"+this.root+"/").replace(I,"/");b&&this._wantsHashChange&&(this.iframe=g.$('