<commit_before># Libre.fm -- a free network service for sharing your music listening habits
#
# Copyright (C) 2009 Libre.fm Project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import md5

from django.contrib import admin
from django.contrib.auth.models import get_hexdigest, User
from django.contrib.auth.admin import UserAdmin
from django.template.defaultfilters import slugify
from django.db import models


RATING_CHOICES = (
    ('L', 'Love'),
    ('B', 'Ban'),
    ('S', 'Skip')
)


SOURCE_CHOICES = (
    ('P', 'Chosen by the user'),
    ('R', 'Non-personalised broadcast'),
    ('E', 'Personalised recommendation except Last.fm'),
    ('L', 'Last.fm'),
    ('U', 'Unknown')
)


class GobblerUser(User):

    def set_password(self, raw_password):
        print "set password"
        import random
        algo = 'sha1'
        salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5]
        hsh = get_hexdigest(algo, salt, raw_password)
        self.password = <PASSWORD>' % (algo, salt, hsh)
        pwd,created = Md5Password.objects.get_or_create(user=self)
        pwd.password = <PASSWORD>(raw_password).hex<PASSWORD>()
        pwd.save()

    def get_md5(self):
        pwd = Md5Password.objects.get(user=self)
        return pwd.password

    class Meta:
        proxy = True

admin.site.register(GobblerUser, UserAdmin)


class Artist(models.Model):
    name = models.CharField(max_length=256, unique=True)
    slug = models.SlugField(unique=True, editable=False)

    def get_absolute_url(self):
        return "/music/%s/" % (self.slug,)

    def save(self, force_insert=False, force_update=False):
        self.slug = slugify(self.name)
        super(Artist, self).save(force_insert, force_update)

    def __unicode__(self):
        return self.name


class Album(models.Model):
    name = models.CharField(max_length=256)
    artist = models.ForeignKey(Artist)
    slug = models.SlugField(editable=False)

    def get_absolute_url(self):
        return "%s%s/" % (self.artist.get_absolute_url(), self.slug)

    def save(self, force_insert=False, force_update=False):
        self.slug = slugify(self.name)
        super(Album, self).save(force_insert, force_update)

    def __unicode__(self):
        return "%s by %s" % (self.name, self.artist)

    class Meta:
        unique_together = (('artist', 'name'), ('artist', 'slug'))<commit_msg>Fix max_length of a field.  I blame MySQL.<commit_after># Libre.fm -- a free network service for sharing your music listening habits
#
# Copyright (C) 2009 Libre.fm Project
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import md5

from django.contrib import admin
from django.contrib.auth.models import get_hexdigest, User
from django.contrib.auth.admin import UserAdmin
from django.template.defaultfilters import slugify
from django.db import models


RATING_CHOICES = (
    ('L', 'Love'),
    ('B', 'Ban'),
    ('S', 'Skip')
)


SOURCE_CHOICES = (
    ('P', 'Chosen by the user'),
    ('R', 'Non-personalised broadcast'),
    ('E', 'Personalised recommendation except Last.fm'),
    ('L', 'Last.fm'),
    ('U', 'Unknown')
)


class GobblerUser(User):

    def set_password(self, raw_password):
        print "set password"
        import random
        algo = 'sha1'
        salt = get_hexdigest(algo, str(random.random()), str(random.random()))[:5]
        hsh = get_hexdigest(algo, salt, raw_password)
        self.password = <PASSWORD>' % (algo, salt, hsh)
        pwd,created = Md5Password.objects.get_or_create(user=self)
        pwd.password = md5.new(raw_password).hex<PASSWORD>()
        pwd.save()

    def get_md5(self):
        pwd = Md5Password.objects.get(user=self)
        return pwd.password

    class Meta:
        proxy = True

admin.site.register(GobblerUser, UserAdmin)


class Artist(models.Model):
    name = models.CharField(max_length=255, unique=True)
    slug = models.SlugField(unique=True, editable=False)

    def get_absolute_url(self):
        return "/music/%s/" % (self.slug,)

    def save(self, force_insert=False, force_update=False):
        self.slug = slugify(self.name)
        super(Artist, self).save(force_insert, force_update)

    def __unicode__(self):
        return self.name


class Album(models.Model):
    name = models.CharField(max_length=256)
    artist = models.ForeignKey(Artist)
    slug = models.SlugField(editable=False)

    def get_absolute_url(self):
        return "%s%s/" % (self.artist.get_absolute_url(), self.slug)

    def save(self, force_insert=False, force_update=False):
        self.slug = slugify(self.name)
        super(Album, self).save(force_insert, force_update)

    def __unicode__(self):
        return "%s by %s" % (self.name, self.artist)

    class Meta:
        unique_together = (('artist', 'name'), ('artist', 'slug'))
{'fraction_non_alphanumeric': 0.11785239361702128, 'fraction_numerical': 0.00581781914893617, 'mean_word_length': 3.4836065573770494, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1521885', 'n_tokens_mistral': 1908, 'n_tokens_neox': 1830, 'n_words': 552}