Ejemplo n.º 1
0
def schema_context(schema_name):
    previous_tenant = connection.get_tenant()
    try:
        connection.set_schema(schema_name)
        yield
    finally:
        connection.set_tenant(previous_tenant)
Ejemplo n.º 2
0
def tenant_context(tenant):
    previous_tenant = connection.get_tenant()
    try:
        connection.set_tenant(tenant)
        yield
    finally:
        connection.set_tenant(previous_tenant)
Ejemplo n.º 3
0
def schema_context(schema_name):
    previous_tenant = connection.get_tenant()
    try:
        connection.set_schema(schema_name)
        yield
    finally:
        connection.set_tenant(previous_tenant)
Ejemplo n.º 4
0
def tenant_context(tenant):
    previous_tenant = connection.get_tenant()
    try:
        connection.set_tenant(tenant)
        yield
    finally:
        connection.set_tenant(previous_tenant)
Ejemplo n.º 5
0
def get_tenant_name():
    from django.db import connection

    try:
        tenant_name = connection.get_tenant().name
    except AttributeError:
        tenant_name = None

    return tenant_name
Ejemplo n.º 6
0
def admin_password_reset(
        request,
        is_admin_site=False,
        template_name='registration/password_reset_form.html',
        email_template_name='registration/password_reset_email.html',
        subject_template_name='registration/password_reset_subject.txt',
        password_reset_form=PasswordResetForm,
        token_generator=default_token_generator,
        post_reset_redirect=None,
        from_email=None,
        extra_context=None):
    """
    This is a copy of django.contrib.auth.views.password_reset but this
    forces the domain to the one specified in current tenant.
    """

    if post_reset_redirect is None:
        post_reset_redirect = reverse('password_reset_done')
    else:
        post_reset_redirect = resolve_url(post_reset_redirect)

    if request.method == "POST":
        form = password_reset_form(request.POST)
        if form.is_valid():
            opts = {
                'use_https': request.is_secure(),
                'token_generator': token_generator,
                'from_email': from_email,
                'email_template_name': email_template_name,
                'subject_template_name': subject_template_name,
                'request': request,
            }
            tenant = connection.get_tenant()
            domain_override = tenant.domain_url
            opts = dict(opts, domain_override=domain_override)
            form.save(**opts)
            return HttpResponseRedirect(post_reset_redirect)
    else:
        form = password_reset_form()
    context = {
        'form': form,
    }
    if extra_context is not None:
        context.update(extra_context)
    return TemplateResponse(request, template_name, context)
Ejemplo n.º 7
0
def admin_password_reset(request, is_admin_site=False,
                         template_name='registration/password_reset_form.html',
                         email_template_name='registration/password_reset_email.html',
                         subject_template_name='registration/password_reset_subject.txt',
                         password_reset_form=PasswordResetForm,
                         token_generator=default_token_generator,
                         post_reset_redirect=None,
                         from_email=None,
                         current_app=None,
                         extra_context=None):
    """
    This is a copy of django.contrib.auth.views.password_reset but this
    forces the domain to the one specified in current tenant.
    """

    if post_reset_redirect is None:
        post_reset_redirect = reverse('password_reset_done')
    else:
        post_reset_redirect = resolve_url(post_reset_redirect)

    if request.method == "POST":
        form = password_reset_form(request.POST)
        if form.is_valid():
            opts = {
                'use_https': request.is_secure(),
                'token_generator': token_generator,
                'from_email': from_email,
                'email_template_name': email_template_name,
                'subject_template_name': subject_template_name,
                'request': request,
            }
            tenant = connection.get_tenant()
            domain_override = tenant.domain_url
            opts = dict(opts, domain_override=domain_override)
            form.save(**opts)
            return HttpResponseRedirect(post_reset_redirect)
    else:
        form = password_reset_form()
    context = {
        'form': form,
    }
    if extra_context is not None:
        context.update(extra_context)
    return TemplateResponse(request, template_name, context,
                            current_app=current_app)
 def has_permission(self, request, view):
     #print(connection.get_tenant())
     return connection.get_tenant() == 'public' and permissions.IsAdminUser(
         request.user)