<commit_before># This file is part of OpenHatch.
# Copyright (C) 2010 <NAME>
# Copyright (C) 2009, 2010 OpenHatch, Inc.
# Copyright (C) 2010 <NAME>
#
# 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/>.

# vim: set ai ts=4 sw=4 et:

import os.path
import shutil

from mysite.search.models import Project, get_image_data_scaled
import mysite.customs.models
import mysite.profile.controllers
import mysite.base.models
import mysite.base.unicode_sanity
import mysite.customs.ping_twisted

from django.db import models
from django.contrib.auth.models import User
from django.core.files.base import ContentFile
from django.conf import settings
from django.contrib.auth import SESSION_KEY, BACKEND_SESSION_KEY, load_backend
from django.core.urlresolvers import reverse
from django.db.models import Q

import datetime
import uuid
import urllib
import random
import collections
import re
import cgi
import logging
import hashlib

DEFAULT_LOCATION='Inaccessible Island'

def url2printably_short(url, CUTOFF=50):
    short_enough_pieces_so_far = []
    die_next = False
    wrappable_characters = "/"
    for url_piece in url.split(wrappable_characters):
        if die_next:
            return '/'.join(short_enough_pieces_so_far)

        # Logic: If this URL piece is longer than CUTOFF, then stop appending
        # and return.
        if len(url_piece) > CUTOFF:
            url_piece = url_piece[:CUTOFF-3] + '...'
            die_next = True
        # always append
        short_enough_pieces_so_far.append(url_piece)
    return '/'.join(short_enough_pieces_so_far)

def generate_person_photo_path(instance, filename, suffix=""):
    random_uuid = uuid.uuid4()
    return random_uuid.hex + suffix

class RepositoryCommitter(models.Model):
    """Ok, so we need to keep track of repository committers, e.g.
        <EMAIL>
    That's because when a user says, 'oy, this data you guys imported isn't
    mine', what she or he is typically saying is something like
    'Don't give me any more data from Ohloh pertaining to this dude named
    <EMAIL> checking code into F-Spot.'"""
    project = models.ForeignKey(Project)
    data_import_attempt = models.ForeignKey('DataImportAttempt')

    def committer_identifier(self):
        return self.data_import_attempt.committer_identifier

    def source(self):
        return self.data_import_attempt.source

    class Meta:
        unique_together = ('project', 'data_import_attempt')

class Person(models.Model):
    """ A human bean. """
    # {{{
    homepage_url = models.URLField(default="", blank=True)
    user = models.ForeignKey(User, unique=True)
    gotten_name_from_ohloh = models.BooleanField(default=False)
    last_polled = models.DateTimeField(default=datetime.datetime(1970, 1, 1))
    show_email = models.BooleanField(default=False)
    bio = models.TextField(blank=True)
    contact_blurb = models.TextField(blank=True)
    expand_next_steps = models.BooleanField(default=True)
    photo = models.ImageField(upload_to=
                              lambda a, b: 'static/photos/profile-photos/' +
                              generate_person_photo_path(a, b),
                              default='')
    photo_thumbnail = models.ImageField(upload_to=
                              lambda a, b: 'static/photos/profile-photos/' +
                              generate_person_photo_path(a, b, suffix="-thumbnail"),
                              default='',
                              null=True)

    photo_thumbnail_30px_wide = models.ImageField(upload_to=
                              lambda a, b: 'static/photos/profile-photos/' +
                              generate_person_photo_path(a, b, suffix="-thumbnail-30px-wide"),
                              default='', null=True)

    photo_thumbnail_20px_wide = models.ImageField(upload_to=
                              lambda a, b: 'static/photos/profile-photos/' +
                              generate_person_photo_path(a, b, suffix="-thumbnail-20px-wide"),
                              default='', null=True)

    blacklisted_repository_committers = models.ManyToManyField(RepositoryCommitter)
    dont_guess_my_location = models.BooleanField(default=False)
    location_confirmed = models.BooleanField(default=False)
    location_display_name = models.CharField(max_length=255, blank=True,
                                             verbose_name='Location')
    email_me_weekly_re_projects = models.BooleanField( default=True,
            verbose_name='Email me weekly about activity in my projects')

    irc_nick = models.CharField(max_length=30, blank=True, null=True)

    @staticmethod
    def create_dummy(first_name="", email=None, **kwargs):

        # Generate a random string to use as a username. Keep it short
        # so that it doesn't overflow the username field!
        username = uuid.uuid4().hex[:16]

        if email is None:
            email = <EMAIL>" % username
        user = User(username=username, first_name=first_name, email=email)
        data = {'user': user}

        # If the caller of create_dummy passes in a user, then we won't use the
        # user defined above
        data.update(kwargs)

        # Save the user after the update, so we don't save a new user if one
        # was never needed
        user = data['user']
        user.save()
        person = user.get_profile()

        for key, value in data.items():
            setattr(person, key, value)<commit_msg>Give profile model a latitude and longitude<commit_after># This file is part of OpenHatch.
# Copyright (C) 2010 <NAME>
# Copyright (C) 2009, 2010 OpenHatch, Inc.
# Copyright (C) 2010 <NAME>
#
# 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/>.

