<commit_before>from django.contrib.gis.db import models
from django.contrib.gis import geos, measure
from django_countries import CountryField
from django.utils.safestring import mark_safe
from datetime import datetime

class Venue(models.Model):
    name = models.CharField(max_length=255)
    street_address = models.TextField()
    country = CountryField()
    location = models.PointField(blank=True)

    objects = models.GeoManager()

    def __init__(self, *args, **kwargs):
        super(Venue, self).__init__(*args, **kwargs)
        if self.location is None:
            longitude = float(kwargs.get('longitude', '0'))
            latitude = float(kwargs.get('latitude', '0'))
            self.location = geos.Point(longitude, latitude)

    @property
    def latitude(self):
        return self.location.y

    @latitude.setter
    def latitude(self, value):
        self.location.y = value

    @property
    def longitude(self):
        return self.location.x

    @longitude.setter
    def longitude(self, value):
        self.location.x = value

def _upcoming(qs, sort, include_private):
    resultset = qs.filter(start__gte = datetime.now()).order_by(sort)
    if not include_private:
        resultset = resultset.filter(public=True)
    return resultset

class Event(models.Model):
    name = models.CharField(max_length = 255)
    description = models.TextField()
    event_url = models.URLField(blank = True)
    venue = models.ForeignKey(Venue)
    start = models.DateTimeField(null = True, blank = True)
    end = models.DateTimeField(null = True, blank = True)
    source_id = models.CharField(max_length = 255, blank = True)
    organiser_email = models.EmailField(max_length = 255)
    campaign = models.ForeignKey('Campaign', null = True)
    kind = models.ForeignKey('EventKind', null = True)
    verified = models.BooleanField(default = False)
    official = models.BooleanField(default = False)
    public = models.BooleanField(default = False)

    objects = models.GeoManager()

    @classmethod
    def upcoming(self, sort='start', include_private=False):
        return _upcoming(self.objects, sort, include_private)

    @classmethod
    def near(self, latitude, longitude, sort='start', include_private=False):
        point = geos.Point(float(longitude), float(latitude))
        return _upcoming(self.objects, sort, include_private).filter(venue__location__distance_lte=(point, measure.D(mi=20)))

class Campaign(models.Model):
    name = models.CharField(max_length = 255)
    description = models.TextField()
    slug = models.SlugField()
    start = models.DateField()
    end = models.DateField()

class EventKind(models.Model):
    name = models.CharField(max_length = 255)
    description = models.TextField()
    slug = models.SlugField()

    def __unicode__(self):
        return mark_safe(u'<strong>%s</strong> <span>%s</span>' % (self.name, self.description))<commit_msg>Adding in __unicode__ methods for each model - so we can recognise them in the django admin<commit_after>from django.contrib.gis.db import models
from django.contrib.gis import geos, measure
from django_countries import CountryField
from django.utils.safestring import mark_safe
from datetime import datetime

class Venue(models.Model):
    name = models.CharField(max_length=255)
    street_address = models.TextField()
    country = CountryField()
    location = models.PointField(blank=True)

    objects = models.GeoManager()

    def __init__(self, *args, **kwargs):
        super(Venue, self).__init__(*args, **kwargs)
        if self.location is None:
            longitude = float(kwargs.get('longitude', '0'))
            latitude = float(kwargs.get('latitude', '0'))
            self.location = geos.Point(longitude, latitude)

    def __unicode__(self):
        return '%s - %s, %s' % (self.name, self.street_address,  self.country)

    @property
    def latitude(self):
        return self.location.y

    @latitude.setter
    def latitude(self, value):
        self.location.y = value

    @property
    def longitude(self):
        return self.location.x

    @longitude.setter
    def longitude(self, value):
        self.location.x = value

def _upcoming(qs, sort, include_private):
    resultset = qs.filter(start__gte = datetime.now()).order_by(sort)
    if not include_private:
        resultset = resultset.filter(public=True)
    return resultset

class Event(models.Model):
    name = models.CharField(max_length = 255)
    description = models.TextField()
    event_url = models.URLField(blank = True)
    venue = models.ForeignKey(Venue)
    start = models.DateTimeField(null = True, blank = True)
    end = models.DateTimeField(null = True, blank = True)
    source_id = models.CharField(max_length = 255, blank = True)
    organiser_email = models.EmailField(max_length = 255)
    campaign = models.ForeignKey('Campaign', null = True, blank=True)
    kind = models.ForeignKey('EventKind', null = True)
    verified = models.BooleanField(default = False)
    official = models.BooleanField(default = False)
    public = models.BooleanField(default = False)

    objects = models.GeoManager()

    def __unicode__(self):
        return self.name

    @classmethod
    def upcoming(self, sort='start', include_private=False):
        return _upcoming(self.objects, sort, include_private)

    @classmethod
    def near(self, latitude, longitude, sort='start', include_private=False):
        point = geos.Point(float(longitude), float(latitude))
        return _upcoming(self.objects, sort, include_private).filter(venue__location__distance_lte=(point, measure.D(mi=20)))

class Campaign(models.Model):
    name = models.CharField(max_length = 255)
    description = models.TextField()
    slug = models.SlugField()
    start = models.DateField()
    end = models.DateField()

    def __unicode__(self):
        return '%s - %s to %s' % (self.name, self.start, self.end)

class EventKind(models.Model):
    name = models.CharField(max_length = 255)
    description = models.TextField()
    slug = models.SlugField()

    def __unicode__(self):
        return mark_safe(u'%s' % (self.name))
{'fraction_non_alphanumeric': 0.1149706457925636, 'fraction_numerical': 0.007175472928897586, 'mean_word_length': 3.5837070254110612, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '3076622', 'n_tokens_mistral': 1881, 'n_tokens_neox': 1804, 'n_words': 418}