# -*- coding: utf-8 -*-
#
# Copyright (c) 2010-2012 Cidadania S. Coop. Galega
#
# This file is part of e-cidadania.
#
# e-cidadania is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# e-cidadania is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with e-cidadania. If not, see <http://www.gnu.org/licenses/>.

"""
Main URLs for the e-cidadania platform.
"""

from django.conf.urls import *
from django.conf import settings
from django.contrib import admin
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.conf.urls.i18n import i18n_patterns
from django.utils.translation import ugettext_lazy as _

from core.views import IndexEntriesFeed, ListNews, AddPost, EditPost, \
                              DeletePost, ViewPost

admin.autodiscover()

# We put here the dictionary with all the packages for translatin JavaScript code
# Please refer to https://docs.djangoproject.com/en/dev/topics/i18n/internationalization/#specifying-translation-strings-in-javascript-code
js_info_dict = {
    'packages': ('apps.ecidadania.debate',),
}

urlpatterns = patterns('',
    # i18n switcher
    (r'^i18n/', include('django.conf.urls.i18n')),
)

urlpatterns += i18n_patterns('',

    (r'^grappelli/', include('grappelli.urls')),
    
    # Django administration
    (r'^admin/', include(admin.site.urls)),

    # Index
    url(r'^$', 'core.views.index.index_view', name='site-index'),

    # User accounts
    url(_(r'^accounts/'), include('apps.thirdparty.userprofile.urls')),

    # Spaces
    url(_(r'^spaces/'), include('core.spaces.urls')),
    
    # Invitations
    url(_(r'^invite/'), 'core.views.invite', name='invite'),
    
    # News (this view of news is only for the index)
    url(_(r'^news/$'), ListNews.as_view(), name='list-site-news'),
    
    url(_(r'^news/add/$'), AddPost.as_view(), name='add-site-post'),

    url(_(r'^news/(?P<post_id>\w+)/delete/$'), DeletePost.as_view(),
                                            name='delete-site-post'),

    url(_(r'^news/(?P<post_id>\w+)/edit/$'), EditPost.as_view(),
                                          name='edit-site-post'),

    url(_(r'^news/(?P<post_id>\w+)/$'), ViewPost.as_view(),
                                     name='view-site-post'),
    
    # RSS Feed for the index news ONLY
    url(r'^rss/$', IndexEntriesFeed(), name='site-feed'),
    
    #(r'^api/', include('e_cidadania.apps.api.urls')),

    # This urls is for the django comments system
    url(_(r'^comments/'), include('django.contrib.comments.urls')),

    (r'^jsi18n/$', 'django.views.i18n.javascript_catalog', js_info_dict),

    # This url is for the access to static pages. I hope this doesn't collide
    # with the index view
    url(r'^(?P<slug>[\w\-]+)/', include('apps.ecidadania.staticpages.urls')),
    
    # For smart_selects app
    url(r'^chaining/', include('apps.thirdparty.smart_selects.urls')),

    # WARNING: This URLs aren't supposed to be here, but apparently on development
    # they are needed
)

if settings.DEBUG:
    # Serve static files
    urlpatterns += staticfiles_urlpatterns()
    # Serve uploaded files
    urlpatterns += patterns('',
        url(r'^uploads/(?P<path>.*)$', 'django.views.static.serve',
            {'document_root': settings.MEDIA_ROOT}),
        )

@@ -855,16 +855,64 @@
 ettings%0A
+from django.conf.urls.i18n import i18n_patterns%0A
 from dja
@@ -936,16 +936,16 @@
 t admin%0A
-
 from dja
@@ -1008,56 +1008,8 @@
 rns%0A
-from django.conf.urls.i18n import i18n_patterns%0A
 from
@@ -1076,16 +1076,22 @@
 re.views
+.index
  import 
@@ -1110,82 +1110,185 @@
 Feed
-, ListNews, AddPost, EditPost, %5C%0A                              DeletePost,
+%0Afrom core.views.news import ListNews%0Afrom core.views.post import AddPost%0Afrom core.views.post import EditPost%0Afrom core.views.post import DeletePost%0Afrom core.views.post import
  Vie

Correct the imports in urls.py so that the correct view for the posts on the index page is called.