# Path: planb/views.py
# class EnqueueJob(View):
#     def post(self, request, fileset_id):
#         if not request.user.has_perm('planb.add_backuprun'):
#             raise PermissionDenied()
#         try:
#             # Allow enqueuing disabled filesets for cases where periodic
#             # backups are not desired or possible.
#             fileset = Fileset.objects.get(id=fileset_id)
#         except Fileset.DoesNotExist:
#             raise PermissionDenied()
# 
#         self.enqueue(fileset)
# 
#         return HttpResponseRedirect(
#             # Our URL is /bla/bla/123/enqueue/.
#             # Drop the "enqueue/".
#             # FIXME: Should use proper reverse() instead!
#             self.request.path_info.rsplit('/', 2)[0] + '/')
# 
#     def enqueue(self, fileset):
#         if fileset.is_queued or fileset.is_running:
#             messages.add_message(
#                 self.request, messages.ERROR,
#                 'Job was already queued/running!')
#             return False
# 
#         # Spawn a single run.
#         Fileset.objects.filter(pk=fileset.pk).update(is_queued=True)
#         task_id = async_backup_job(fileset)
#         messages.add_message(
#             self.request, messages.INFO,
#             'Spawned job %s as requested.' % (task_id,))


from django.contrib import admin
from django.urls import re_path as url
from django.views.generic.base import RedirectView
from .views import EnqueueJob



admin.autodiscover()
admin.site.site_title = 'PlanB'
admin.site.site_header = 'PlanB management'

urlpatterns = [
    #################
    # Admin interface
    #################

    # Use / as the admin path (only if this is the only app in the project)
    # (point people to the right url.. fails to work if STATIC_URL is '/')
    url(r'^admin(/.*)$', RedirectView.as_view(url='/', permanent=False)),
    url(r'^planb/fileset/(?P<fileset_id>\d+)/enqueue/$',

# Path: planb/views.py
# class EnqueueJob(View):
#     def post(self, request, fileset_id):
#         if not request.user.has_perm('planb.add_backuprun'):
#             raise PermissionDenied()
#         try:
#             # Allow enqueuing disabled filesets for cases where periodic
#             # backups are not desired or possible.
#             fileset = Fileset.objects.get(id=fileset_id)
#         except Fileset.DoesNotExist:
#             raise PermissionDenied()
# 
#         self.enqueue(fileset)
# 
#         return HttpResponseRedirect(
#             # Our URL is /bla/bla/123/enqueue/.
#             # Drop the "enqueue/".
#             # FIXME: Should use proper reverse() instead!
#             self.request.path_info.rsplit('/', 2)[0] + '/')
# 
#     def enqueue(self, fileset):
#         if fileset.is_queued or fileset.is_running:
#             messages.add_message(
#                 self.request, messages.ERROR,
#                 'Job was already queued/running!')
#             return False
# 
#         # Spawn a single run.
#         Fileset.objects.filter(pk=fileset.pk).update(is_queued=True)
#         task_id = async_backup_job(fileset)
#         messages.add_message(
#             self.request, messages.INFO,
#             'Spawned job %s as requested.' % (task_id,))


# Path: planb/urls.py
from django.contrib import admin
from django.urls import re_path as url
from django.views.generic.base import RedirectView
from .views import EnqueueJob




admin.autodiscover()
admin.site.site_title = 'PlanB'
admin.site.site_header = 'PlanB management'

urlpatterns = [
    #################
    # Admin interface
    #################

    # Use / as the admin path (only if this is the only app in the project)
    # (point people to the right url.. fails to work if STATIC_URL is '/')
    url(r'^admin(/.*)$', RedirectView.as_view(url='/', permanent=False)),
    url(r'^planb/fileset/(?P<fileset_id>\d+)/enqueue/$',

        EnqueueJob.as_view(), name='enqueue'),