<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from django.db import models
from django.utils.translation import ugettext_lazy as _

from opps.core.models import Publishable
from opps.db import Db


NOTIFICATION_TYPE = (
    (u'json', _(u'JSON')),
    (u'text', _(u'Text')),
    (u'html', _(u'HTML')),
)


class Notification(Publishable):
    container = models.ForeignKey('containers.Container')
    action = models.CharField(_('Action'), max_length=75,
                              default="message")
    type = models.CharField(_('Type'), max_length=10,
                            choices=NOTIFICATION_TYPE,
                            default='json')
    message = models.TextField(_('Message'))

    def save(self, *args, **kwargs):
        super(Notification, self).save(*args, **kwargs)
        _db = Db(self.container.get_absolute_url(),
                 self.container.id)
        _db.publish(json.dumps({
            "action": self.action,
            "id": self.id,
            "published": self.published,
            "date": self.date_available.strftime("%D %T"),
            "message": self.message}))<commit_msg>generate messagem type (json)<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
from django.db import models
from django.utils.translation import ugettext_lazy as _

from opps.core.models import Publishable
from opps.db import Db


NOTIFICATION_TYPE = (
    (u'json', _(u'JSON')),
    (u'text', _(u'Text')),
    (u'html', _(u'HTML')),
)


class Notification(Publishable):
    container = models.ForeignKey('containers.Container')
    action = models.CharField(_('Action'), max_length=75,
                              default="message")
    type = models.CharField(_('Type'), max_length=10,
                            choices=NOTIFICATION_TYPE,
                            default='json')
    message = models.TextField(_('Message'))

    def save(self, *args, **kwargs):
        super(Notification, self).save(*args, **kwargs)
        _db = Db(self.container.get_absolute_url(),
                 self.container.id)
        message = self.message
        if self.type == "json":
            message = json.dumps(self.message)
        _db.publish(json.dumps({
            "action": self.action,
            "id": self.id,
            "published": self.published,
            "date": self.date_available.strftime("%D %T"),
            "message": message}))
{'fraction_non_alphanumeric': 0.14644179350061703, 'fraction_numerical': 0.004113533525298231, 'mean_word_length': 2.4013986013986015, 'pattern_counts': {'":': 11, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4211572', 'n_tokens_mistral': 725, 'n_tokens_neox': 707, 'n_words': 143}