# -*- coding: utf8 -*-

from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import RedirectView
from django.contrib.sitemaps.views import sitemap
from wikipendium.sitemap import ArticleSitemap


sitemaps = {
    'articles': ArticleSitemap,
}

admin.autodiscover()

slug_regex = ur'[A-Za-z0-9æøåÆØÅ]+'
article_regex = ur'(?P<slug>' + slug_regex + ')[^/]*'

article_patterns = patterns(
    'wikipendium.wiki.views',
    url(r'^edit/$', 'edit'),
    url(r'^history/$', 'history'),
    url(r'^history/(?P<id>\d+)/$', 'history_single'),
)


urlpatterns = patterns(
    'wikipendium.wiki.views',
    url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('registration.backends.simple.urls')),
    url(r'^$', 'home', name='home'),
    url(r'^new/$', 'new', name='newarticle'),

    url(r'^users/(?P<username>' + slug_regex + ')/$',
        'user', name='user'),

    url(r'^' + article_regex + '/$',
        RedirectView.as_view(url='/%(slug)s')),

    url(r'^' + article_regex + '$', 'article'),
    url(r'^' + article_regex + '/',
        include(article_patterns)),
    url(r'^' + article_regex + '/add_language/$',
        'add_language'),

    url(r'^' + article_regex + '/(?P<lang>[a-z]+)/$',
        'article'),
    url(r'^' + article_regex + '/(?P<lang>[a-z]+)/',
        include(article_patterns)),
)

# -*- coding: utf8 -*-

from django.conf.urls import patterns, include, url
from django.contrib import admin
from django.views.generic import RedirectView
from django.contrib.sitemaps.views import sitemap
from wikipendium.sitemap import ArticleSitemap


sitemaps = {
    'articles': ArticleSitemap,
}

admin.autodiscover()

slug_regex = ur'[A-Za-z0-9æøåÆØÅ]+'
article_regex = ur'(?P<slug>' + slug_regex + ')[^/]*'

article_patterns = patterns(
    'wikipendium.wiki.views',
    url(r'^edit/$', 'edit'),
    url(r'^history/$', 'history'),
    url(r'^history/(?P<id>\d+)/$', 'history_single'),
)


urlpatterns = patterns(
    'wikipendium.wiki.views',
    url(r'^sitemap\.xml$', sitemap, {'sitemaps': sitemaps}),
    url(r'^admin/', include(admin.site.urls)),
    url(r'^accounts/', include('registration.backends.simple.urls')),
    url(r'^$', 'home', name='home'),
    url(r'^new/$', 'new', name='newarticle'),

    url(r'^users/(?P<username>[\w|\W]+)/$',
        'user', name='user'),

    url(r'^' + article_regex + '/$',
        RedirectView.as_view(url='/%(slug)s')),

    url(r'^' + article_regex + '$', 'article'),
    url(r'^' + article_regex + '/',
        include(article_patterns)),
    url(r'^' + article_regex + '/add_language/$',
        'add_language'),

    url(r'^' + article_regex + '/(?P<lang>[a-z]+)/$',
        'article'),
    url(r'^' + article_regex + '/(?P<lang>[a-z]+)/',
        include(article_patterns)),
)

Allow UTF-8 characters in username