<commit_before># -*- coding: utf-8 -*-
# EForge project management system, Copyright © 2010, Element43
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

from django.db import models
from eforge.models import Project, Milestone
from eforge.utils.picklefield import PickledObjectField
from eforge.utils.text import textscan
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.conf import settings
import os.path

class Component(models.Model):
    project = models.ForeignKey(Project)
    name    = models.CharField(max_length=32)
    def __unicode__(self):
        return self.name

IssuePriority = (
    (1, 'Security Vulnerability'),
    (2, 'Critical'),
    (3, 'High'),
    (4, 'Medium'),
    (5, 'Low'),
)

IssueType = (
    (1, 'Bug'),
    (2, 'Feature Request'),
    (3, 'Patch'),
)

IssueStatus = (
    (1, 'New'),
    (2, 'Assigned'),
    (3, 'Reopened'),
    (4, 'In Progress'),
    (5, 'Resolved'),
)

IssueResolution = (
    (1, 'Fixed'),
    (2, 'Invalid'),
    (3, 'Won\'t Fix'),
    (4, 'Duplicate'),
    (5, 'Works for me'),
    (6, 'Incomplete'),
)
class Bug(models.Model):
    project    = models.ForeignKey(Project)
    component  = models.ForeignKey(Component)
    priority   = models.SmallIntegerField(choices=IssuePriority, default=4)
    issue_type = models.SmallIntegerField(choices=IssueType, default=1)
    title      = models.CharField(max_length=50)

    target     = models.ForeignKey(Milestone)

    status     = models.SmallIntegerField(choices=IssueStatus, default=1)
    resolution = models.SmallIntegerField(choices=IssueResolution, default=0, blank=True)

    submitter  = models.ForeignKey(User, related_name='submitted_bugs')
    owner      = models.ForeignKey(User, related_name='owned_bugs', blank=True, null=True)

    depends    = models.ManyToManyField('self', symmetrical=False, related_name='blocks', blank=True)

    watchers   = models.ManyToManyField(User, related_name='watching_bugs', blank=True)

    @property
    def issue_type_name(self):
        return IssueType[self.issue_type-1][1]

    @property
    def priority_name(self):
        return IssuePriority[self.priority-1][1]

    @property
    def status_name(self):
        return IssueStatus[self.status-1][1]

    @property
    def resolution_name(self):
        return IssueResolution[self.resolution-1][1]

    @property
    def is_resolved(self):
        return self.status == 5

    @property
    def slug(self):
        return '#%s-%d' % (self.project.slug.upper(), self.id)

    @property
    def submitted(self):
        return self.comment_set.all()[0].date


    @property
    def url(self):
        return reverse('bug-show', args=[self.project.slug, self.id])

    def __unicode__(self):
        return self.slug

    def fromSlug(slug):
        parts = slug[1:].split('-')
        if len(parts) <> 2:
            raise ValueError('Bad slug')
        else:
            return Bug.objects.get(project__slug__iexact=parts[0], id=int(parts[1]))

class Comment(models.Model):
    bug        = models.ForeignKey(Bug)
    submitter  = models.ForeignKey(User)
    date       = models.DateTimeField(auto_now_add=True)
    text       = models.TextField()

    @property
    def formatted(self):
        return textscan(self.bug.project, self.text)

def up_file(this, name):
    return 'bugfiles/%d-%d/%s' % (this.bug_id, this.comment_id, name)

class Attachment(models.Model):
    bug        = models.ForeignKey(Bug)
    comment    = models.ForeignKey(Comment)
    file       = models.FileField(upload_to = up_file, verbose_name='Attachment')
    @property
    def file_name(self):
        return os.path.basename(str(self.file))<commit_msg>Tracking comments as updates (Initial test backend for update framework) (3/3)<commit_after># -*- coding: utf-8 -*-
# EForge project management system, Copyright © 2010, Element43
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#

from django.db import models
from eforge.models import Project, Milestone
from eforge.utils.picklefield import PickledObjectField
from eforge.utils.text import textscan
from eforge.update.models import Update, register_update_type
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse
from django.conf import settings
import os.path

class Component(models.Model):
    project = models.ForeignKey(Project)
    name    = models.CharField(max_length=32)
    def __unicode__(self):
        return self.name

