Commits

Rafał Selewońko committed c8c76d5

Comments (0)

Files changed (6)

templates/admin/base_site.html

 {% extends "admin/base.html" %}
 {% load i18n %}
 
-{% block title %}{{ title }} | {% trans 'WorkLogs' %}{% endblock %}
+{% block title %}{% trans 'WorkLogs' %} - {{ title }}{% endblock %}
 
 {% block branding %}
 <h1 id="site-name">{% trans 'WorkLogs' %}</h1>

templates/worklogs/report.html

     <div id="tabs-1">
     <pre>{{ from }} - {{ to }}
 {% for worklog, duration in time_per_worklog %}
-{{ worklog.description }} ({{duration|seconds_to_time}}) - {{ worklog.state }}
+{{ worklog.description }} ({{duration|seconds_to_time}}) - {{ worklog.get_state_display }}
 {{ worklog.bugtracker_url }}
 {% endfor %}
 </pre>

worklogs/admin.py

 from django.contrib import admin
 from django.utils.translation import ugettext_lazy as _
 from django.contrib.admin.templatetags.admin_list import _boolean_icon
+
 from .models import WorkLog, WorkLogEntry, Project, BugTracker
 from .urls import worklog_admin_urls
+from .forms import WorkLogAddForm
 
 
 class WorkLogAdmin(admin.ModelAdmin):
