<commit_before>from django.core.cache import cache
from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import force_text
from django.views.generic.edit import BaseUpdateView
from django.http import HttpResponseRedirect


class BaseConcurency(object):
    def is_locked(obj, user):
        raise NotImplementedError(
            'subclasses of BaseConcurency must \
            provide a is_locked(obj, user) method')

    def lock(obj, user):
        raise NotImplementedError(
            'subclasses of BaseConcurency must \
            provide a lock(obj, user) method')

    def unlock(obj):
        raise NotImplementedError(
            'subclasses of BaseConcurency must \
            provide a unlock(obj, user) method')


class CacheConcurency(BaseConcurency):
    def _make_key(self, obj):
        obj_name = obj.__class__.__name__
        pk = obj.pk
        return 'concurency_' + obj_name + '_' + str(pk)

    def is_locked(self, obj, user):
        key = self._make_key(obj)
        lock_pk = cache.get(key)
        if not lock_pk:
            return False
        return user.pk != lock_pk

    def lock(self, obj, user):
        key = self._make_key(obj)
        return cache.set(key, user.pk)

    def unlock(self, obj):
        key = self._make_key(obj)
        cache.delete(key)

concurency = CacheConcurency()


class ConcurencyProtectUpdateView(object):
    def get_concurency(self):
        return concurency

    def get_concurency_url(self):
        if self.concurency_url:<commit_msg>Extension of the time lock<commit_after>from django.core.cache import cache
from django.core.exceptions import ImproperlyConfigured
from django.utils.encoding import force_text
from django.views.generic.edit import BaseUpdateView
from django.http import HttpResponseRedirect


class BaseConcurency(object):
    def is_locked(obj, user):
        raise NotImplementedError(
            'subclasses of BaseConcurency must \
            provide a is_locked(obj, user) method')

    def lock(obj, user):
        raise NotImplementedError(
            'subclasses of BaseConcurency must \
            provide a lock(obj, user) method')

    def unlock(obj):
        raise NotImplementedError(
            'subclasses of BaseConcurency must \
            provide a unlock(obj, user) method')


class CacheConcurency(BaseConcurency):
    timeout = 30 * 60  # 30 minuts * 60 seconds

    def _make_key(self, obj):
        obj_name = obj.__class__.__name__
        pk = obj.pk
        return 'concurency_' + obj_name + '_' + str(pk)

    def is_locked(self, obj, user):
        key = self._make_key(obj)
        lock_pk = cache.get(key)
        if not lock_pk:
            return False
        return user.pk != lock_pk

    def lock(self, obj, user):
        key = self._make_key(obj)
        return cache.set(key, user.pk, timeout=self.timeout)

    def unlock(self, obj):
        key = self._make_key(obj)
        cache.delete(key)

concurency = CacheConcurency()


class ConcurencyProtectUpdateView(object):
    def get_concurency(self):
        return concurency

    def get_concurency_url(self):
        if self.concurency_url:
{'fraction_non_alphanumeric': 0.08312262958280657, 'fraction_numerical': 0.0025284450063211127, 'mean_word_length': 2.67169373549884, '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': '2238445', 'n_tokens_mistral': 977, 'n_tokens_neox': 931, 'n_words': 249}