def do_nothing(function=None): def decorator(view_func): @wraps(view_func) def _wrapped_view(request, *args, **kwargs): return view_func(request, *args, **kwargs) return _wrapped_view return decorator(function) class DoNothing(object): def __call__(self, target): return target # Disable async view rendering in debug to allow for performance profiling if get_debug_from_env(): from silk.profiling.profiler import silk_profile class performance_metrics(silk_profile): pass else: class performance_metrics(DoNothing): pass
1. Add an import: from my_app import views 2. Add a URL to urlpatterns: path('', views.home, name='home') Class-based views 1. Add an import: from other_app.views import Home 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin from django.contrib.auth import views as auth_views from django.urls import include, path from conreq.utils.generic import get_base_url, get_debug_from_env DEBUG = get_debug_from_env() BASE_URL = get_base_url() urlpatterns = [ path("", include("conreq.apps.base.urls")), path( BASE_URL + "sign_in/", auth_views.LoginView.as_view( redirect_authenticated_user=True, template_name="registration/sign_in.html"), name="sign_in", ), path(BASE_URL + "sign_out/", auth_views.logout_then_login, name="sign_out"), path(BASE_URL + "sign_up/", include("conreq.apps.sign_up.urls")), path(BASE_URL + "request/", include("conreq.apps.user_requests.urls")),
from conreq.core.base.forms import InitializationForm from conreq.core.server_settings.models import ConreqConfig from conreq.utils.generic import get_base_url, get_debug_from_env from conreq.utils.testing import performance_metrics from django.contrib.auth import authenticate, get_user_model, login from django.contrib.auth.decorators import login_required from django.http import HttpResponse from django.shortcuts import redirect, render from django.template import loader from .helpers import initialize_conreq base_url = get_base_url() debug = get_debug_from_env() @performance_metrics() def main(request): """The primary view that handles whether to take the user to login, splash, initialization, or homepage.""" conreq_config = ConreqConfig.get_solo() user_objects = get_user_model().objects # Authenticate using Organizr headers organizr_username = request.headers.get("X-WEBAUTH-USER") if conreq_config.conreq_http_header_auth and organizr_username: # Configure the user parameters organizr_email = request.headers.get("X-WEBAUTH-EMAIL") organizr_group = int(request.headers.get("X-WEBAUTH-GROUP")) user = user_objects.get_or_create(username=organizr_username, )[0] user.email = organizr_email