<commit_before>import urllib
from django.conf import settings
from django.contrib.gis.db import models
from django.contrib.gis.measure import D
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db.models import F, Q
from django.urls import reverse
from django.utils import timezone

from utils import bounds_from_box
import utils
from .changes import summarize_subscription_updates
from site_config import site_config

from base64 import b64encode
from datetime import datetime
import os
import pickle


def make_token():
    """
    :returns: (str) an authentication token
    """
    return b64encode(os.urandom(32)).decode("utf-8")


def prettify_point(pt):
    return utils.prettify_lat(pt.y) + ", " + utils.prettify_long(pt.x)


def poly_bounds(poly):
    bounds = poly.envelope.tuple[0]
    return bounds[2], bounds[0]


class UserProfile(models.Model):
    """
    Extension to the built-in User class that adds a token for allowing
    password-less login from email links.

    For now, we can get away with this, because we won't be handling any
    sensitive data.
    """
    user = models.OneToOneField(settings.AUTH_USER_MODEL,
                                on_delete=models.CASCADE,
                                related_name="profile")
    token = models.CharField(max_length=64, default=make_token)
    language = models.CharField(max_length=10, default="en")
    nickname = models.CharField(max_length=128,
                                help_text="What do you prefer to be called?")
    site_name = models.CharField(
        help_text="The site where the user created his/her account",
        db_index=True,
        max_length=64,
        default="somerville.cornerwise.org")

    @property
    def addressal(self):
        return self.nickname or self.user.first_name

    def activate(self):
        """Activates a user account.
        """
        if not self.user.is_active:
            self.user.is_active = True
            self.token = make_token()
            self.user.save()
            self.save()

    def deactivate(self):
        if not self.user.is_active:
            return

        self.user.is_active = False
        self.token = make_token()
        self.user.save()
        self.save()

        self.deactivate_subscriptions()
<commit_msg>Profile.activate() / .deactivate() returns success or failure<commit_after>import urllib
from django.conf import settings
from django.contrib.gis.db import models
from django.contrib.gis.measure import D
from django.core.exceptions import ValidationError
from django.core.validators import MaxValueValidator, MinValueValidator
from django.db.models import F, Q
from django.urls import reverse
from django.utils import timezone

from utils import bounds_from_box
import utils
from .changes import summarize_subscription_updates
from site_config import site_config

from base64 import b64encode
from datetime import datetime
import os
import pickle


def make_token():
    """
    :returns: (str) an authentication token
    """
    return b64encode(os.urandom(32)).decode("utf-8")


def prettify_point(pt):
    return utils.prettify_lat(pt.y) + ", " + utils.prettify_long(pt.x)


def poly_bounds(poly):
    bounds = poly.envelope.tuple[0]
    return bounds[2], bounds[0]


class UserProfile(models.Model):
    """
    Extension to the built-in User class that adds a token for allowing
    password-less login from email links.

    For now, we can get away with this, because we won't be handling any
    sensitive data.
    """
    user = models.OneToOneField(settings.AUTH_USER_MODEL,
                                on_delete=models.CASCADE,
                                related_name="profile")
    token = models.CharField(max_length=64, default=make_token)
    language = models.CharField(max_length=10, default="en")
    nickname = models.CharField(max_length=128,
                                help_text="What do you prefer to be called?")
    site_name = models.CharField(
        help_text="The site where the user created his/her account",
        db_index=True,
        max_length=64,
        default="somerville.cornerwise.org")

    @property
    def addressal(self):
        return self.nickname or self.user.first_name

    def activate(self):
        """Activates a user account.
        """
        if not self.user.is_active:
            self.user.is_active = True
            self.token = make_token()
            self.user.save()
            self.save()
            return True
        return False

    def deactivate(self):
        if not self.user.is_active:
            return False

        self.user.is_active = False
        self.token = make_token()
        self.user.save()
        self.save()

        self.deactivate_subscriptions()
        return True

{'fraction_non_alphanumeric': 0.08540852027166083, 'fraction_numerical': 0.008643753858818687, 'mean_word_length': 2.684609552691433, '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': '3060938', 'n_tokens_mistral': 1416, 'n_tokens_neox': 1371, 'n_words': 382}