Added email templates (not finished) and defined the notifiable fields for all models
parent
4becf63ce4
commit
a16847ce58
|
@ -17,17 +17,15 @@ class NotificationSenderMixin(object):
|
|||
def post_save(self, obj, created=False):
|
||||
users = obj.get_watchers_to_notify(self.request.user)
|
||||
context = {
|
||||
'changer': self.request.user,
|
||||
'changed_fields_dict': obj.get_changed_fields_dict(self.request.DATA),
|
||||
'object': obj
|
||||
"changer": self.request.user,
|
||||
"object": obj
|
||||
}
|
||||
|
||||
if created:
|
||||
#self._send_notification_email(self.create_notification_template, users=users, context=context)
|
||||
print "TODO: Send the notification email of object creation"
|
||||
self._send_notification_email(self.create_notification_template, users=users, context=context)
|
||||
else:
|
||||
#self._send_notification_email(self.update_notification_template, users=users, context=context)
|
||||
print "TODO: Send the notification email of object modification"
|
||||
context["changed_fields_dict"] = obj.get_changed_fields_dict(self.request.DATA)
|
||||
self._send_notification_email(self.update_notification_template, users=users, context=context)
|
||||
|
||||
def destroy(self, request, *args, **kwargs):
|
||||
users = obj.get_watchers_to_notify(self.request.user)
|
||||
|
@ -35,7 +33,6 @@ class NotificationSenderMixin(object):
|
|||
'changer': self.request.user,
|
||||
'object': obj
|
||||
}
|
||||
#self._send_notification_email(self.destroy_notification_template, users=users, context=context)
|
||||
print "TODO: Send the notification email of object deletion"
|
||||
self._send_notification_email(self.destroy_notification_template, users=users, context=context)
|
||||
|
||||
return super(NotificationSenderMixin, self).destroy(request, *args, **kwargs)
|
||||
|
|
|
@ -53,6 +53,8 @@ class WatcherMixin(object):
|
|||
|
||||
|
||||
class WatchedMixin(object):
|
||||
notifiable_fields = []
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
@ -62,6 +64,11 @@ class WatchedMixin(object):
|
|||
return version_list and version_list[0] or None
|
||||
|
||||
def get_changed_fields_dict(self, data_dict):
|
||||
if self.notified_fields:
|
||||
changed_data = dict((k, d[k]) for k in data_dict if k in self.notifiable_fields)
|
||||
else:
|
||||
changed_data = data_dict
|
||||
|
||||
field_dict = {}
|
||||
for field_name, data_value in data_dict.items():
|
||||
field_dict.update(self._get_changed_field(field_name, data_value))
|
||||
|
|
|
@ -218,6 +218,15 @@ class Project(models.Model, WatchedMixin):
|
|||
tags = PickledObjectField(null=False, blank=True,
|
||||
verbose_name=_('tags'))
|
||||
|
||||
notifiable_fields = [
|
||||
"name",
|
||||
"description",
|
||||
"owner",
|
||||
"members",
|
||||
"public",
|
||||
"tags",
|
||||
]
|
||||
|
||||
class Meta:
|
||||
verbose_name = u'project'
|
||||
verbose_name_plural = u'projects'
|
||||
|
@ -243,18 +252,6 @@ class Project(models.Model, WatchedMixin):
|
|||
def _get_watchers_by_role(self):
|
||||
return {'owner': self.owner}
|
||||
|
||||
def eget_attrinutes_to_notify(self):
|
||||
return {
|
||||
'name': self.name,
|
||||
'slug': self.slug,
|
||||
'description': self.description,
|
||||
'modified_date': self.modified_date,
|
||||
'owner': self.owner.get_full_name(),
|
||||
'members': ', '.join([member.get_full_name() for member in self.members.all()]),
|
||||
'public': self.public,
|
||||
'tags': self.tags,
|
||||
}
|
||||
|
||||
@property
|
||||
def list_of_milestones(self):
|
||||
return [{
|
||||
|
@ -293,9 +290,6 @@ class Project(models.Model, WatchedMixin):
|
|||
.exclude(role__id__in=role_ids)\
|
||||
.delete()
|
||||
|
||||
def _get_watchers_by_role(self):
|
||||
return {'owner': self.owner}
|
||||
|
||||
|
||||
class Milestone(models.Model, WatchedMixin):
|
||||
uuid = models.CharField(max_length=40, unique=True, null=False, blank=True,
|
||||
|
@ -323,6 +317,15 @@ class Milestone(models.Model, WatchedMixin):
|
|||
order = models.PositiveSmallIntegerField(default=1, null=False, blank=False,
|
||||
verbose_name=_('order'))
|
||||
|
||||
notifiable_fields = [
|
||||
"name",
|
||||
"owner",
|
||||
"estimated_start",
|
||||
"estimated_finish",
|
||||
"closed",
|
||||
"disponibility",
|
||||
]
|
||||
|
||||
class Meta:
|
||||
verbose_name = u'milestone'
|
||||
verbose_name_plural = u'milestones'
|
||||
|
@ -454,6 +457,19 @@ class UserStory(WatchedMixin, models.Model):
|
|||
tags = PickledObjectField(null=False, blank=True,
|
||||
verbose_name=_('tags'))
|
||||
|
||||
notifiable_fields = [
|
||||
"milestone",
|
||||
"owner",
|
||||
"status",
|
||||
"points",
|
||||
"finish_date",
|
||||
"subject",
|
||||
"description",
|
||||
"client_requirement",
|
||||
"team_requirement",
|
||||
"tags",
|
||||
]
|
||||
|
||||
class Meta:
|
||||
verbose_name = u'user story'
|
||||
verbose_name_plural = u'user stories'
|
||||
|
@ -559,6 +575,17 @@ class Task(models.Model, WatchedMixin):
|
|||
is_iocaine = models.BooleanField(default=False, null=False, blank=True,
|
||||
verbose_name=_('is iocaine'))
|
||||
|
||||
notifiable_fields = [
|
||||
"owner",
|
||||
"status",
|
||||
"finished_date",
|
||||
"subject",
|
||||
"description",
|
||||
"assigned_to",
|
||||
"tags",
|
||||
"is_iocaine",
|
||||
]
|
||||
|
||||
class Meta:
|
||||
verbose_name = u'task'
|
||||
verbose_name_plural = u'tasks'
|
||||
|
@ -638,6 +665,20 @@ class Issue(models.Model, WatchedMixin):
|
|||
tags = PickledObjectField(null=False, blank=True,
|
||||
verbose_name=_('tags'))
|
||||
|
||||
notifiable_fields = [
|
||||
"owner",
|
||||
"status",
|
||||
"severity",
|
||||
"priority",
|
||||
"type",
|
||||
"milestone",
|
||||
"finished_date",
|
||||
"subject",
|
||||
"description",
|
||||
"assigned_to",
|
||||
"tags",
|
||||
]
|
||||
|
||||
class Meta:
|
||||
verbose_name = u'issue'
|
||||
verbose_name_plural = u'issues'
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Create the new Issue "{{ object }}"
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Create the new milestone "{{ object }}"
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Create the new project "{{ object }}"
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Create the new user story "{{ object }}"
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Create the new task "{{ object }}"
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Deleted the issue "{{ object }}"
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Deleted the milestone "{{ object }}"
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Deleted the project "{{ object }}"
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Deleted the task "{{ object }}"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
# TODO: {{ changer }} {{ object }}
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
Deleted the user story "{{ object }}"
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
<p>Updated fields by {{ changer }}:</p>
|
||||
<ul>
|
||||
{% for field in changed_fields %}
|
||||
<li><b>{{ field.verbose_name}}</b>: from "{{ field.old_value}}" to "{{ field.new_value}}".</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{# TODO Print the "object" details #}
|
|
@ -0,0 +1,9 @@
|
|||
Updated fields by {{ changer }}:
|
||||
|
||||
{% for field in changed_fields %}
|
||||
** {{ field.verbose_name}}: from "{{ field.old_value}}" to "{{ field.new_value}}".
|
||||
{% endfor %}
|
||||
|
||||
{# TODO Print the "object" details #}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
Updated the issue "{{ object }}"
|
|
@ -0,0 +1,8 @@
|
|||
<p>Updated fields by {{ changer }}:</p>
|
||||
<ul>
|
||||
{% for field in changed_fields %}
|
||||
<li><b>{{ field.verbose_name}}</b>: from "{{ field.old_value}}" to "{{ field.new_value}}".</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{# TODO Print the "object" details #}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Updated fields by {{ changer }}:
|
||||
|
||||
{% for field in changed_fields %}
|
||||
** {{ field.verbose_name}}: from "{{ field.old_value}}" to "{{ field.new_value}}".
|
||||
{% endfor %}
|
||||
|
||||
{# TODO Print the "object" details #}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
Updated the milestone "{{ object }}"
|
|
@ -0,0 +1,8 @@
|
|||
<p>Updated fields by {{ changer }}:</p>
|
||||
<ul>
|
||||
{% for field in changed_fields %}
|
||||
<li><b>{{ field.verbose_name}}</b>: from "{{ field.old_value}}" to "{{ field.new_value}}".</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{# TODO Print the "object" details #}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Updated fields by {{ changer }}:
|
||||
|
||||
{% for field in changed_fields %}
|
||||
** {{ field.verbose_name}}: from "{{ field.old_value}}" to "{{ field.new_value}}".
|
||||
{% endfor %}
|
||||
|
||||
{# TODO Print the "object" details #}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
Updated the project "{{ object }}"
|
|
@ -0,0 +1,8 @@
|
|||
<p>Updated fields by {{ changer }}:</p>
|
||||
<ul>
|
||||
{% for field in changed_fields %}
|
||||
<li><b>{{ field.verbose_name}}</b>: from "{{ field.old_value}}" to "{{ field.new_value}}".</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{# TODO Print the "object" details #}
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
Updated fields by {{ changer }}:
|
||||
|
||||
{% for field in changed_fields %}
|
||||
** {{ field.verbose_name}}: from "{{ field.old_value}}" to "{{ field.new_value}}".
|
||||
{% endfor %}
|
||||
|
||||
{# TODO Print the "object" details #}
|
||||
|
||||
|
|
@ -0,0 +1 @@
|
|||
Updated the task "{{ object }}"
|
|
@ -0,0 +1,8 @@
|
|||
<p>Updated fields by {{ changer }}:</p>
|
||||
<ul>
|
||||
{% for field in changed_fields %}
|
||||
<li><b>{{ field.verbose_name}}</b>: from "{{ field.old_value}}" to "{{ field.new_value}}".</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
{# TODO Print the "object" details #}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
Updated fields by {{ changer }}:
|
||||
|
||||
{% for field in changed_fields %}
|
||||
** {{ field.verbose_name}}: from "{{ field.old_value}}" to "{{ field.new_value}}".
|
||||
{% endfor %}
|
||||
|
||||
{# TODO Print the "object" details #}
|
||||
|
|
@ -0,0 +1 @@
|
|||
Updated the user story "{{ object }}"
|
Loading…
Reference in New Issue