Skip to content

Commit

Permalink
personal ignore list
Browse files Browse the repository at this point in the history
  • Loading branch information
gotlium committed Mar 14, 2015
1 parent c745197 commit 549a4e6
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ docs/build
db.sqlite
*.sh
TODO
*.bak
20 changes: 20 additions & 0 deletions mmc/migrations/0004_mmcemail_ignore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
('mmc', '0003_mmclog_stdout_messages'),
]

operations = [
migrations.AddField(
model_name='mmcemail',
name='ignore',
field=models.ManyToManyField(help_text=b'Helpful for different teams. Choose script which you want to ignore.', to='mmc.MMCScript', null=True, blank=True),
preserve_default=True,
),
]
11 changes: 8 additions & 3 deletions mmc/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class MMCEmail(models.Model):
created = models.DateField(auto_now=True, editable=False)
email = models.EmailField(
help_text='Email will be used for send all exceptions from command.')
ignore = models.ManyToManyField(
MMCScript, blank=True, null=True,
help_text='Helpful for different teams. '
'Choose script which you want to ignore.')
is_active = models.BooleanField(
default=True,
help_text='Email may be switched off for a little while.')
Expand All @@ -113,10 +117,11 @@ class Meta:
def send(cls, host_name, script_name, message):
try:
emails = list(cls.objects.values_list(
'email', flat=True).filter(is_active=True))
subject = SUBJECT % dict(script=script_name, host=host_name)

'email', flat=True
).filter(is_active=True).exclude(ignore__name=script_name))
if emails:
subject = SUBJECT % dict(script=script_name, host=host_name)

send_mail(
subject, message, settings.DEFAULT_FROM_EMAIL, emails,
fail_silently=True
Expand Down
71 changes: 71 additions & 0 deletions mmc/south_migrations/0011_auto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
from south.utils import datetime_utils as datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models


class Migration(SchemaMigration):

def forwards(self, orm):
# Adding M2M table for field ignore on 'MMCEmail'
m2m_table_name = db.shorten_name('mmc_mmcemail_ignore')
db.create_table(m2m_table_name, (
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True)),
('mmcemail', models.ForeignKey(orm['mmc.mmcemail'], null=False)),
('mmcscript', models.ForeignKey(orm['mmc.mmcscript'], null=False))
))
db.create_unique(m2m_table_name, ['mmcemail_id', 'mmcscript_id'])


def backwards(self, orm):
# Removing M2M table for field ignore on 'MMCEmail'
db.delete_table(db.shorten_name('mmc_mmcemail_ignore'))


models = {
'mmc.mmcemail': {
'Meta': {'object_name': 'MMCEmail'},
'created': ('django.db.models.fields.DateField', [], {'auto_now': 'True', 'blank': 'True'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ignore': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': "orm['mmc.MMCScript']", 'null': 'True', 'blank': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'})
},
'mmc.mmchost': {
'Meta': {'object_name': 'MMCHost'},
'created': ('django.db.models.fields.DateField', [], {'auto_now': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ignore': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'})
},
'mmc.mmclog': {
'Meta': {'object_name': 'MMCLog'},
'cpu_time': ('django.db.models.fields.FloatField', [], {'default': '0.0'}),
'created': ('django.db.models.fields.DateField', [], {'auto_now': 'True', 'blank': 'True'}),
'elapsed': ('django.db.models.fields.FloatField', [], {}),
'end': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'error_message': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'hostname': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['mmc.MMCHost']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'memory': ('django.db.models.fields.FloatField', [], {'default': '0.0'}),
'script': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['mmc.MMCScript']"}),
'start': ('django.db.models.fields.DateTimeField', [], {}),
'stdout_messages': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'success': ('django.db.models.fields.NullBooleanField', [], {'default': 'None', 'null': 'True', 'blank': 'True'}),
'sys_argv': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}),
'traceback': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'was_notified': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
},
'mmc.mmcscript': {
'Meta': {'object_name': 'MMCScript'},
'created': ('django.db.models.fields.DateField', [], {'auto_now': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'ignore': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '255'}),
'one_copy': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'save_on_error': ('django.db.models.fields.BooleanField', [], {'default': 'False'})
}
}

complete_apps = ['mmc']

0 comments on commit 549a4e6

Please sign in to comment.