Skip to content

Commit

Permalink
Merge branch 'main' into fix-6900
Browse files Browse the repository at this point in the history
  • Loading branch information
evyncke authored Mar 17, 2024
2 parents 46e1c7e + 1a9a111 commit b31e446
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 41 deletions.
8 changes: 4 additions & 4 deletions ietf/meeting/tests_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8598,7 +8598,7 @@ def test_session_attendance(self):
self.assertEqual(r.status_code, 200)
self.assertContains(r, '3 attendees')
for person in persons:
self.assertContains(r, person.name)
self.assertContains(r, person.plain_name())

# Test for the "I was there" button.
def _test_button(person, expected):
Expand All @@ -8618,14 +8618,14 @@ def _test_button(person, expected):
# attempt to POST anyway is ignored
r = self.client.post(attendance_url)
self.assertEqual(r.status_code, 200)
self.assertNotContains(r, persons[3].name)
self.assertNotContains(r, persons[3].plain_name())
self.assertEqual(session.attended_set.count(), 3)
# button is shown, and POST is accepted
meeting.importantdate_set.update(name_id='revsub',date=date_today() + datetime.timedelta(days=20))
_test_button(persons[3], True)
r = self.client.post(attendance_url)
self.assertEqual(r.status_code, 200)
self.assertContains(r, persons[3].name)
self.assertContains(r, persons[3].plain_name())
self.assertEqual(session.attended_set.count(), 4)

# When the meeting is finalized, a bluesheet file is generated,
Expand All @@ -8639,7 +8639,7 @@ def _test_button(person, expected):
text = doc.text()
self.assertIn('4 attendees', text)
for person in persons:
self.assertIn(person.name, text)
self.assertIn(person.plain_name(), text)
r = self.client.get(session_url)
self.assertContains(r, doc.get_href())
self.assertNotContains(r, attendance_url)
Expand Down
79 changes: 42 additions & 37 deletions ietf/utils/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

import datetime

from decorator import decorator, decorate
from functools import wraps

from django.conf import settings
Expand All @@ -20,25 +19,29 @@
from ietf.person.models import Person, PersonalApiKey, PersonApiKeyEvent
from ietf.utils import log

@decorator
def skip_coverage(f, *args, **kwargs):
if settings.TEST_CODE_COVERAGE_CHECKER:
set_coverage_checking(False)
result = f(*args, **kwargs)
set_coverage_checking(True)
return result
else:
return f(*args, **kwargs)

@decorator
def person_required(f, request, *args, **kwargs):
if not request.user.is_authenticated:
raise ValueError("The @person_required decorator should be called after @login_required.")
try:
request.user.person
except Person.DoesNotExist:
return render(request, 'registration/missing_person.html')
return f(request, *args, **kwargs)
def skip_coverage(f):
@wraps(f)
def _wrapper(*args, **kwargs):
if settings.TEST_CODE_COVERAGE_CHECKER:
set_coverage_checking(False)
result = f(*args, **kwargs)
set_coverage_checking(True)
return result
else:
return f(*args, **kwargs)
return _wrapper

def person_required(f):
@wraps(f)
def _wrapper(request, *args, **kwargs):
if not request.user.is_authenticated:
raise ValueError("The @person_required decorator should be called after @login_required.")
try:
request.user.person
except Person.DoesNotExist:
return render(request, 'registration/missing_person.html')
return f(request, *args, **kwargs)
return _wrapper


def require_api_key(f):
Expand Down Expand Up @@ -90,29 +93,31 @@ def err(code, text):
return _wrapper


def _memoize(func, self, *args, **kwargs):
'''Memoize wrapper for instance methods. Use @lru_cache for functions.'''
if kwargs: # frozenset is used to ensure hashability
key = args, frozenset(list(kwargs.items()))
else:
key = args
# instance method, set up cache if needed
if not hasattr(self, '_cache'):
self._cache = {}
if not func in self._cache:
self._cache[func] = {}
#
cache = self._cache[func]
if key not in cache:
cache[key] = func(self, *args, **kwargs)
return cache[key]
def memoize(func):
@wraps(func)
def _memoize(self, *args, **kwargs):
'''Memoize wrapper for instance methods. Use @lru_cache for functions.'''
if kwargs: # frozenset is used to ensure hashability
key = args, frozenset(list(kwargs.items()))
else:
key = args
# instance method, set up cache if needed
if not hasattr(self, '_cache'):
self._cache = {}
if not func in self._cache:
self._cache[func] = {}
#
cache = self._cache[func]
if key not in cache:
cache[key] = func(self, *args, **kwargs)
return cache[key]

if not hasattr(func, '__class__'):
raise NotImplementedError("Use @lru_cache instead of memoize() for functions.")
# For methods, we want the cache on the object, not on the class, in order
# to not having to think about cache bloat and content becoming stale, so
# we cannot set up the cache here.
return decorate(func, _memoize)
return _memoize


def ignore_view_kwargs(*args):
Expand Down

0 comments on commit b31e446

Please sign in to comment.