from django.conf.urls import patterns, url
from django.contrib.admin.views.decorators import staff_member_required
from django.utils.translation import ugettext_lazy as _

from oscar.core.application import Application
from oscar.apps.dashboard.ranges import views
from oscar.apps.dashboard.nav import register, Node

node = Node(_('Ranges'), 'dashboard:range-list')
register(node, 70)


class RangeDashboardApplication(Application):
    name = None

    list_view = views.RangeListView
    create_view = views.RangeCreateView
    update_view = views.RangeUpdateView
    delete_view = views.RangeDeleteView
    products_view = views.RangeProductListView

    def get_urls(self):
        urlpatterns = patterns('',
            url(r'^$', self.list_view.as_view(), name='range-list'),
            url(r'^create/$', self.create_view.as_view(), name='range-create'),
            url(r'^(?P<pk>\d+)/$', self.update_view.as_view(), name='range-update'),
            url(r'^(?P<pk>\d+)/delete/$', self.delete_view.as_view(), name='range-delete'),
            url(r'^(?P<pk>\d+)/products/$', self.products_view.as_view(), name='range-products'),
        )
        return self.post_process_urls(urlpatterns)

    def get_url_decorator(self, url_name):
        return staff_member_required


application = RangeDashboardApplication()
