def tethys_global_settings_context(request): """ Add the current Tethys app metadata to the template context. """ from .models import Setting from termsandconditions.models import TermsAndConditions # Get settings site_globals = Setting.as_dict() # Get terms and conditions # Grrr!!! TermsAndConditions has a different interface for Python 2 and 3 try: # for Python 3 site_globals.update( {'documents': TermsAndConditions.get_active_terms_list()}) except AttributeError: # for Python 3 site_globals.update( {'documents': TermsAndConditions.get_active_list(as_dict=False)}) context = {'site_globals': site_globals} return context
def tethys_global_settings_context(request): """ Add the current Tethys app metadata to the template context. """ from .models import Setting from termsandconditions.models import TermsAndConditions # Get settings site_globals = Setting.as_dict() # Get terms and conditions site_globals.update({'documents': TermsAndConditions.get_active_list(as_dict=False)}) context = {'site_globals': site_globals} return context
def tethys_global_settings_context(request): """ Add the current Tethys app metadata to the template context. """ from .models import Setting from termsandconditions.models import TermsAndConditions # Get settings site_globals = Setting.as_dict() # Get terms and conditions site_globals.update( {'documents': TermsAndConditions.get_active_list(as_dict=False)}) context = {'site_globals': site_globals} return context
def process_request(self, request): """Process each request to app to ensure terms have been accepted""" current_path = request.META['PATH_INFO'] protected_path = is_path_protected(current_path) if request.user.is_authenticated and protected_path: for term in TermsAndConditions.get_active_list(): if not TermsAndConditions.agreed_to_latest(request.user, term): accept_url = getattr(settings, 'ACCEPT_TERMS_PATH', '/terms/accept/') + term messages.warning( request, '<h4>Please Accept the Terms of Use</h4>' 'You have not yet agreed to the current Terms of Use. ' 'Please <a href="%s">CLICK HERE</a> to review and ' 'accept the Terms of Use.<br>Acceptance of the Terms of ' 'Use is required for continued use of the portal ' 'resources.' % accept_url) return None
def process_request(self, request): """Process each request to app to ensure terms have been accepted""" current_path = request.META['PATH_INFO'] protected_path = is_path_protected(current_path) if request.user.is_authenticated() and protected_path: for term in TermsAndConditions.get_active_list(): if not TermsAndConditions.agreed_to_latest(request.user, term): accept_url = getattr(settings, 'ACCEPT_TERMS_PATH', '/terms/accept/') + term messages.warning( request, '<h4>Please Accept the Terms of Use</h4>' 'You have not yet agreed to the current Terms of Use. ' 'Please <a href="%s">CLICK HERE</a> to review and ' 'accept the Terms of Use.<br>Acceptance of the Terms of ' 'Use is required for continued use of DesignSafe ' 'resources.' % accept_url) return None
def __init__(self, *args, **kwargs): if 'instance' in kwargs: kwargs.pop('instance') terms_list = None if 'initial' in kwargs: initial = kwargs.get('initial') if 'terms' in initial: terms_list = initial.get('terms') if terms_list is None: terms_list = TermsAndConditions.get_active_list(as_dict=False) self.terms = forms.ModelMultipleChoiceField( terms_list, widget=forms.MultipleHiddenInput) super(UserTermsAndConditionsModelForm, self).__init__(*args, **kwargs)
def test_get_active_list(self): active_list = TermsAndConditions.get_active_list() LOGGER.debug('Active Terms: ' + str(active_list)) self.assertEqual(2, len(active_list))