Пример #1
0
def prefix_url(url):
    """
    Add url prefix defined in `settings.py` to url.
    """
    if not url or url == "/":
        return "/{}/".format(URL_PREFIX.strip("/"))
    else:
        return "/{0}/{1}/".format(URL_PREFIX.strip("/"), url.strip("/"))
Пример #2
0
    def test_prefix_url(self):
        """
        Check if `prefix_url` function correctly builds URLs,
        irrespective of whether the target URL is affixed with slashes
        or not.

        Edge cases tested by this method include empty strings and
        strings consisting of a single slash.
        """
        bare_prefix = URL_PREFIX.strip('/')
        url = prefix_url('')
        self.assertEquals(url, '/{}/'.format(bare_prefix))
        url = prefix_url('/')
        self.assertEquals(url, '/{}/'.format(bare_prefix))
        url = prefix_url('foo')
        self.assertEquals(url, '/{}/foo/'.format(bare_prefix))
        url = prefix_url('/foo')
        self.assertEquals(url, '/{}/foo/'.format(bare_prefix))
        url = prefix_url('foo/')
        self.assertEquals(url, '/{}/foo/'.format(bare_prefix))
        url = prefix_url('/foo/')
        self.assertEquals(url, '/{}/foo/'.format(bare_prefix))
Пример #3
0
# from django.contrib import admin
# admin.autodiscover()

app_patterns = patterns('',
    url(r'^$', 'trendminer.views.home', name='home'),

    (r'^login/$', 'trendminer.views.login',
     {'template_name': 'login.html'}),

    (r'^logout/$', 'trendminer.views.logout',
     {'next_page': HOME_URL}),

    url(r'^analyse/$', 'trendminer.views.analyse', name='analyse'),
    url(r'^analyse/(?P<request_id>\d{4}(-\d{2}){2}_(\d{2}-){2}\d{2}_.*)' \
            '/(?P<page>[1-9]\d*)/$',
        'trendminer.views.analyse', name='results'),

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    # url(r'^admin/', include(admin.site.urls)),
)

if URL_PREFIX:
    urlpatterns = patterns('',
        ('^{}/'.format(URL_PREFIX.strip('/')), include(app_patterns)),
    )
else:
    urlpatterns = app_patterns