Skip to content
Snippets Groups Projects
Commit 0515de48 authored by Todd Dembrey's avatar Todd Dembrey
Browse files

Add the concept of type to activity

parent 5dab01e8
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
# Generated by Django 1.11.8 on 2018-03-01 15:49
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('activity', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='activity',
name='type',
field=models.CharField(choices=[('comment', 'Comment'), ('activity', 'Activity')], default='comment', max_length=30),
preserve_default=False,
),
]
from django.conf import settings
from django.db import models
COMMENT = 'comment'
ACTIVITY = 'activity'
ACTIVITY_TYPES = {
COMMENT: 'Comment',
ACTIVITY: 'Activity',
}
class CommentManger(models.Manager):
def create(self, **kwargs):
kwargs.update(type=COMMENT)
return super().create(**kwargs)
def get_queryset(self):
return super().get_queryset().filter(type=COMMENT)
class ActivityManager(models.Manager):
def create(self, **kwargs):
kwargs.update(type=ACTIVITY)
return super().create(**kwargs)
def get_queryset(self):
return super().get_queryset().filter(type=ACTIVITY)
class Activity(models.Model):
timestamp = models.DateTimeField(auto_now_add=True)
type = models.CharField(choices=ACTIVITY_TYPES.items(), max_length=30)
user = models.ForeignKey(settings.AUTH_USER_MODEL)
submission = models.ForeignKey('funds.ApplicationSubmission', related_name='activities')
message = models.TextField()
objects = models.Manager()
comments = CommentManger()
activities = ActivityManager()
class Meta:
ordering = ['-timestamp']
from django.views.generic import CreateView, View
from .forms import CommentForm
from .models import Activity
from .models import Activity, COMMENT
class CommentContextMixin:
def get_context_data(self, **kwargs):
extra = {
'comments': Activity.objects.filter(submission=self.object),
'comments': Activity.comments.filter(submission=self.object),
CommentFormView.context_name: CommentFormView.form_class(),
}
......@@ -34,6 +34,7 @@ class CommentFormView(DelegatedViewMixin, CreateView):
def form_valid(self, form):
form.instance.user = self.request.user
form.instance.submission = self.kwargs['submission']
form.instance.type = COMMENT
return super().form_valid(form)
def get_success_url(self):
......
......@@ -62,7 +62,7 @@ class ProgressSubmissionView(DelegatedViewMixin, UpdateView):
old_phase = form.instance.phase.name
response = super().form_valid(form)
new_phase = form.instance.phase.name
Activity.objects.create(
Activity.activities.create(
user=self.request.user,
submission=self.kwargs['submission'],
message=f'Progressed from {old_phase} to {new_phase}'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment