<commit_before># -*- coding: utf-8 -*-

from django.contrib.auth.models import User
from django.contrib.gis.db import models as geomodels
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.db import models
from django.db.models.query import QuerySet
from django.utils.translation import ugettext_lazy as _

from model_utils.managers import PassThroughManager

from core.models import Category, Subdomain
from geozones.models import Region, Location


class MessageType():
    '''Message types'''

    TYPE_REQUEST = 1
    TYPE_RESPONSE = 2
    TYPE_INFO = 3

    TYPES_CHOICE = (
        (TYPE_REQUEST, _("request")),
        (TYPE_RESPONSE, _("response")),
        (TYPE_INFO, _("informatial"))
    )


class MessageQueryset(QuerySet):
    def list(self):
        ''' Ask only few fields for listing'''
        return self.values(
            'id', 'title', 'message', 'messageType', 'georegion', 'date_add')

    def active(self):
        return self.filter(status__gt=1, status__lt=6)

    def closed(self):
        return self.filter(status=6)


class Message(geomodels.Model):
    '''Message data'''
    #Flag values
    MESSAGE_ACTIVE = 0x1L
    MESSAGE_IMPORTANT = 0x2L
    MESSAGE_NONANONYMOUS = 0x4L
    ALLOW_FEEDBACK = 0x8L
    MESSAGE_DELETED = 0x10L
    LOCATION_VALID = 0x20L

    MESSAGE_STATUS = ((1, _('new')),
                      (2, _('unverified')),
                      (3, _('verified')),
                      (4, _('pending')),
                      (6, _('closed')))

    class Meta():
        ordering = ['-date_add']
        get_latest_by = 'date_add'
        verbose_name = _('message')
        verbose_name_plural = _('messages')

    #Managers
    objects = PassThroughManager.for_queryset_class(MessageQueryset)()

    #Mandatory fields
    title = models.CharField(
        max_length=200,
        verbose_name=_('title'),
        blank=True)
    message = models.TextField(verbose_name=_('message'))
    contact_first_name = models.CharField(
        max_length=200,
        verbose_name=_("first name"))
    contact_last_name = models.CharField(
        max_length=200,
        verbose_name=_("last name"))
    contact_mail = models.CharField(
        max_length=200,
        blank=True,
        verbose_name=_("email(s)"),
        validators=[validate_email])
    contact_phone = models.CharField(
        max_length=200,
        blank=True,
        verbose_name=_("phone(s)"))
    messageType = models.IntegerField(
        choices=MessageType.TYPES_CHOICE,
        db_column='message_type',
        verbose_name=_('message type'),)
    georegion = models.ForeignKey(Region, verbose_name=_('region'))<commit_msg>Contact mail field type is email<commit_after># -*- coding: utf-8 -*-

from django.contrib.auth.models import User
from django.contrib.gis.db import models as geomodels
from django.core.exceptions import ValidationError
from django.core.validators import validate_email
from django.db import models
from django.db.models.query import QuerySet
from django.utils.translation import ugettext_lazy as _

from model_utils.managers import PassThroughManager

from core.models import Category, Subdomain
from geozones.models import Region, Location


class MessageType():
    '''Message types'''

    TYPE_REQUEST = 1
    TYPE_RESPONSE = 2
    TYPE_INFO = 3

    TYPES_CHOICE = (
        (TYPE_REQUEST, _("request")),
        (TYPE_RESPONSE, _("response")),
        (TYPE_INFO, _("informatial"))
    )


class MessageQueryset(QuerySet):
    def list(self):
        ''' Ask only few fields for listing'''
        return self.values(
            'id', 'title', 'message', 'messageType', 'georegion', 'date_add')

    def active(self):
        return self.filter(status__gt=1, status__lt=6)

    def closed(self):
        return self.filter(status=6)


class Message(geomodels.Model):
    '''Message data'''
    #Flag values
    MESSAGE_ACTIVE = 0x1L
    MESSAGE_IMPORTANT = 0x2L
    MESSAGE_NONANONYMOUS = 0x4L
    ALLOW_FEEDBACK = 0x8L
    MESSAGE_DELETED = 0x10L
    LOCATION_VALID = 0x20L

    MESSAGE_STATUS = ((1, _('new')),
                      (2, _('unverified')),
                      (3, _('verified')),
                      (4, _('pending')),
                      (6, _('closed')))

    class Meta():
        ordering = ['-date_add']
        get_latest_by = 'date_add'
        verbose_name = _('message')
        verbose_name_plural = _('messages')

    #Managers
    objects = PassThroughManager.for_queryset_class(MessageQueryset)()

    #Mandatory fields
    title = models.CharField(
        max_length=200,
        verbose_name=_('title'),
        blank=True)
    message = models.TextField(verbose_name=_('message'))
    contact_first_name = models.CharField(
        max_length=200,
        verbose_name=_("first name"))
    contact_last_name = models.CharField(
        max_length=200,
        verbose_name=_("last name"))
    contact_mail = models.EmailField(
        max_length=200,
        blank=True,
        verbose_name=_("email(s)"))
    contact_phone = models.CharField(
        max_length=200,
        blank=True,
        verbose_name=_("phone(s)"))
    messageType = models.IntegerField(
        choices=MessageType.TYPES_CHOICE,
        db_column='message_type',
        verbose_name=_('message type'),)
    georegion = models.ForeignKey(Region, verbose_name=_('region'))
{'fraction_non_alphanumeric': 0.1149935293030135, 'fraction_numerical': 0.015159918654095026, 'mean_word_length': 2.8615274803711634, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7440847', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1664, 'n_words': 349}