# vim: set ai ts=4 sw=4 et:

import os.path
import shutil

from mysite.search.models import Project, get_image_data_scaled
import mysite.customs.models
import mysite.profile.controllers
import mysite.base.models
import mysite.base.unicode_sanity
import mysite.customs.ping_twisted

from django.db import models
from django.contrib.auth.models import User
from django.core.files.base import ContentFile
from django.conf import settings
from django.contrib.auth import SESSION_KEY, BACKEND_SESSION_KEY, load_backend
from django.core.urlresolvers import reverse
from django.db.models import Q

import datetime
import uuid
import urllib
import random
import collections
import re
import cgi
import logging
import hashlib

DEFAULT_LOCATION='Inaccessible Island'

def url2printably_short(url, CUTOFF=50):
    short_enough_pieces_so_far = []
    die_next = False
    wrappable_characters = "/"
    for url_piece in url.split(wrappable_characters):
        if die_next:
            return '/'.join(short_enough_pieces_so_far)

        # Logic: If this URL piece is longer than CUTOFF, then stop appending
        # and return.
        if len(url_piece) > CUTOFF:
            url_piece = url_piece[:CUTOFF-3] + '...'
            die_next = True
        # always append
        short_enough_pieces_so_far.append(url_piece)
    return '/'.join(short_enough_pieces_so_far)

def generate_person_photo_path(instance, filename, suffix=""):
    random_uuid = uuid.uuid4()
    return random_uuid.hex + suffix

class RepositoryCommitter(models.Model):
    """Ok, so we need to keep track of repository committers, e.g.
        <EMAIL>@<EMAIL>
    That's because when a user says, 'oy, this data you guys imported isn't
    mine', what she or he is typically saying is something like
    'Don't give me any more data from Ohloh pertaining to this dude named
    <EMAIL> checking code into F-Spot.'"""
    project = models.ForeignKey(Project)
    data_import_attempt = models.ForeignKey('DataImportAttempt')

    def committer_identifier(self):
        return self.data_import_attempt.committer_identifier

    def source(self):
        return self.data_import_attempt.source

    class Meta:
        unique_together = ('project', 'data_import_attempt')

class Person(models.Model):
    """ A human bean. """
    # {{{
    homepage_url = models.URLField(default="", blank=True)
    user = models.ForeignKey(User, unique=True)
    gotten_name_from_ohloh = models.BooleanField(default=False)
    last_polled = models.DateTimeField(default=datetime.datetime(1970, 1, 1))
    show_email = models.BooleanField(default=False)
    bio = models.TextField(blank=True)
    contact_blurb = models.TextField(blank=True)
    expand_next_steps = models.BooleanField(default=True)
    photo = models.ImageField(upload_to=
                              lambda a, b: 'static/photos/profile-photos/' +
                              generate_person_photo_path(a, b),
                              default='')
    photo_thumbnail = models.ImageField(upload_to=
                              lambda a, b: 'static/photos/profile-photos/' +
                              generate_person_photo_path(a, b, suffix="-thumbnail"),
                              default='',
                              null=True)

    photo_thumbnail_30px_wide = models.ImageField(upload_to=
                              lambda a, b: 'static/photos/profile-photos/' +
                              generate_person_photo_path(a, b, suffix="-thumbnail-30px-wide"),
                              default='', null=True)

    photo_thumbnail_20px_wide = models.ImageField(upload_to=
                              lambda a, b: 'static/photos/profile-photos/' +
                              generate_person_photo_path(a, b, suffix="-thumbnail-20px-wide"),
                              default='', null=True)

    blacklisted_repository_committers = models.ManyToManyField(RepositoryCommitter)
    dont_guess_my_location = models.BooleanField(default=False)
    location_confirmed = models.BooleanField(default=False)
    location_display_name = models.CharField(max_length=255, blank=True,
                                             default=DEFAULT_LOCATION,
                                             verbose_name='Location')
    latitude = models.FloatField(null=False, default=-37.3049962)
    longitude = models.FloatField(null=False, default=-12.6790445)
    email_me_weekly_re_projects = models.BooleanField( default=True,
            verbose_name='Email me weekly about activity in my projects')

    irc_nick = models.CharField(max_length=30, blank=True, null=True)

    @staticmethod
    def create_dummy(first_name="", email=None, **kwargs):

        # Generate a random string to use as a username. Keep it short
        # so that it doesn't overflow the username field!
        username = uuid.uuid4().hex[:16]

        if email is None:
            email = <EMAIL>" % username
        user = User(username=username, first_name=first_name, email=email)
        data = {'user': user}

        # If the caller of create_dummy passes in a user, then we won't use the
        # user defined above
        data.update(kwargs)

        # Save the user after the update, so we don't save a new user if one
        # was never needed
        user = data['user']
        user.save()
        person = user.get_profile()

        for key, value in data.items():
            setattr(person, key, value)
{'fraction_non_alphanumeric': 0.08572587185725872, 'fraction_numerical': 0.008921330089213302, 'mean_word_length': 2.8070392096326025, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '779578', 'n_tokens_mistral': 3564, 'n_tokens_neox': 3394, 'n_words': 1018}