<commit_before># -*- coding: UTF-8 -*-
from django.db import models
import settings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django_urls import UrlMixin
import tagging
import tagging.fields

class Category(models.Model):
    name = models.CharField(max_length = 100)
    description = models.TextField(blank = True)

    def __unicode__(self):
        return self.name

POST_STATUS = (('P', 'Pubblicato'), ('D', 'Bozza'))

class PostManager(models.Manager):
    def published(self):
        return self.all().filter(status = 'P').order_by('-date')

class Post(models.Model):
    date = models.DateTimeField(db_index=True)
    author = models.ForeignKey(User)
    status = models.CharField(max_length = 1, default = 'P', choices = POST_STATUS)
    allow_comments = models.BooleanField()
    tags = tagging.fields.TagField()
    category = models.ForeignKey(Category)

    objects = PostManager()

    def __unicode__(self):
        return "Post of %s on %s" % (self.author, self.date)

    class Meta:
        ordering = ('-date',)
        get_latest_by = 'date'

    def is_published(self):
        return self.status == 'P'

    def content(self, lang, fallback=True):
        """
        Ritorna il PostContent nella lingua specificata.
        Se il PostContent non esiste e fallback è False viene sollevata
        l'eccezione ObjectDoesNotExist. Se fallback è True viene prima
        ricercato il PostContent nella lingua di default del blog, poi in
        quella del sito, se non esiste viene ritornato il primo PostContent
        esistente, se non esiste neanche questo viene sollevata l'eccezione
        ObjectDoesNotExist.
        """
        contents = dict((c.language, c) for c in self.postcontent_set.exclude(headline=''))
        if not contents:
            raise PostContent.DoesNotExist()
        try:
            return contents[lang]
        except KeyError:
            if not fallback:
                raise PostContent.DoesNotExist()

        try:
            c = contents[settings.MICROBLOG_DEFAULT_LANGUAGE]
            c = contents[settings.LANGUAGES[0][0]]
        except KeyError:
            c = contents.values()[0]<commit_msg>bug fixing, LANGUAGES e' un attributo del settings globale<commit_after># -*- coding: UTF-8 -*-
from django.conf import settings as dsettings
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.db import models

from django_urls import UrlMixin
import tagging
import tagging.fields

import settings

class Category(models.Model):
    name = models.CharField(max_length = 100)
    description = models.TextField(blank = True)

    def __unicode__(self):
        return self.name

POST_STATUS = (('P', 'Pubblicato'), ('D', 'Bozza'))

class PostManager(models.Manager):
    def published(self):
        return self.all().filter(status = 'P').order_by('-date')

class Post(models.Model):
    date = models.DateTimeField(db_index=True)
    author = models.ForeignKey(User)
    status = models.CharField(max_length = 1, default = 'P', choices = POST_STATUS)
    allow_comments = models.BooleanField()
    tags = tagging.fields.TagField()
    category = models.ForeignKey(Category)

    objects = PostManager()

    def __unicode__(self):
        return "Post of %s on %s" % (self.author, self.date)

    class Meta:
        ordering = ('-date',)
        get_latest_by = 'date'

    def is_published(self):
        return self.status == 'P'

    def content(self, lang, fallback=True):
        """
        Ritorna il PostContent nella lingua specificata.
        Se il PostContent non esiste e fallback è False viene sollevata
        l'eccezione ObjectDoesNotExist. Se fallback è True viene prima
        ricercato il PostContent nella lingua di default del blog, poi in
        quella del sito, se non esiste viene ritornato il primo PostContent
        esistente, se non esiste neanche questo viene sollevata l'eccezione
        ObjectDoesNotExist.
        """
        contents = dict((c.language, c) for c in self.postcontent_set.exclude(headline=''))
        if not contents:
            raise PostContent.DoesNotExist()
        try:
            return contents[lang]
        except KeyError:
            if not fallback:
                raise PostContent.DoesNotExist()

        try:
            c = contents[settings.MICROBLOG_DEFAULT_LANGUAGE]
            c = contents[dsettings.LANGUAGES[0][0]]
        except KeyError:
            c = contents.values()[0]
{'fraction_non_alphanumeric': 0.09623893805309734, 'fraction_numerical': 0.0035398230088495575, 'mean_word_length': 2.8248730964467006, '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': '4968517', 'n_tokens_mistral': 1327, 'n_tokens_neox': 1295, 'n_words': 379}