<commit_before># -*- coding: UTF-8 -*-
from django.db import models

from random import choice

class ShortUrl(models.Model):
    id = models.CharField(max_length=6, primary_key=True)
    url = models.URLField(verify_exists=False, db_index=True)
    title = models.CharField(max_length=200)
    created = models.DateTimeField(auto_now_add=True)

    @classmethod
    def new_url(cls, url, title=''):
        character_set = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'
        def r():
            return ''.join(choice(character_set) for x in range(6))

        i = ShortUrl()
        i.url = url
        i.title = title
        while True:
            i.id = r()
            try:
                i.save()
            except Exception, e:
                print e
            else:
                break
        return i<commit_msg>poiché imposto la pk a mano devo forzare il salvataggio per prevenire un Update<commit_after># -*- coding: UTF-8 -*-
from django.db import models

from datetime import datetime
from random import choice

character_set = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz'

class ShortUrl(models.Model):
    id = models.CharField(max_length=6, primary_key=True)
    url = models.URLField(verify_exists=False, db_index=True)
    title = models.CharField(max_length=200)
    created = models.DateTimeField(auto_now_add=True)

    @classmethod
    def new_url(cls, url, title='', id=None):
        def r():
            return ''.join(choice(character_set) for x in range(6))

        i = ShortUrl()
        i.url = url
        i.title = title
        i.created = datetime.now()
        if id is None:
            while True:
                i.id = r()
                try:
                    i.save(force_insert=True)
                except Exception, e:
                    print e
                else:
                    break
        else:
            i.id = id
            i.save(force_insert=True)
        return i
{'fraction_non_alphanumeric': 0.09278870398386284, 'fraction_numerical': 0.016137165910237016, 'mean_word_length': 1.9969788519637461, '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': '5140085', 'n_tokens_mistral': 641, 'n_tokens_neox': 600, 'n_words': 145}