<commit_before>import os
import re
from datetime import datetime

from django.contrib.auth.models import User
from django.db import models
from django.db.models import Q

from reviewboard.diffviewer.models import DiffSet, DiffSetHistory, FileDiff
from reviewboard.scmtools.models import Repository
from reviewboard.utils.fields import ModificationTimestampField
from utils.templatetags.htmlutils import thumbnail


class Group(models.Model):
    name = models.CharField(maxlength=64)
    display_name = models.CharField(maxlength=64)
    mailing_list = models.EmailField(blank=True)
    users = models.ManyToManyField(User, core=False, blank=True,
                                   filter_interface=models.HORIZONTAL)

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return "/groups/%s/" % self.name

    class Admin:
        list_display = ('name', 'display_name', 'mailing_list')
        ordering = ['name']


class Screenshot(models.Model):
    caption = models.CharField(maxlength=256, blank=True)
    draft_caption = models.CharField(maxlength=256, blank=True)
    image = models.ImageField(upload_to=os.path.join('images', 'uploaded'))

    def thumb(self):
        url = thumbnail(self.image)
        return '<img src="%s" alt="%s" />' % (url, self.caption)
    thumb.allow_tags = True

    def __str__(self):
        return "%s (%s)" % (self.caption, self.image)

    def get_absolute_url(self):
        try:
            review = self.review_request.all()[0]
        except IndexError:
            review = self.inactive_review_request.all()[0]
        return "/r/%s/s/%s/" % (review.id, self.id)

    class Admin:
        list_display = ('thumb', 'caption', 'image')
        list_display_links = ('thumb', 'caption')


class ReviewRequest(models.Model):
    STATUSES = (
        ('P', 'Pending Review'),
        ('S', 'Submitted'),
        ('D', 'Discarded'),
    )

    submitter = models.ForeignKey(User, verbose_name="Submitter")
    time_added = models.DateTimeField("Time Added", default=datetime.now)
    last_updated = ModificationTimestampField("Last Updated")
    status = models.CharField(maxlength=1, choices=STATUSES)
    public = models.BooleanField("Public", default=False)
    changenum = models.PositiveIntegerField("Change Number", blank=True,
                                            null=True, db_index=True)
    repository = models.ForeignKey(Repository)
    email_message_id = models.CharField("E-Mail Message ID", maxlength=255,
                                        blank=True, null=True)
    time_emailed = models.DateTimeField("Time E-Mailed", null=True,
                                        default=None, blank=True)

    summary = models.CharField("Summary", maxlength=300, core=True)
    description = models.TextField("Description")
    testing_done = models.TextField("Testing Done")
    bugs_closed = models.CommaSeparatedIntegerField("Bugs Closed",
                                                    maxlength=300, blank=True)
    diffset_history = models.ForeignKey(DiffSetHistory,
                                        verbose_name='diff set history',
                                        blank=True)
    branch = models.CharField("Branch", maxlength=300, blank=True)
    target_groups = models.ManyToManyField(Group, verbose_name="Target Groups",
                                           core=False, blank=True)
    target_people = models.ManyToManyField(User, verbose_name="Target People",<commit_msg>It's annoying not being able to save a review request object in the admin interface that has a blank description or testing done. Set blank=True.<commit_after>import os
import re
from datetime import datetime

from django.contrib.auth.models import User
from django.db import models
from django.db.models import Q

from reviewboard.diffviewer.models import DiffSet, DiffSetHistory, FileDiff
from reviewboard.scmtools.models import Repository
from reviewboard.utils.fields import ModificationTimestampField
from utils.templatetags.htmlutils import thumbnail


class Group(models.Model):
    name = models.CharField(maxlength=64)
    display_name = models.CharField(maxlength=64)
    mailing_list = models.EmailField(blank=True)
    users = models.ManyToManyField(User, core=False, blank=True,
                                   filter_interface=models.HORIZONTAL)

    def __str__(self):
        return self.name

    def get_absolute_url(self):
        return "/groups/%s/" % self.name

    class Admin:
        list_display = ('name', 'display_name', 'mailing_list')
        ordering = ['name']


class Screenshot(models.Model):
    caption = models.CharField(maxlength=256, blank=True)
    draft_caption = models.CharField(maxlength=256, blank=True)
    image = models.ImageField(upload_to=os.path.join('images', 'uploaded'))

    def thumb(self):
        url = thumbnail(self.image)
        return '<img src="%s" alt="%s" />' % (url, self.caption)
    thumb.allow_tags = True

    def __str__(self):
        return "%s (%s)" % (self.caption, self.image)

    def get_absolute_url(self):
        try:
            review = self.review_request.all()[0]
        except IndexError:
            review = self.inactive_review_request.all()[0]
        return "/r/%s/s/%s/" % (review.id, self.id)

    class Admin:
        list_display = ('thumb', 'caption', 'image')
        list_display_links = ('thumb', 'caption')


class ReviewRequest(models.Model):
    STATUSES = (
        ('P', 'Pending Review'),
        ('S', 'Submitted'),
        ('D', 'Discarded'),
    )

    submitter = models.ForeignKey(User, verbose_name="Submitter")
    time_added = models.DateTimeField("Time Added", default=datetime.now)
    last_updated = ModificationTimestampField("Last Updated")
    status = models.CharField(maxlength=1, choices=STATUSES)
    public = models.BooleanField("Public", default=False)
    changenum = models.PositiveIntegerField("Change Number", blank=True,
                                            null=True, db_index=True)
    repository = models.ForeignKey(Repository)
    email_message_id = models.CharField("E-Mail Message ID", maxlength=255,
                                        blank=True, null=True)
    time_emailed = models.DateTimeField("Time E-Mailed", null=True,
                                        default=None, blank=True)

    summary = models.CharField("Summary", maxlength=300, core=True)
    description = models.TextField("Description", blank=True)
    testing_done = models.TextField("Testing Done", blank=True)
    bugs_closed = models.CommaSeparatedIntegerField("Bugs Closed",
                                                    maxlength=300, blank=True)
    diffset_history = models.ForeignKey(DiffSetHistory,
                                        verbose_name='diff set history',
                                        blank=True)
    branch = models.CharField("Branch", maxlength=300, blank=True)
    target_groups = models.ManyToManyField(Group, verbose_name="Target Groups",
                                           core=False, blank=True)
    target_people = models.ManyToManyField(User, verbose_name="Target People",
{'fraction_non_alphanumeric': 0.11027359017308766, 'fraction_numerical': 0.006979341150195421, 'mean_word_length': 2.75721027792344, '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': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '303543', 'n_tokens_mistral': 2000, 'n_tokens_neox': 1924, 'n_words': 427}