Python django.conf.urls.patterns() Examples

The following are 27 code examples of django.conf.urls.patterns(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module django.conf.urls , or try the search function .
Example #1
Source File: admin.py    From crowdata with MIT License 6 votes vote down vote up
def get_urls(self):
        urls = super(DocumentSetAdmin, self).get_urls()

        extra_urls = patterns('',
                              url('^(?P<document_set_id>\d+)/answers/$',
                                  self.admin_site.admin_view(self.answers_view),
                                  name="document_set_answers_csv"),
                              url('^(?P<document_set_id>\d+)/add_documents/$',
                                  self.admin_site.admin_view(self.add_documents_view),
                                  name='document_set_add_documents'),
                              url('^(?P<document_set_id>\d+)/update_canons/$',
                                  self.admin_site.admin_view(self.update_canons_view),
                                  name='document_set_update_canons'),
                              url('^(?P<document_set_id>\d+)/reverify_documents/$',
                                self.admin_site.admin_view(self.reverify_documents_view),
                                  name='document_set_reverify_documents')
                             )

        return extra_urls + urls 
Example #2
Source File: base.py    From avos with Apache License 2.0 6 votes vote down vote up
def _get_default_urlpatterns(self):
        package_string = '.'.join(self.__module__.split('.')[:-1])
        if getattr(self, 'urls', None):
            try:
                mod = import_module('.%s' % self.urls, package_string)
            except ImportError:
                mod = import_module(self.urls)
            urlpatterns = mod.urlpatterns
        else:
            # Try importing a urls.py from the dashboard package
            if module_has_submodule(import_module(package_string), 'urls'):
                urls_mod = import_module('.urls', package_string)
                urlpatterns = urls_mod.urlpatterns
            else:
                urlpatterns = patterns('')
        return urlpatterns 
Example #3
Source File: static.py    From luscan-devel with GNU General Public License v2.0 6 votes vote down vote up
def static(prefix, view='django.views.static.serve', **kwargs):
    """
    Helper function to return a URL pattern for serving files in debug mode.

    from django.conf import settings
    from django.conf.urls.static import static

    urlpatterns = patterns('',
        # ... the rest of your URLconf goes here ...
    ) + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

    """
    # No-op if not in debug mode or an non-local prefix
    if not settings.DEBUG or (prefix and '://' in prefix):
        return []
    elif not prefix:
        raise ImproperlyConfigured("Empty static prefix not permitted")
    return patterns('',
        url(r'^%s(?P<path>.*)$' % re.escape(prefix.lstrip('/')), view, kwargs=kwargs),
    ) 
Example #4
Source File: views.py    From django-generic-scaffold with MIT License 6 votes vote down vote up
def get_url_patterns(self, ):
        prefix = hasattr(self, 'prefix') and self.prefix or ''

        url_patterns = [
            url(r'^'+prefix+'$', self.perms['list'](self.get_list_class_view().as_view()), name=self.list_url_name, ),
            url(r'^'+prefix+'create/$', self.perms['create'](self.get_create_class_view().as_view()), name=self.create_url_name ),
            url(r'^'+prefix+'detail/(?P<pk>\d+)$', self.perms['detail'](self.get_detail_class_view().as_view()), name=self.detail_url_name ),
            url(r'^'+prefix+'update/(?P<pk>\d+)$', self.perms['update'](self.get_update_class_view().as_view()), name=self.update_url_name ),
            url(r'^'+prefix+'delete/(?P<pk>\d+)$', self.perms['delete'](self.get_delete_class_view().as_view()), name=self.delete_url_name ),
        ]

        if django.VERSION >= (1, 8, 0):
            return url_patterns
        else:
            from django.conf.urls import patterns
            return patterns('', *url_patterns) 
Example #5
Source File: urls.py    From builder with GNU Affero General Public License v3.0 6 votes vote down vote up
def _buildPatternList():
  urls = [
    # Main website
    url(r'^', include(SITE_URLS)) if SITE_URLS else None,

    # Main app
    url(r'^', include(MAIN_URLS)),

    # Polychart.js website
    url(r'^js/', include(JS_SITE_URLS)) if JS_SITE_URLS else None,

    # Analytics
    url('^', include(ANALYTICS_URLS)) if ANALYTICS_URLS else None,

    # Deprecated URLs
    url(r'^beta$', permanentRedirect('/signup')),
    url(r'^devkit.*$', permanentRedirect('/')),
    url(r'^embed/.*$', permanentRedirect('/')),
  ]

  # Filter out None
  urls = [x for x in urls if x]

  return patterns('polychart.main.views', *urls) 
Example #6
Source File: urls.py    From builder with GNU Affero General Public License v3.0 6 votes vote down vote up
def _buildPatternList():
  urls = [
    # Main website
    url(r'^', include(SITE_URLS)) if SITE_URLS else None,

    # Main app
    url(r'^', include(MAIN_URLS)),

    # Polychart.js website
    url(r'^js/', include(JS_SITE_URLS)) if JS_SITE_URLS else None,

    # Analytics
    url('^', include(ANALYTICS_URLS)) if ANALYTICS_URLS else None,

    # Deprecated URLs
    url(r'^beta$', permanentRedirect('/signup')),
    url(r'^devkit.*$', permanentRedirect('/')),
    url(r'^embed/.*$', permanentRedirect('/')),
  ]

  # Filter out None
  urls = [x for x in urls if x]

  return patterns('polychart.main.views', *urls) 
Example #7
Source File: __init__.py    From django-bananas with MIT License 5 votes vote down vote up
def urlpatterns(*urls):
    if django.VERSION < (1, 10):
        from django.conf.urls import patterns

        return patterns("", *urls)

    return list(urls) 
Example #8
Source File: __init__.py    From py2swagger with MIT License 5 votes vote down vote up
def patterns(*args):
        return list(filter(lambda x: x, args)) 
Example #9
Source File: base.py    From avos with Apache License 2.0 5 votes vote down vote up
def _urls(self):
        """Constructs the URLconf for Horizon from registered Dashboards."""
        urlpatterns = self._get_default_urlpatterns()
        self._autodiscover()

        # Discover each dashboard's panels.
        for dash in self._registry.values():
            dash._autodiscover()

        # Load the plugin-based panel configuration
        self._load_panel_customization()

        # Allow for override modules
        if self._conf.get("customization_module", None):
            customization_module = self._conf["customization_module"]
            bits = customization_module.split('.')
            mod_name = bits.pop()
            package = '.'.join(bits)
            mod = import_module(package)
            try:
                before_import_registry = copy.copy(self._registry)
                import_module('%s.%s' % (package, mod_name))
            except Exception:
                self._registry = before_import_registry
                if module_has_submodule(mod, mod_name):
                    raise

        # Compile the dynamic urlconf.
        for dash in self._registry.values():
            urlpatterns += patterns('',
                                    url(r'^%s/' % dash.slug,
                                        include(dash._decorated_urls)))

        # Return the three arguments to django.conf.urls.include
        return urlpatterns, self.namespace, self.slug 
Example #10
Source File: base.py    From avos with Apache License 2.0 5 votes vote down vote up
def _lazy_urls(self):
        """Lazy loading for URL patterns.

        This method avoids problems associated with attempting to evaluate
        the URLconf before the settings module has been loaded.
        """
        def url_patterns():
            return self._urls()[0]

        return LazyURLPattern(url_patterns), self.namespace, self.slug 
Example #11
Source File: base.py    From avos with Apache License 2.0 5 votes vote down vote up
def _decorated_urls(self):
        urlpatterns = self._get_default_urlpatterns()

        default_panel = None

        # Add in each panel's views except for the default view.
        for panel in self._registry.values():
            if panel.slug == self.default_panel:
                default_panel = panel
                continue
            url_slug = panel.slug.replace('.', '/')
            urlpatterns += patterns('',
                                    url(r'^%s/' % url_slug,
                                        include(panel._decorated_urls)))
        # Now the default view, which should come last
        if not default_panel:
            raise NotRegistered('The default panel "%s" is not registered.'
                                % self.default_panel)
        urlpatterns += patterns('',
                                url(r'',
                                    include(default_panel._decorated_urls)))

        # Require login if not public.
        if not self.public:
            _decorate_urlconf(urlpatterns, require_auth)
        # Apply access controls to all views in the patterns
        permissions = getattr(self, 'permissions', [])
        _decorate_urlconf(urlpatterns, require_perms, permissions)
        _decorate_urlconf(urlpatterns, _current_component, dashboard=self)

        # Return the three arguments to django.conf.urls.include
        return urlpatterns, self.slug, self.slug 
Example #12
Source File: base.py    From avos with Apache License 2.0 5 votes vote down vote up
def _decorated_urls(self):
        urlpatterns = self._get_default_urlpatterns()

        # Apply access controls to all views in the patterns
        permissions = getattr(self, 'permissions', [])
        _decorate_urlconf(urlpatterns, require_perms, permissions)
        _decorate_urlconf(urlpatterns, _current_component, panel=self)

        # Return the three arguments to django.conf.urls.include
        return urlpatterns, self.slug, self.slug 
Example #13
Source File: admin.py    From esdc-ce with Apache License 2.0 5 votes vote down vote up
def get_urls(self):
        urls = patterns(
            '',
            url(r'cancel_impersonation/$', self.admin_site.admin_view(self.stop_impersonation),
                name='stop_impersonation'),
            url(r'(?P<user_id>\d+)/impersonate/$', self.admin_site.admin_view(self.start_impersonation),
                name='start_impersonation'),
        )
        return urls + super(UserAdmin, self).get_urls() 
Example #14
Source File: admin.py    From django-heythere with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_urls(self):
        admin_send_all_unsent = self.admin_site.admin_view(
            self.handle_sending_all_unsent)
        return patterns(
            '',
            url(r'^send_all_unsent/$', admin_send_all_unsent,
                name='heythere_notification_send_all_unsent'),
        ) + super(NotificationAdmin, self).get_urls() 
Example #15
Source File: api.py    From chain-api with MIT License 5 votes vote down vote up
def urls(cls):
        base_name = cls.resource_name
        return patterns('',
                        url(r'^$',
                            cls.list_view, name=base_name + '-list'),
                        url(r'^(\d+)$',
                            cls.single_view, name=base_name + '-single'),
                        url(r'^(\d+)/edit$',
                            cls.edit_view, name=base_name + '-edit'),
                        url(r'^create$',
                            cls.create_view, name=base_name + '-create'))

# Resource URL Setup and Lookup: 
Example #16
Source File: resources.py    From chain-api with MIT License 5 votes vote down vote up
def urls(cls):
        base_name = cls.resource_name
        return patterns('',
                        url(r'^$',
                            cls.list_view, name=base_name + '-list')) 
Example #17
Source File: settings.py    From django-sae with Apache License 2.0 5 votes vote down vote up
def patch_root_urlconf():
    from django.conf.urls import include, patterns, url
    from django.core.urlresolvers import clear_url_caches, reverse, NoReverseMatch
    from django.utils.importlib import import_module

    try:
        reverse('tasks:execute')
    except NoReverseMatch:
        root = import_module(settings.ROOT_URLCONF)
        root.urlpatterns = patterns('', url(r'^tasks/', include('django_sae.contrib.tasks.urls', 'tasks',
                                                                'tasks')), ) + root.urlpatterns
        clear_url_caches() 
Example #18
Source File: sites.py    From devops with MIT License 5 votes vote down vote up
def get_urls(self):
        from django.conf.urls import patterns, url, include
        from xadmin.views.base import BaseAdminView

        if settings.DEBUG:
            self.check_dependencies()

        def wrap(view, cacheable=False):
            def wrapper(*args, **kwargs):
                return self.admin_view(view, cacheable)(*args, **kwargs)
            return update_wrapper(wrapper, view)

        # Admin-site-wide views.
        urlpatterns = patterns('',
                               url(r'^jsi18n/$', wrap(self.i18n_javascript,
                                                      cacheable=True), name='jsi18n')
                               )

        # Registed admin views
        urlpatterns += patterns('',
                                *[url(
                                  path, wrap(self.create_admin_view(clz_or_func)) if type(clz_or_func) == type and issubclass(clz_or_func, BaseAdminView) else include(clz_or_func(self)),
                                  name=name) for path, clz_or_func, name in self._registry_views]
                                )

        # Add in each model's views.
        for model, admin_class in self._registry.iteritems():
            view_urls = [url(
                path, wrap(
                    self.create_model_admin_view(clz, model, admin_class)),
                name=name % (model._meta.app_label, model._meta.model_name))
                for path, clz, name in self._registry_modelviews]
            urlpatterns += patterns('',
                                    url(
                                    r'^%s/%s/' % (
                                        model._meta.app_label, model._meta.model_name),
                                    include(patterns('', *view_urls)))
                                    )

        return urlpatterns 
Example #19
Source File: sites.py    From devops with MIT License 5 votes vote down vote up
def admin_view(self, view, cacheable=False):
        """
        Decorator to create an admin view attached to this ``AdminSite``. This
        wraps the view and provides permission checking by calling
        ``self.has_permission``.

        You'll want to use this from within ``AdminSite.get_urls()``:

            class MyAdminSite(AdminSite):

                def get_urls(self):
                    from django.conf.urls import patterns, url

                    urls = super(MyAdminSite, self).get_urls()
                    urls += patterns('',
                        url(r'^my_view/$', self.admin_view(some_view))
                    )
                    return urls

        By default, admin_views are marked non-cacheable using the
        ``never_cache`` decorator. If the view can be safely cached, set
        cacheable=True.
        """
        def inner(request, *args, **kwargs):
            if not self.has_permission(request) and getattr(view, 'need_site_permission', True):
                return self.create_admin_view(self.login_view)(request, *args, **kwargs)
            return view(request, *args, **kwargs)
        if not cacheable:
            inner = never_cache(inner)
        return update_wrapper(inner, view) 
Example #20
Source File: app.py    From django-oscar-shipping with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_urls(self):
        urlpatterns = super(ShippingApplication, self).get_urls()
        urlpatterns += patterns('',
            url(r'^city-lookup/(?P<slug>[\w-]+)/$', cache_page(60*10)(self.city_lookup_view.as_view()),
                name='city-lookup'),
        )
        urlpatterns += patterns('',
            url(r'^details/(?P<slug>[\w-]+)/$', cache_page(60*10)(self.shipping_details_view.as_view()),
                name='charge-details'),
        )
        return self.post_process_urls(urlpatterns) 
Example #21
Source File: i18n.py    From luscan-devel with GNU General Public License v2.0 5 votes vote down vote up
def i18n_patterns(prefix, *args):
    """
    Adds the language code prefix to every URL pattern within this
    function. This may only be used in the root URLconf, not in an included
    URLconf.

    """
    pattern_list = patterns(prefix, *args)
    if not settings.USE_I18N:
        return pattern_list
    return [LocaleRegexURLResolver(pattern_list)] 
Example #22
Source File: clipboardadmin.py    From django-leonardo with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_urls(self):
        from django.conf.urls import patterns, url
        urls = super(ClipboardAdmin, self).get_urls()
        from .. import views
        url_patterns = patterns('',
                                url(r'^operations/paste_clipboard_to_folder/$',
                                    self.admin_site.admin_view(
                                        views.paste_clipboard_to_folder),
                                    name='filer-paste_clipboard_to_folder'),
                                url(r'^operations/discard_clipboard/$',
                                    self.admin_site.admin_view(
                                        views.discard_clipboard),
                                    name='filer-discard_clipboard'),
                                url(r'^operations/delete_clipboard/$',
                                    self.admin_site.admin_view(
                                        views.delete_clipboard),
                                    name='filer-delete_clipboard'),
                                # upload does it's own permission stuff (because of the stupid
                                # flash missing cookie stuff)
                                url(r'^operations/upload/(?P<folder_id>[0-9]+)/$',
                                    self.ajax_upload,
                                    name='filer-ajax_upload'),
                                url(r'^operations/upload/no_folder/$',
                                    self.ajax_upload,
                                    name='filer-ajax_upload'),
                                )
        url_patterns.extend(urls)
        return url_patterns 
Example #23
Source File: admin.py    From django-quill with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_urls(self):
        """Add URLs needed to handle image uploads."""
        urls = patterns(
            '',
            url(r'^upload/$', self.admin_site.admin_view(self.handle_upload), name='quill-file-upload'),
        )
        return urls + super(QuillAdmin, self).get_urls() 
Example #24
Source File: toolbox.py    From django-sitemessage with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def get_sitemessage_urls() -> List:
    """Returns sitemessage urlpatterns, that can be attached to urlpatterns of a project:

        # Example from urls.py.

        from sitemessage.toolbox import get_sitemessage_urls

        urlpatterns = patterns('',
            # Your URL Patterns belongs here.

        ) + get_sitemessage_urls()  # Now attaching additional URLs.

    """
    url_unsubscribe = url(
        r'^messages/unsubscribe/(?P<message_id>\d+)/(?P<dispatch_id>\d+)/(?P<hashed>[^/]+)/$',
        unsubscribe,
        name='sitemessage_unsubscribe'
    )

    url_mark_read = url(
        r'^messages/ping/(?P<message_id>\d+)/(?P<dispatch_id>\d+)/(?P<hashed>[^/]+)/$',
        mark_read,
        name='sitemessage_mark_read'
    )

    if VERSION >= (1, 9):
        return [url_unsubscribe, url_mark_read]

    from django.conf.urls import patterns
    return patterns('', url_unsubscribe, url_mark_read) 
Example #25
Source File: admin.py    From crowdata with MIT License 5 votes vote down vote up
def get_urls(self):
        urls = super(DocumentAdmin, self).get_urls()
        my_urls = patterns('',
                           url('^(?P<document>\d+)/document_set_field_entry/(?P<document_set_field_entry>\d+)/$',
                               self.admin_site.admin_view(self.field_entry_set),
                               name='document_set_field_entry_change')
        )
        return my_urls + urls 
Example #26
Source File: admin.py    From crowdata with MIT License 5 votes vote down vote up
def get_urls(self):
        urls = super(CanonicalFieldEntryLabelAdmin, self).get_urls()

        extra_urls = patterns('',
                              url('^cluster/$',
                                  self.admin_site.admin_view(self.cluster_canons),
                                  name="cluster_canons"),
                                  )
        return extra_urls + urls 
Example #27
Source File: base.py    From django-leonardo with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
def urlpatterns(self):
        '''load and decorate urls from all modules
        then store it as cached property for less loading
        '''
        if not hasattr(self, '_urlspatterns'):
            urlpatterns = []
            # load all urls
            # support .urls file and urls_conf = 'elephantblog.urls' on default module
            # decorate all url patterns if is not explicitly excluded
            for mod in leonardo.modules:
                # TODO this not work
                if is_leonardo_module(mod):

                    conf = get_conf_from_module(mod)

                    if module_has_submodule(mod, 'urls'):
                        urls_mod = import_module('.urls', mod.__name__)
                        if hasattr(urls_mod, 'urlpatterns'):
                            # if not public decorate all

                            if conf['public']:
                                urlpatterns += urls_mod.urlpatterns
                            else:
                                _decorate_urlconf(urls_mod.urlpatterns,
                                                  require_auth)
                                urlpatterns += urls_mod.urlpatterns
            # avoid circural dependency
            # TODO use our loaded modules instead this property
            from django.conf import settings
            for urls_conf, conf in six.iteritems(getattr(settings, 'MODULE_URLS', {})):
                # is public ?
                try:
                    if conf['is_public']:
                        urlpatterns += \
                            patterns('',
                                     url(r'', include(urls_conf)),
                                     )
                    else:
                        _decorate_urlconf(
                            url(r'', include(urls_conf)),
                            require_auth)
                        urlpatterns += patterns('',
                                                url(r'', include(urls_conf)))
                except Exception as e:
                    raise Exception('raised %s during loading %s' %
                                    (str(e), urls_conf))

            self._urlpatterns = urlpatterns

        return self._urlpatterns