def payments(request): username = request.user.username can_view_payment = PermissionManager.user_can_view_payment(request.user) if not can_view_payment: logger.warning("PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied context = {'content_title': CORE_STRINGS.DASHBOARD_PAYMENTS_TITLE} queryset = Payment.objects.order_by('-created_at').all() template_name = "payment/payment_list.html" page_title = "Payments - " + settings.SITE_NAME page = request.GET.get('page', 1) paginator = Paginator(queryset, utils.PAGINATED_BY) try: list_set = paginator.page(page) except PageNotAnInteger: list_set = paginator.page(1) except EmptyPage: list_set = None context['page_title'] = page_title context['payment_list'] = list_set context.update(get_view_permissions(request.user)) return render(request, template_name, context)
def policy_groups(request): username = request.user.username can_access_dashboard = PermissionManager.user_can_access_dashboard( request.user) if not can_access_dashboard: logger.warning("Payment : PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied can_view_policy = PermissionManager.user_can_view_policy(request.user) can_add_policy = PermissionManager.user_can_add_policy(request.user) if not can_view_policy: logger.warning("PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied context = {'content_title': CORE_STRINGS.DASHBOARD_POLICY_GROUPS_TITLE} queryset = PaymentPolicyGroup.objects.all() template_name = "payment/policy_group_list.html" page_title = "Policy Group - " + settings.SITE_NAME page = request.GET.get('page', 1) paginator = Paginator(queryset, utils.PAGINATED_BY) try: list_set = paginator.page(page) except PageNotAnInteger: list_set = paginator.page(1) except EmptyPage: list_set = None context['page_title'] = page_title context['groups'] = list_set context.update(get_view_permissions(request.user)) return render(request, template_name, context)
def policy_group_details(request, group_uuid=None): username = request.user.username can_access_dashboard = PermissionManager.user_can_access_dashboard( request.user) if not can_access_dashboard: logger.warning("Payment : PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied can_view_policy = PermissionManager.user_can_view_policy(request.user) if not can_view_policy: logger.warning("PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied context = {'content_title': CORE_STRINGS.DASHBOARD_POLICY_GROUP_TITLE} group = get_object_or_404(PaymentPolicyGroup, policy_group_uuid=group_uuid) template_name = "payment/policy_group_detail.html" page_title = "Policy Group Details - " + settings.SITE_NAME context['page_title'] = page_title context['group'] = group context['members'] = group.members.all() context['users'] = User.objects.filter(is_active=True, is_superuser=False) context.update(get_view_permissions(request.user)) return render(request, template_name, context)
def policy_create(request): username = request.user.username can_access_dashboard = PermissionManager.user_can_access_dashboard( request.user) if not can_access_dashboard: logger.warning("Payment : PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied can_add_policy = PermissionManager.user_can_add_policy(request.user) if not can_add_policy: logger.warning("PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied page_title = _("Create Policy") + ' | ' + settings.SITE_NAME template_name = "payment/policy_create.html" form = None if request.method == "POST": form = PaymentPolicyForm(request.POST) if form.is_valid(): logger.info("PaymentPolicyForm for instance %s is valid", form.cleaned_data['commission']) form.save() return redirect('payment:policies') else: form = PaymentPolicyForm() logger.info("Edit PaymentPolicyForm is not valid. Errors : %s", form.errors) elif request.method == "GET": form = PaymentPolicyForm() context = { 'page_title': page_title, 'template_name': template_name, 'form': form, 'can_add_policy': can_add_policy, 'content_title': CORE_STRINGS.DASHBOARD_POLICY_CREATE_TITLE } context.update(get_view_permissions(request.user)) return render(request, template_name, context)
def policy_update(request, policy_uuid=None): username = request.user.username can_access_dashboard = PermissionManager.user_can_access_dashboard( request.user) if not can_access_dashboard: logger.warning("Payment : PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied can_change_policy = PermissionManager.user_can_change_policy(request.user) if not can_change_policy: logger.warning("PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied page_title = _("Edit Policy") + ' | ' + settings.SITE_NAME instance = get_object_or_404(PaymentPolicy, policy_uuid=policy_uuid) template_name = "payment/policy_update.html" if request.method == "POST": form = PaymentPolicyForm(request.POST, instance=instance) if form.is_valid(): logger.info("PaymentPolicyForm for instance %s is valid", form.cleaned_data['commission']) form.save() return redirect('payment:policies') else: logger.info("[failed] Edit PaymentPolicyForm commission : %s", request.POST.copy()['commission']) logger.info("Edit PaymentPolicyForm is not valid. Errors : %s", form.errors) form = PaymentPolicyForm(instance=instance) context = { 'page_title': page_title, 'template_name': template_name, 'policy': instance, 'form': form, 'can_change_policy': can_change_policy, 'content_title': CORE_STRINGS.DASHBOARD_POLICY_UPDATE_TITLE } context.update(get_view_permissions(request.user)) return render(request, template_name, context)
def payment_details(request, payment_uuid=None): username = request.user.username can_view_payment = PermissionManager.user_can_view_payment(request.user) if not can_view_payment: logger.warning("PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied context = {'content_title': CORE_STRINGS.DASHBOARD_PAYMENT_TITLE} payment = get_object_or_404(Payment, payment_uuid=payment_uuid) can_be_updated = payment_service.payment_can_be_updated(payment) template_name = "payment/payment_detail.html" page_title = "Payment Details - " + settings.SITE_NAME context['page_title'] = CORE_STRINGS.DASHBOARD_PAYMENT_TITLE context['payment'] = payment context['can_be_updated'] = can_be_updated context['fee'] = payment.balance_amount - payment.amount context.update(get_view_permissions(request.user)) return render(request, template_name, context)
def policy_group_update(request, group_uuid=None): username = request.user.username can_access_dashboard = PermissionManager.user_can_access_dashboard( request.user) if not can_access_dashboard: logger.warning("payment : PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied can_change_policy = PermissionManager.user_can_change_policy(request.user) if not can_change_policy: logger.warning("PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied page_title = _("Edit Payment Policy Group") + ' | ' + settings.SITE_NAME instance = get_object_or_404(PaymentPolicyGroup, policy_group_uuid=group_uuid) template_name = "payment/policy_group_update.html" if request.method == "POST": form = PaymentPolicyGroupUpdateForm(request.POST, instance=instance) if form.is_valid(): form.save() return redirect('payment:policy-groups') else: logger.info( "Edit PaymentPolicyGroupUpdateForm is not valid. Errors : %s", form.errors) form = PaymentPolicyGroupForm(instance=instance) context = { 'page_title': page_title, 'template_name': template_name, 'group': instance, 'form': form, 'policies': PaymentPolicy.objects.all(), 'can_change_policy': can_change_policy, 'content_title': CORE_STRINGS.DASHBOARD_POLICY_GROUP_UPDATE_TITLE } context.update(get_view_permissions(request.user)) return render(request, template_name, context)
def payment_home(request): username = request.user.username if not PermissionManager.user_can_view_payment(request.user): logger.warning( "Payment Page : PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied template_name = "payment/payment_home.html" page_title = _("Payment-Home") recent_payments = Payment.objects.select_related().order_by( '-created_at')[:5] context = { 'page_title': page_title, 'recent_payments': recent_payments, 'content_title': CORE_STRINGS.DASHBOARD_PAYMENT_HOME_TITLE } context.update(get_view_permissions(request.user)) return render(request, template_name, context)
def policy_details(request, policy_uuid=None): username = request.user.username can_access_dashboard = PermissionManager.user_can_access_dashboard( request.user) if not can_access_dashboard: logger.warning("Payment : PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied can_view_policy = PermissionManager.user_can_view_policy(request.user) if not can_view_policy: logger.warning("PermissionDenied to user %s for path %s", username, request.path) raise PermissionDenied context = {'content_title': CORE_STRINGS.DASHBOARD_POLICY_TITLE} policy = get_object_or_404(PaymentPolicy, policy_uuid=policy_uuid) template_name = "payment/policy_detail.html" page_title = "Policy Details - " + settings.SITE_NAME context['page_title'] = page_title context['policy'] = policy context.update(get_view_permissions(request.user)) return render(request, template_name, context)