IssuePriority = (
    (1, 'Security Vulnerability'),
    (2, 'Critical'),
    (3, 'High'),
    (4, 'Medium'),
    (5, 'Low'),
)

IssueType = (
    (1, 'Bug'),
    (2, 'Feature Request'),
    (3, 'Patch'),
)

IssueStatus = (
    (1, 'New'),
    (2, 'Assigned'),
    (3, 'Reopened'),
    (4, 'In Progress'),
    (5, 'Resolved'),
)

IssueResolution = (
    (1, 'Fixed'),
    (2, 'Invalid'),
    (3, 'Won\'t Fix'),
    (4, 'Duplicate'),
    (5, 'Works for me'),
    (6, 'Incomplete'),
)
class Bug(models.Model):
    project    = models.ForeignKey(Project)
    component  = models.ForeignKey(Component)
    priority   = models.SmallIntegerField(choices=IssuePriority, default=4)
    issue_type = models.SmallIntegerField(choices=IssueType, default=1)
    title      = models.CharField(max_length=50)

    target     = models.ForeignKey(Milestone)

    status     = models.SmallIntegerField(choices=IssueStatus, default=1)
    resolution = models.SmallIntegerField(choices=IssueResolution, default=0, blank=True)

    submitter  = models.ForeignKey(User, related_name='submitted_bugs')
    owner      = models.ForeignKey(User, related_name='owned_bugs', blank=True, null=True)

    depends    = models.ManyToManyField('self', symmetrical=False, related_name='blocks', blank=True)

    watchers   = models.ManyToManyField(User, related_name='watching_bugs', blank=True)

    @property
    def issue_type_name(self):
        return IssueType[self.issue_type-1][1]

    @property
    def priority_name(self):
        return IssuePriority[self.priority-1][1]

    @property
    def status_name(self):
        return IssueStatus[self.status-1][1]

    @property
    def resolution_name(self):
        return IssueResolution[self.resolution-1][1]

    @property
    def is_resolved(self):
        return self.status == 5

    @property
    def slug(self):
        return '#%s-%d' % (self.project.slug.upper(), self.id)

    @property
    def submitted(self):
        return self.comment_set.all()[0].date


    @property
    def url(self):
        return reverse('bug-show', args=[self.project.slug, self.id])

    def __unicode__(self):
        return self.slug

    def fromSlug(slug):
        parts = slug[1:].split('-')
        if len(parts) <> 2:
            raise ValueError('Bad slug')
        else:
            return Bug.objects.get(project__slug__iexact=parts[0], id=int(parts[1]))

class Comment(models.Model):
    bug        = models.ForeignKey(Bug)
    submitter  = models.ForeignKey(User)
    date       = models.DateTimeField(auto_now_add=True)
    text       = models.TextField()

    @property
    def formatted(self):
        return textscan(self.bug.project, self.text)
        
    class Update:
        @classmethod
        def user(self, comment):
            return comment.submitter
        
        @classmethod
        def project(self, comment):
            return comment.bug.project
            
        @classmethod
        def summary(self, comment):
            return 'Comment on bug %s' % comment.bug.slug
        
        @classmethod
        def description(self, comment):
            return 'User %s said:\n\n%s' % (comment.submitter, comment.text)
            
        @classmethod
        def url(self, comment):
            return '%s#c%d' % (comment.bug.url, comment.pk)
        
        @classmethod
        def date(self, comment):
            return comment.date

        @classmethod            
        def recipients(self, comment):
            return comment.bug.watchers.all() 
register_update_type(Comment)

def up_file(this, name):
    return 'bugfiles/%d-%d/%s' % (this.bug_id, this.comment_id, name)

class Attachment(models.Model):
    bug        = models.ForeignKey(Bug)
    comment    = models.ForeignKey(Comment)
    file       = models.FileField(upload_to = up_file, verbose_name='Attachment')
    @property
    def file_name(self):
        return os.path.basename(str(self.file))
{'fraction_non_alphanumeric': 0.11494252873563218, 'fraction_numerical': 0.010057471264367816, 'mean_word_length': 3.1556503198294243, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4700013', 'n_tokens_mistral': 3044, 'n_tokens_neox': 2896, 'n_words': 775}