<commit_before>from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from jsonfield import JSONField
from oauth2_provider.models import AbstractApplication
from autoslug import AutoSlugField
from openbudget.apps.accounts.models import Account
from openbudget.commons.mixins.models import TimeStampedModel, UUIDModel, ClassMethodMixin


class ProjectManager(models.Manager):
    """Exposes the related_map method for more efficient bulk select queries."""

    def related_map(self):
        return self.select_related()


class Project(AbstractApplication, TimeStampedModel, UUIDModel, ClassMethodMixin):
    """API Project object, comprised of initial data + some meta data."""

    LABEL_CHOICES = (
        ('public', _('For the General Public')),
        ('developers', _('For Developers'))
    )

    objects = ProjectManager()

    author = models.ForeignKey(
        Account,
        related_name='author_projects'
    )
    description = models.TextField(
        _('Description'),
        help_text=_('Provide a short description of this project')
    )
    label = models.CharField(
        max_length=50,
        choices=LABEL_CHOICES,
        default=LABEL_CHOICES[0][0],
        help_text=_('Set your preferred language for the app')
    )
    featured = models.BooleanField(
        _('Featured'),
        default=False,
    )
    screenshot = models.URLField(
        _('Screenshot'),
        blank=True,
        null=True,
        help_text=_('A screenshot for this visualization')
    )
    slug = AutoSlugField(
        db_index=True,
        populate_from='name',
        unique=True
    )
    config = JSONField(
        _('Data and configuration'),
        blank=True,
        null=True,
        help_text=_('JSON serialized configuration object of the visualization.')
    )

    @models.permalink
    def get_absolute_url(self):
        return ('project-detail', [self.uuid])

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = _('Project')
        verbose_name_plural = _('Projects')


class StateManager(models.Manager):
    """Exposes the related_map method for more efficient bulk select queries."""

    def related_map(self):
        return self.select_related()


class State(TimeStampedModel, UUIDModel, ClassMethodMixin):
    """State objects describe saved states of specific projects."""

    objects = StateManager()

    project = models.ForeignKey(
        Project,
        related_name='states'
    )
    author = models.ForeignKey(
        Account,
        related_name='saved_states'
    )
    screenshot = models.URLField(
        _('Screenshot'),
        blank=True,
        null=True,
        help_text=_('A screenshot for this state')
    )
    config = JSONField(
        _('Data and configuration'),
        blank=True,
        null=True,
        help_text=_('JSON serialized configuration object of the state.')
    )

    @models.permalink
    def get_absolute_url(self):
        return ('state-detail', [self.uuid])

    def __unicode__(self):
        return self.project.name + u'state: ' + unicode(self.last_modified)

    class Meta:
        verbose_name = _('State')
        verbose_name_plural = _('States')<commit_msg>Fixed get_absolute_url methods to use the names of api urls; Changed uuid to slug in Project.get_absolute_url<commit_after>from django.conf import settings
from django.db import models
from django.utils.translation import ugettext_lazy as _
from jsonfield import JSONField
from oauth2_provider.models import AbstractApplication
from autoslug import AutoSlugField
from openbudget.apps.accounts.models import Account
from openbudget.commons.mixins.models import TimeStampedModel, UUIDModel, ClassMethodMixin


class ProjectManager(models.Manager):
    """Exposes the related_map method for more efficient bulk select queries."""

    def related_map(self):
        return self.select_related()


class Project(AbstractApplication, TimeStampedModel, UUIDModel, ClassMethodMixin):
    """API Project object, comprised of initial data + some meta data."""

    LABEL_CHOICES = (
        ('public', _('For the General Public')),
        ('developers', _('For Developers'))
    )

    objects = ProjectManager()

    author = models.ForeignKey(
        Account,
        related_name='author_projects'
    )
    description = models.TextField(
        _('Description'),
        help_text=_('Provide a short description of this project')
    )
    label = models.CharField(
        max_length=50,
        choices=LABEL_CHOICES,
        default=LABEL_CHOICES[0][0],
        help_text=_('Set your preferred language for the app')
    )
    featured = models.BooleanField(
        _('Featured'),
        default=False,
    )
    screenshot = models.URLField(
        _('Screenshot'),
        blank=True,
        null=True,
        help_text=_('A screenshot for this visualization')
    )
    slug = AutoSlugField(
        db_index=True,
        populate_from='name',
        unique=True
    )
    config = JSONField(
        _('Data and configuration'),
        blank=True,
        null=True,
        help_text=_('JSON serialized configuration object of the visualization.')
    )

    @models.permalink
    def get_absolute_url(self):
        return 'project_detail', [self.slug]

    def __unicode__(self):
        return self.name

    class Meta:
        verbose_name = _('Project')
        verbose_name_plural = _('Projects')


class StateManager(models.Manager):
    """Exposes the related_map method for more efficient bulk select queries."""

    def related_map(self):
        return self.select_related()


class State(TimeStampedModel, UUIDModel, ClassMethodMixin):
    """State objects describe saved states of specific projects."""

    objects = StateManager()

    project = models.ForeignKey(
        Project,
        related_name='states'
    )
    author = models.ForeignKey(
        Account,
        related_name='saved_states'
    )
    screenshot = models.URLField(
        _('Screenshot'),
        blank=True,
        null=True,
        help_text=_('A screenshot for this state')
    )
    config = JSONField(
        _('Data and configuration'),
        blank=True,
        null=True,
        help_text=_('JSON serialized configuration object of the state.')
    )

    @models.permalink
    def get_absolute_url(self):
        return 'state_detail', [self.uuid]

    def __unicode__(self):
        return self.project.name + u'state: ' + unicode(self.last_modified)

    class Meta:
        verbose_name = _('State')
        verbose_name_plural = _('States')
{'fraction_non_alphanumeric': 0.09626955475330927, 'fraction_numerical': 0.0015042117930204573, 'mean_word_length': 2.8905792861322412, 'pattern_counts': {'":': 0, '<': 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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1667595', 'n_tokens_mistral': 1888, 'n_tokens_neox': 1842, 'n_words': 478}