Skip to content

Commit

Permalink
Remove repo (#902)
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmi4er4 authored Nov 5, 2024
1 parent 150df2b commit dddbe8d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 7 deletions.
1 change: 0 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ XlsxWriter = "==3.0.3"
# FIXME: it's nbconvert dependency remove?
jupyter_client = "==7.1.2"
isoweek = "*"
django-subdomains = {git = "https://github.com/pacahon/django-subdomains.git",ref = "4096c2dc82f9f5e511e8c8f78d31e804ac028b5d"}
django-simple-menu = "*"
# XXX: UI problems with ckeditor widget in 6.0.0 release
django-ckeditor = "==5.9.0"
Expand Down
4 changes: 0 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import re
from urllib.parse import urlparse

from subdomains.utils import reverse as subdomain_reverse
from core.utils import reverse as subdomain_reverse

from django.conf import settings
from django.urls import reverse as django_reverse
Expand Down
78 changes: 77 additions & 1 deletion apps/core/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,87 @@
from django.db.models import Max, Min
from django.utils import formats

import functools
try:
from urlparse import urlunparse
except ImportError:
from urllib.parse import urlunparse

from django.conf import settings
try:
from django.urls import reverse as simple_reverse
except ImportError: # Django<2.0
from django.core.urlresolvers import reverse as simple_reverse


def current_site_domain():
from django.contrib.sites.models import Site
domain = Site.objects.get_current().domain

prefix = 'www.'
if getattr(settings, 'REMOVE_WWW_FROM_DOMAIN', False) \
and domain.startswith(prefix):
domain = domain.replace(prefix, '', 1)

return domain

get_domain = current_site_domain


def urljoin(domain, path=None, scheme=None):
"""
Joins a domain, path and scheme part together, returning a full URL.
:param domain: the domain, e.g. ``example.com``
:param path: the path part of the URL, e.g. ``/example/``
:param scheme: the scheme part of the URL, e.g. ``http``, defaulting to the
value of ``settings.DEFAULT_URL_SCHEME``
:returns: a full URL
"""
if scheme is None:
scheme = getattr(settings, 'DEFAULT_URL_SCHEME', 'http')

return urlunparse((scheme, domain, path or '', None, None, None))


def reverse(viewname, subdomain=None, scheme=None, args=None, kwargs=None,
current_app=None):
"""
Reverses a URL from the given parameters, in a similar fashion to
:meth:`django.urls.reverse`.
:param viewname: the name of URL
:param subdomain: the subdomain to use for URL reversing
:param scheme: the scheme to use when generating the full URL
:param args: positional arguments used for URL reversing
:param kwargs: named arguments used for URL reversing
:param current_app: hint for the currently executing application
"""
urlconf = settings.SUBDOMAIN_URLCONFS.get(subdomain, settings.ROOT_URLCONF)

domain = get_domain()
if subdomain is not None:
domain = '%s.%s' % (subdomain, domain)

path = simple_reverse(viewname, urlconf=urlconf, args=args, kwargs=kwargs,
current_app=current_app)
return urljoin(domain, path, scheme=scheme)


#: :func:`reverse` bound to insecure (non-HTTPS) URLs scheme
insecure_reverse = functools.partial(reverse, scheme='http')

#: :func:`reverse` bound to secure (HTTPS) URLs scheme
secure_reverse = functools.partial(reverse, scheme='https')

#: :func:`reverse` bound to be relative to the current scheme
relative_reverse = functools.partial(reverse, scheme='')


logger = logging.getLogger(__name__)

hashids = Hashids(salt=settings.HASHIDS_SALT, min_length=8)


class Empty(enum.Enum):
token = 0

Expand Down

0 comments on commit dddbe8d

Please sign in to comment.