def test_custom_permission_redirect(self): testuser = model_creation.create_user('testuser', 'testuser', 'testuser', '*****@*****.**', []) required_permission = 'apt_rentals.add_aptrental' codename = required_permission.split('.')[1] permission = apps.get_model('auth.Permission').objects.get( codename=codename) # Not logged in request = Mock() request.configure_mock(user=AnonymousUser()) return_view = 'mockview' view = Mock(return_value=return_view) view.request = Mock(return_value=request) response = custom_permission_required(required_permission)(view)( request) self.assertEqual(response.status_code, 302) self.assertEqual(response.url, '/login/') # No permission request = Mock() request.configure_mock(user=testuser) return_view = 'mockview' view = Mock(return_value=return_view) self.assertRaises( PermissionDenied, custom_permission_required(required_permission)(view), request) # Has permission print('has permission') testuser.user_permissions.add(permission) testuser.save() testuser = get_object_or_404(get_user_model(), id=testuser.id) request = Mock() request.configure_mock(user=testuser) return_view = 'mockview' view = Mock(return_value=return_view) response = custom_permission_required(required_permission)(view)( request) self.assertEqual(response, return_view)
from clickgestion.service_sales.forms import ServiceSalesForm from clickgestion.concepts.views import concept_delete, concept_detail, concept_edit from clickgestion.core.utilities import custom_permission_required from django.conf.urls import url urlpatterns = [ url(r'^new/(?P<transaction_code>T[A-F0-9]{10})$', custom_permission_required('service_sales.add_servicesale')( concept_edit), {'concept_form': ServiceSalesForm}, name='servicesale_new'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)$', custom_permission_required('service_sales.add_servicesale')( concept_detail), {'concept_form': ServiceSalesForm}, name='servicesale_detail'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/edit/$', custom_permission_required('service_sales.add_servicesale')( concept_edit), {'concept_form': ServiceSalesForm}, name='servicesale_edit'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/delete/$', custom_permission_required('service_sales.add_servicesale')( concept_delete), {'concept_form': ServiceSalesForm}, name='servicesale_delete'), ]
from clickgestion.parking_rentals.forms import ParkingRentalForm from clickgestion.concepts.views import concept_delete, concept_detail, concept_edit from clickgestion.core.utilities import custom_permission_required from django.conf.urls import url urlpatterns = [ url(r'^new/(?P<transaction_code>T[A-F0-9]{10})$', custom_permission_required('parking_rentals.add_parkingrental')( concept_edit), {'concept_form': ParkingRentalForm}, name='parkingrental_new'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)$', custom_permission_required('parking_rentals.add_parkingrental')( concept_detail), {'concept_form': ParkingRentalForm}, name='parkingrental_detail'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/edit/$', custom_permission_required('parking_rentals.add_parkingrental')( concept_edit), {'concept_form': ParkingRentalForm}, name='parkingrental_edit'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/delete/$', custom_permission_required('parking_rentals.add_parkingrental')( concept_delete), {'concept_form': ParkingRentalForm}, name='parkingrental_delete'), ]
urlpatterns = [ url(r'^balance/$', views.cash_desk_balance, name='cash_desk_balance'), url(r'^close/$', views.cash_desk_close, name='cash_desk_close'), url(r'^closures/$', views.CashCloseList.as_view(), name='cashclose_list'), url(r'^closures/(?P<cashclose_code>CC[A-F0-9]+)/$', views.cashclose_row, name='cashclose_row'), url(r'^closures/(?P<cashclose_code>CC[A-F0-9]+)/detail/$', views.cashclose_detail, name='cashclose_detail'), url(r'^closures/(?P<cashclose_code>CC[A-F0-9]+)/document/$', views.cashclose_document, name='cashclose_document'), url(r'^deposits/new/(?P<transaction_code>T[A-F0-9]{10})$', custom_permission_required('cash_desk.add_cashfloatdeposit')( concept_edit), {'concept_form': CashFloatDepositForm}, name='cashfloatdeposit_new'), url(r'^deposits/(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)$', custom_permission_required('cash_desk.add_cashfloatdeposit')( concept_detail), {'concept_form': CashFloatDepositForm}, name='cashfloatdeposit_detail'), url(r'^deposits/(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/edit/$', custom_permission_required('cash_desk.add_cashfloatdeposit')( concept_edit), {'concept_form': CashFloatDepositForm}, name='cashfloatdeposit_edit'), url(r'^deposits/(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/delete/$', custom_permission_required('cash_desk.add_cashfloatdeposit')( concept_delete), {'concept_form': CashFloatDepositForm}, name='cashfloatdeposit_delete'), url(r'^withdrawals/new/(?P<transaction_code>T[A-F0-9]{10})$', custom_permission_required('cash_desk.add_cashfloatwithdrawal')(
from clickgestion.ticket_sales.forms import TicketSalesForm from clickgestion.concepts.views import concept_delete, concept_detail, concept_edit from clickgestion.core.utilities import custom_permission_required from django.conf.urls import url urlpatterns = [ url(r'^new/(?P<transaction_code>T[A-F0-9]{10})$', custom_permission_required('ticket_sales.add_ticketsale')(concept_edit), {'concept_form': TicketSalesForm}, name='ticketsale_new'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)$', custom_permission_required('ticket_sales.add_ticketsale')(concept_detail), {'concept_form': TicketSalesForm}, name='ticketsale_detail'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/edit/$', custom_permission_required('ticket_sales.add_ticketsale')(concept_edit), {'concept_form': TicketSalesForm}, name='ticketsale_edit'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/delete/$', custom_permission_required('ticket_sales.add_ticketsale')(concept_delete), {'concept_form': TicketSalesForm}, name='ticketsale_delete'), ]
# Get the cashclose cashclose_code = kwargs.get('cashclose_code', None) cashclose = get_object_or_404(CashClose, code=cashclose_code) # Set initial filter data filter_data = { 'code': cashclose.code, } params = urllib.parse.urlencode(filter_data) # Return response = redirect('cashclose_list') response['Location'] += '?{}'.format(params) return response @method_decorator(custom_permission_required('cash_desk.add_cashclose'), name='dispatch') class CashCloseList(PaginationMixin, ListView): model = CashClose context_object_name = 'cashcloses' paginate_by = 8 # ListView.as_view will pass custom arguments here queryset = None header = gettext_lazy('Cash Desk Closures') request = None filter = None filter_data = None is_filtered = False def get(self, request, *args, **kwargs): # First
from clickgestion.apt_rentals.forms import AptRentalForm from clickgestion.concepts.views import concept_delete, concept_detail, concept_edit from clickgestion.core.utilities import custom_permission_required from django.conf.urls import url urlpatterns = [ url(r'^new/(?P<transaction_code>T[A-F0-9]{10})$', custom_permission_required('apt_rentals.add_aptrental')(concept_edit), {'concept_form': AptRentalForm}, name='aptrental_new'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)$', custom_permission_required('apt_rentals.add_aptrental')( concept_detail), {'concept_form': AptRentalForm}, name='aptrental_detail'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/edit/$', custom_permission_required('apt_rentals.add_aptrental')(concept_edit), {'concept_form': AptRentalForm}, name='aptrental_edit'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/delete/$', custom_permission_required('apt_rentals.add_aptrental')( concept_delete), {'concept_form': AptRentalForm}, name='aptrental_delete'), ]
from clickgestion.safe_rentals.forms import SafeRentalForm from clickgestion.concepts.views import concept_delete, concept_detail, concept_edit from clickgestion.core.utilities import custom_permission_required from django.conf.urls import url urlpatterns = [ url(r'^new/(?P<transaction_code>T[A-F0-9]{10})$', custom_permission_required('safe_rentals.add_saferental')( concept_edit), {'concept_form': SafeRentalForm}, name='saferental_new'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)$', custom_permission_required('safe_rentals.add_saferental')( concept_detail), {'concept_form': SafeRentalForm}, name='saferental_detail'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/edit/$', custom_permission_required('safe_rentals.add_saferental')( concept_edit), {'concept_form': SafeRentalForm}, name='saferental_edit'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/delete/$', custom_permission_required('safe_rentals.add_saferental')( concept_delete), {'concept_form': SafeRentalForm}, name='saferental_delete'), ]
from clickgestion.refunds.forms import RefundForm from clickgestion.concepts.views import concept_delete, concept_detail, concept_edit from clickgestion.core.utilities import custom_permission_required from clickgestion.refunds import views from django.conf.urls import url urlpatterns = [ #url(r'^$', # custom_permission_required('refunds.add_refund')(views.RefundList.as_view()), # name='refund_list'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/$', custom_permission_required('refunds.add_refund')(concept_detail), {'concept_form': RefundForm}, name='refund_detail'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/delete/$', custom_permission_required('refunds.add_refund')(concept_delete), {'concept_form': RefundForm}, name='refund_delete'), url(r'^(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/edit/$', custom_permission_required('refunds.add_refund')(concept_edit), {'concept_form': RefundForm}, name='refund_edit'), url(r'^new/(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/$', custom_permission_required('refunds.add_refund')(views.refund_new), name='refund_new'), url(r'^new/(?P<transaction_code>T[A-F0-9]{10})/$', custom_permission_required('refunds.add_refund')(views.refund_new), name='refund_new'), ]
from clickgestion.deposits.forms import AptRentalDepositForm, DepositReturnForm, ParkingRentalDepositForm, SafeRentalDepositForm from clickgestion.concepts.views import concept_delete, concept_detail, concept_edit from clickgestion.core.utilities import custom_permission_required from clickgestion.deposits import views from django.conf.urls import url urlpatterns = [ #url(r'^$', views.DepositList.as_view(), # name='deposit_list'), url(r'^aptrental/new/(?P<transaction_code>T[A-F0-9]{10})$', custom_permission_required('deposits.add_aptrentaldeposit')(concept_edit), {'concept_form': AptRentalDepositForm}, name='aptrentaldeposit_new'), url(r'^aptrental/(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)$', custom_permission_required('deposits.add_aptrentaldeposit')(concept_detail), {'concept_form': AptRentalDepositForm}, name='aptrentaldeposit_detail'), url(r'^aptrental/(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/edit/$', custom_permission_required('deposits.add_aptrentaldeposit')(concept_edit), {'concept_form': AptRentalDepositForm}, name='aptrentaldeposit_edit'), url(r'^aptrental/(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)/delete/$', custom_permission_required('deposits.add_aptrentaldeposit')(concept_delete), {'concept_form': AptRentalDepositForm}, name='aptrentaldeposit_delete'), url(r'^returns/(?P<concept_code>T[A-F0-9]{10}-[A-Z0-9]+)$', custom_permission_required('deposits.add_depositreturn')(concept_detail), {'concept_form': DepositReturnForm},