<commit_before># -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals

from django.core.urlresolvers import reverse
from django.http import QueryDict

from .models import Nut
from .utils import generate_nonce, get_user_ip


class SQRLInitialization(object):
    def __init__(self, request, nut=None):
        self.request = request
        if nut is not None:
            self.nut = nut

    def get_session_key(self):
        session_key = self.request.session.session_key

        if session_key is None:
            self.request.session.save()
            session_key = self.request.session.session_key

        return session_key

    @property
    def nut(self):
        if hasattr(self, '_nut'):
            return self._nut

        self._nut = Nut.objects.replace_or_create(<commit_msg>fixed a bug of how session is initialized. now using create() vs save()<commit_after># -*- coding: utf-8 -*-
from __future__ import print_function, unicode_literals

from django.core.urlresolvers import reverse
from django.http import QueryDict

from .models import Nut
from .utils import generate_nonce, get_user_ip


class SQRLInitialization(object):
    def __init__(self, request, nut=None):
        self.request = request
        if nut is not None:
            self.nut = nut

    def get_session_key(self):
        session_key = self.request.session.session_key

        if session_key is None:
            self.request.session.create()
            session_key = self.request.session.session_key

        return session_key

    @property
    def nut(self):
        if hasattr(self, '_nut'):
            return self._nut

        self._nut = Nut.objects.replace_or_create(
{'fraction_non_alphanumeric': 0.08068315665488811, 'fraction_numerical': 0.001177856301531213, 'mean_word_length': 2.6934782608695653, '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': '3457586', 'n_tokens_mistral': 490, 'n_tokens_neox': 474, 'n_words': 137}