+    add_form = WorkLogAddForm
     date_hierarchy = 'mod_date'
     list_display = (
+        'get_bugtracker_id',
         'description',
         'project_link',
         'bugtracker_link',
     list_editable = ('state',)
     list_filter = ('project', 'state', 'bugtracker')
     list_select_related = True
-    search_fields = ('description', 'worklog_entries__description')
+    search_fields = ('description', 'worklog_entries__description', 'bugtracker_object_id')
+
+    def get_bugtracker_id(self, worklog):
+        return '#%s' % worklog.bugtracker_object_id
+    get_bugtracker_id.short_description = _(u"#")
 
     def get_duration_display(self, worklog):
         kwargs = {
         url = worklog.project.url
         name = worklog.project.name
         if url:
-            return """<a href="{url}">{name}</a>""".format(url=url, name=name)
+            return u"""<a href="{url}">{name}</a>""".format(url=url, name=name)
         else:
             return name
     project_link.allow_tags = True
     project_link.short_description = _("project")
 
+    def get_form(self, request, obj=None, **kwargs):
+        defaults = {}
+        if obj is None:
+            defaults.update({
+                'form': self.add_form,
+            })
+        defaults.update(kwargs)
+        return super(WorkLogAdmin, self).get_form(request, obj, **defaults)
+
     def get_urls(self):
         urls = super(WorkLogAdmin, self).get_urls()
         return worklog_admin_urls + urls

worklogs/forms.py

 from django.conf import settings
 from django.utils.translation import ugettext_lazy as _
 
-from tinymce.widgets import TinyMCE
+from .models import WorkLog
 
-from .models import Video
 
-
-class VideoForm(forms.ModelForm):
-    description = forms.CharField(widget=TinyMCE(attrs={'cols': 80,
-                                                        'rows': 30}))
+class WorkLogAddForm(forms.ModelForm):
 
     class Meta:
-        model = Video
-
-    def clean(self):
-        cleaned_data = super(VideoForm, self).clean()
-        file = cleaned_data.get('file', None)
-        file_ftp = cleaned_data.get('file_ftp', None)
-#        if not (file or file_ftp):
-#            raise forms.ValidationError(_(u'proszę wskazać plik lub plik na ftp'))
-
-        return cleaned_data
-
-    def clean_file(self):
-        file = self.cleaned_data.get('file')
-        if file:
-            filename = file.name
-            root, ext = os.path.splitext(filename)
-            ext = ext.lstrip('.').lower()
-            if ext not in settings.ALLOWED_VIDEO_FORMATS:
-                raise forms.ValidationError(_(u'niepoprawny format pliku video'))
-        return file
-
-    def clean_file_ftp(self):
-        file_ftp = self.cleaned_data.get('file_ftp')
-        if file_ftp:
-            filename = os.path.join(settings.FTP_MEDIA_ROOT, file_ftp)
-            if not os.path.exists(filename):
-                raise forms.ValidationError(_(u'plik nie znaleziony na ftp'))
-        return file_ftp
-
-
-class VideoAddForm(forms.ModelForm):
-    description = forms.CharField(widget=forms.Textarea(), required=False)
-    tags = forms.CharField(widget=forms.Textarea(), required=False)
-
-    class Meta:
-        model = Video
-        exclude = ('slug', 'user', 'aspect_ratio', 'duration', 'pub_date', 'end_date',
-                   'highlighted', 'imported', 'id_provider', 'authors',)
-    """
-    def clean(self):
-        cleaned_data = super(VideoAddForm, self).clean()
-        #file = cleaned_data.get('file', None)
-        #file_ftp = cleaned_data.get('file_ftp', None)
-        #if not (file or file_ftp):
-        #    raise forms.ValidationError(_(u'proszę wskazać plik lub plik na ftp'))
-
-        return cleaned_data
-    
-    def clean_file(self):
-        file = self.cleaned_data.get('file')
-        if file:
-            filename = file.name
-            root, ext = os.path.splitext(filename)
-            ext = ext.lstrip('.').lower()
-            if ext not in settings.ALLOWED_VIDEO_FORMATS:
-                raise forms.ValidationError(_(u'niepoprawny format pliku video'))
-        return file
-
-    def clean_file_ftp(self):
-        file_ftp = self.cleaned_data.get('file_ftp')
-        if file_ftp:
-            filename = os.path.join(settings.FTP_MEDIA_ROOT, file_ftp)
-            if not os.path.exists(filename):
-                raise forms.ValidationError(_(u'plik nie znaleziony na ftp'))
-        return file_ftp
-    """
-
-class VideoEditForm(forms.ModelForm):
-
-    class Meta:
-        model = Video
-        #exclude = ('description','frame_time','rating','slug','user')
+        model = WorkLog
+        exclude = ('active', 'duration')

worklogs/migrations/0002_auto__chg_field_worklog_bugtracker__chg_field_worklog_bugtracker_objec.py

+# -*- coding: utf-8 -*-
+import datetime
+from south.db import db
+from south.v2 import SchemaMigration
+from django.db import models
+
+
+class Migration(SchemaMigration):
+
+    def forwards(self, orm):
+
+        # Changing field 'WorkLog.bugtracker'
+        db.alter_column('worklogs_worklog', 'bugtracker_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['worklogs.BugTracker']))
+
+        # Changing field 'WorkLog.bugtracker_object_id'
+        db.alter_column('worklogs_worklog', 'bugtracker_object_id', self.gf('django.db.models.fields.CharField')(max_length=16, null=True))
+    def backwards(self, orm):
+
+        # User chose to not deal with backwards NULL issues for 'WorkLog.bugtracker'
+        raise RuntimeError("Cannot reverse this migration. 'WorkLog.bugtracker' and its values cannot be restored.")
+
+        # User chose to not deal with backwards NULL issues for 'WorkLog.bugtracker_object_id'
+        raise RuntimeError("Cannot reverse this migration. 'WorkLog.bugtracker_object_id' and its values cannot be restored.")
+    models = {
+        'auth.group': {
+            'Meta': {'object_name': 'Group'},
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
+            'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
+        },
+        'auth.permission': {
+            'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
+            'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
+        },
+        'auth.user': {
+            'Meta': {'object_name': 'User'},
+            'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
+            'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
+            'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
+            'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
+            'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
+        },
+        'contenttypes.contenttype': {
+            'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
+            'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
+        },
+        'worklogs.bugtracker': {
+            'Meta': {'object_name': 'BugTracker'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+            'url_pattern': ('django.db.models.fields.CharField', [], {'max_length': '256'})
+        },
+        'worklogs.project': {
+            'Meta': {'object_name': 'Project'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'name': ('django.db.models.fields.CharField', [], {'max_length': '64'}),
+            'url': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'})
+        },
+        'worklogs.worklog': {
+            'Meta': {'ordering': "('-add_date',)", 'object_name': 'WorkLog'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
+            'add_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
+            'bugtracker': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'worklogs'", 'null': 'True', 'to': "orm['worklogs.BugTracker']"}),
+            'bugtracker_object_id': ('django.db.models.fields.CharField', [], {'max_length': '16', 'null': 'True', 'blank': 'True'}),
+            'description': ('django.db.models.fields.CharField', [], {'max_length': '1024'}),
+            'duration': ('django.db.models.fields.PositiveIntegerField', [], {'null': 'True', 'blank': 'True'}),
+            'eta': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '8', 'decimal_places': '4', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'mod_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
+            'project': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'worklogs'", 'to': "orm['worklogs.Project']"}),
+            'state': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '0'}),
+            'user': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'worklogs'", 'to': "orm['auth.User']"})
+        },
+        'worklogs.worklogentry': {
+            'Meta': {'ordering': "('-start',)", 'object_name': 'WorkLogEntry'},
+            'active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
+            'description': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'null': 'True', 'blank': 'True'}),
+            'end': ('django.db.models.fields.DateTimeField', [], {'null': 'True', 'blank': 'True'}),
+            'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
+            'start': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
+            'worklog': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'worklog_entries'", 'to': "orm['worklogs.WorkLog']"})
+        }
+    }
+
+    complete_apps = ['worklogs']

worklogs/models.py

     STATE_NEW = 0
     STATE_IN_PROGRESS = 1
     STATE_WAITING = 2
-    STATE_RESOLVED = 3
-    STATE_CLOSED = 4
-    STATE_REJECTED = 5
+    STATE_READY = 3
+    STATE_RESOLVED = 4
+    STATE_CLOSED = 5
+    STATE_REJECTED = 6
 
     STATE_CHOICES = (\
         (STATE_NEW, _(u"new")),
         (STATE_IN_PROGRESS, _(u"in progress")),
         (STATE_WAITING, _(u"waiting")),
+        (STATE_READY, _(u"ready")),
         (STATE_RESOLVED, _(u"resolved")),
         (STATE_CLOSED, _(u"closed")),
         (STATE_REJECTED, _(u"rejected")),
                     related_name='worklogs')
 
     bugtracker = models.ForeignKey('BugTracker',
-                    verbose_name=_(u'bugtracker'),
-                    related_name='worklogs')
+            blank=True,
+            null=True,
+            verbose_name=_(u'bugtracker'),
+            related_name='worklogs')
 
     bugtracker_object_id = models.CharField(
-                    max_length=16,
-                    verbose_name=_(u"bugtracker object id"))
+            blank=True,
+            null=True,
+            max_length=16,
+            verbose_name=_(u"bugtracker object id"))
 
     duration = models.PositiveIntegerField(
                     blank=True,