Here are the examples of the python api django.conf.settings.ADMIN_URL taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
11 Examples
3
Source : test_admin.py
with MIT License
from betagouv
with MIT License
from betagouv
def test_honeypot_login_attempt_fails_gracefuly(self):
login_attempt_id = LoginAttempt.objects.create(username="test").pk
path = reverse(
"admin:admin_honeypot_loginattempt_change", args=(login_attempt_id,)
)
admin = settings.ADMIN_URL
admin_url = f"/{admin}admin_honeypot/loginattempt/{login_attempt_id}/change/"
self.assertEqual(admin_url, path)
def test_sidebar_is_not_in_login_admin_page(self):
3
Source : test_admin.py
with MIT License
from betagouv
with MIT License
from betagouv
def test_sidebar_is_not_in_login_admin_page(self):
admin = settings.ADMIN_URL
amac_client = Client()
response = amac_client.get(f"/{admin}login", follow=True)
self.assertTemplateUsed(response, "aidants_connect_web/admin/login.html")
self.assertNotContains(response, "nav-sidebar")
@tag("admin")
3
Source : context_processors.py
with MIT License
from BitChute
with MIT License
from BitChute
def settings(request):
ctx = {
"ADMIN_URL": django_settings.ADMIN_URL,
"CONTACT_EMAIL": django_settings.CONTACT_EMAIL,
"pinax_notifications_installed": "pinax.notifications" in django_settings.INSTALLED_APPS,
"pinax_stripe_installed": "pinax.stripe" in django_settings.INSTALLED_APPS,
"pinax_apps": package_names(filter(pinax_apps_filter, django_settings.INSTALLED_APPS))
}
if Site._meta.installed:
site = Site.objects.get_current(request)
ctx.update({
"SITE_NAME": 'Comment Freely',
"SITE_DOMAIN": 'commentfreely.com'
})
return ctx
3
Source : middleware.py
with GNU General Public License v3.0
from gojuukaze
with GNU General Public License v3.0
from gojuukaze
def password_age_middleware(get_response):
"""
登录admin时,校验密码有效期
"""
def middleware(request):
password_change_url=reverse('admin:password_change')
if request.path.startswith(urljoin('/', settings.ADMIN_URL)) \
and not request.path.startswith(password_change_url) \
and request.user.is_authenticated \
and request.user.user_info.is_password_expired():
return HttpResponseRedirect(password_change_url + '?from=reset')
return get_response(request)
return middleware
3
Source : serializers.py
with MIT License
from pixelpassion
with MIT License
from pixelpassion
def get_admin_url(self, instance):
if instance.is_staff or instance.is_superuser:
return settings.ADMIN_URL
return None
class UserRegistrationSerializer(BaseUserSerializer):
3
Source : test_user_me_endpoint.py
with MIT License
from pixelpassion
with MIT License
from pixelpassion
def test_get_admin_url_user_is_staff(logged_in_client, user):
user.is_staff = True
user.save()
response = logged_in_client.get(USER_API_URL)
assert response.status_code == 200
assert response.data["admin_url"] == settings.ADMIN_URL
def test_get_admin_url_user_is_superuser(logged_in_client, user):
3
Source : test_user_me_endpoint.py
with MIT License
from pixelpassion
with MIT License
from pixelpassion
def test_get_admin_url_user_is_superuser(logged_in_client, user):
user.is_superuser = True
user.save()
response = logged_in_client.get(USER_API_URL)
assert response.status_code == 200
assert response.data["admin_url"] == settings.ADMIN_URL
def test_get_admin_url_user_is_superuser_is_staff(logged_in_client, user):
3
Source : test_user_me_endpoint.py
with MIT License
from pixelpassion
with MIT License
from pixelpassion
def test_get_admin_url_user_is_superuser_is_staff(logged_in_client, user):
user.is_superuser = True
user.is_staff = True
user.save()
response = logged_in_client.get(USER_API_URL)
assert response.status_code == 200
assert response.data["admin_url"] == settings.ADMIN_URL
def test_get_admin_url_user_is_not_staff(logged_in_client, user):
0
Source : views.py
with GNU General Public License v3.0
from gojuukaze
with GNU General Public License v3.0
from gojuukaze
def init_view(request):
if all_user().first():
# 说明已经初始化过了
return HttpResponseNotFound()
if request.method == 'POST':
admin_form = AddAdminForm(request.POST, prefix='创建一个管理员账户')
ldap_form = AddLdapForm(request.POST, prefix='创建一个LDAP账户')
# 不能用if and判断,
# 否则前一个form无效时会导致后一个form没执行is_valid()
if all([admin_form.is_valid(), ldap_form.is_valid()]):
init([admin_form, ldap_form])
return HttpResponseRedirect('/' + settings.ADMIN_URL)
else:
admin_form = AddAdminForm(prefix='创建一个管理员账户')
ldap_form = AddLdapForm(prefix='创建一个LDAP账户')
admin_form.remove_exclude_field()
ldap_form.remove_exclude_field()
forms = [admin_form, ldap_form]
return render(request, 'app/init.html', {'forms': forms, 'version': version})
0
Source : context_processors.py
with MIT License
from Hedera-Lang-Learn
with MIT License
from Hedera-Lang-Learn
def settings(request):
ctx = {
"ADMIN_URL": django_settings.ADMIN_URL,
"CONTACT_EMAIL": django_settings.CONTACT_EMAIL,
"IS_LTI": django_settings.IS_LTI,
"pinax_notifications_installed": "pinax.notifications" in django_settings.INSTALLED_APPS,
"pinax_stripe_installed": "pinax.stripe" in django_settings.INSTALLED_APPS,
"pinax_apps": package_names(filter(pinax_apps_filter, django_settings.INSTALLED_APPS))
}
if Site._meta.installed:
site = Site.objects.get_current(request)
ctx.update({
"SITE_NAME": site.name,
"SITE_DOMAIN": site.domain
})
return ctx
def vue_debug(request):
0
Source : show_urls_no_admin.py
with MIT License
from jeffshek
with MIT License
from jeffshek
def handle(self, *args, **options):
style = no_style() if options["no_color"] else color_style()
language = options["language"]
if language is not None:
translation.activate(language)
self.LANGUAGES = [
(code, name)
for code, name in getattr(settings, "LANGUAGES", [])
if code == language
]
else:
self.LANGUAGES = getattr(settings, "LANGUAGES", ((None, None),))
decorator = options["decorator"]
if not decorator:
decorator = ["login_required"]
format_style = options["format_style"]
if format_style not in FMTR:
raise CommandError(
"Format style '%s' does not exist. Options: %s"
% (format_style, ", ".join(sorted(FMTR.keys())),)
)
pretty_json = format_style == "pretty-json"
if pretty_json:
format_style = "json"
fmtr = FMTR[format_style]
urlconf = options["urlconf"]
views = []
if not hasattr(settings, urlconf):
raise CommandError(
"Settings module {} does not have the attribute {}.".format(
settings, urlconf
)
)
try:
urlconf = __import__(getattr(settings, urlconf), {}, {}, [""])
except Exception as e:
if options["traceback"]:
import traceback
traceback.print_exc()
raise CommandError(
"Error occurred while trying to load %s: %s"
% (getattr(settings, urlconf), str(e))
)
view_functions = self.extract_views_from_urlpatterns(urlconf.urlpatterns)
for (func, regex, url_name) in view_functions:
if hasattr(func, "__globals__"):
func_globals = func.__globals__
elif hasattr(func, "func_globals"):
func_globals = func.func_globals
else:
func_globals = {}
decorators = [d for d in decorator if d in func_globals]
if isinstance(func, functools.partial):
func = func.func
decorators.insert(0, "functools.partial")
if hasattr(func, "__name__"):
func_name = func.__name__
elif hasattr(func, "__class__"):
func_name = "%s()" % func.__class__.__name__
else:
func_name = re.sub(r" at 0x[0-9a-f]+", "", repr(func))
module = "{0}.{1}".format(func.__module__, func_name)
url_name = url_name or ""
url = simplify_regex(regex)
decorator = ", ".join(decorators)
if format_style == "json":
views.append(
{
"url": url,
"module": module,
"name": url_name,
"decorators": decorator,
}
)
else:
views.append(
fmtr.format(
module="{0}.{1}".format(
style.MODULE(func.__module__), style.MODULE_NAME(func_name)
),
url_name=style.URL_NAME(url_name),
url=style.URL(url),
decorator=decorator,
).strip()
)
if not options["unsorted"] and format_style != "json":
views = sorted(views)
if format_style == "aligned":
views = [row.split(",", 3) for row in views]
widths = [len(max(columns, key=len)) for columns in zip(*views)]
views = [
" ".join(
"{0: < {1}}".format(cdata, width) for width, cdata in zip(widths, row)
)
for row in views
]
elif format_style == "table":
# Reformat all data and show in a table format
views = [row.split(",", 3) for row in views]
widths = [len(max(columns, key=len)) for columns in zip(*views)]
table_views = []
header = (
style.MODULE_NAME("URL"),
style.MODULE_NAME("Module"),
style.MODULE_NAME("Name"),
style.MODULE_NAME("Decorator"),
)
table_views.append(
" | ".join(
"{0: < {1}}".format(title, width)
for width, title in zip(widths, header)
)
)
table_views.append("-+-".join("-" * width for width in widths))
for row in views:
table_views.append(
" | ".join(
"{0: < {1}}".format(cdata, width)
for width, cdata in zip(widths, row)
)
)
# Replace original views so we can return the same object
views = table_views
elif format_style == "json":
if pretty_json:
return json.dumps(views, indent=4)
return json.dumps(views)
return "\n".join([v for v in views if settings.ADMIN_URL not in v]) + "\n"
def extract_views_from_urlpatterns(self, urlpatterns, base="", namespace=None):