<commit_before>from django.contrib.auth.decorators import user_passes_test


def role_required(*roles):
    """
    Decorator for views that checks whether a user has a particular role,
    redirecting to the log-in page if neccesary.
    Follows same style as django.contrib.auth.decorators.login_required,
    and django.contrib.auth.decorators.permission_required.
    """
    def check_role(user):
        return getattr(user, 'role', None) in roles
    return user_passes_test(check_role)
<commit_msg>modification that prevents the error (UserRole matching query does not exist) on a database that already contains users with no permissions assigned<commit_after>from django.contrib.auth.decorators import user_passes_test


def role_required(*roles):
    """
    Decorator for views that checks whether a user has a particular role,
    redirecting to the log-in page if neccesary.
    Follows same style as django.contrib.auth.decorators.login_required,
    and django.contrib.auth.decorators.permission_required.
    """
    def check_role(user):
        if not hasattr(user, 'role'):
	    return False
	return getattr(user, 'role', None) in roles
    return user_passes_test(check_role)

{'fraction_non_alphanumeric': 0.07357859531772576, 'fraction_numerical': 0.0, 'mean_word_length': 4.115384615384615, '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': '4591233', 'n_tokens_mistral': 341, 'n_tokens_neox': 337, 'n_words': 111}