def can_create_group(user): """define who can access""" if can_access(user): try: preferences = UserPermissions.objects.get(user=user) return preferences.can_create_group except UserPermissions.DoesNotExist: return True # allowed by default return False
def get_children(self): """returns children""" children = [] try: request = RequestManager().get_request() if can_access(request.user): for item in self.custommenuitem_set.all(): if item.only_for_users.count() == 0 or (request.user in item.only_for_users.all()): if item.get_url(*request.resolver_match.args, **request.resolver_match.kwargs): children.append(item) except (RequestNotFound, AttributeError): pass return children
def get_children(self): """returns children""" children = [] try: request = RequestManager().get_request() if can_access(request.user): for item in self.custommenuitem_set.all(): if item.only_for_users.count() == 0 or ( request.user in item.only_for_users.all()): if item.get_url(*request.resolver_match.args, **request.resolver_match.kwargs): children.append(item) except (RequestNotFound, AttributeError): pass return children
def get_context_data(self, **kwargs): """get context data""" context = super(SalesDocumentViewMixin, self).get_context_data(**kwargs) if not self.is_public and not can_access(self.request.user): raise PermissionDenied action = self.get_action() try: sale = action.sale except Sale.DoesNotExist: raise Http404 if self.is_public: is_read_only = True else: if action.type: is_read_only = action.status in action.type.storemanagementactiontype.readonly_status.all() else: is_read_only = False action_serializer = ActionSerializer(self.get_action()) action_data = Utf8JSONRenderer().render(action_serializer.data) sale_serializer = SaleSerializer(sale) sale_data = Utf8JSONRenderer().render(sale_serializer.data) sale_items_serializer = SaleItemSerializer(self.get_sale_items(), many=True) sale_items_data = Utf8JSONRenderer().render(sale_items_serializer.data) vat_rates_serializer = VatRateSerializer(VatRate.objects.all(), many=True) vat_rates_data = Utf8JSONRenderer().render(vat_rates_serializer.data) discounts_serializer = DiscountSerializer(Discount.objects.filter(active=True), many=True) discounts_data = Utf8JSONRenderer().render(discounts_serializer.data) context['action'] = action context['is_read_only'] = is_read_only context['is_pdf'] = self.is_pdf context['DJANGO_APP'] = """ var DJANGO_APP = {{ action: {0}, sale_items: {1}, sale: {2}, vat_rates: {3}, isPdf: {4}, isPublic: {5}, isReadOnly: {6}, discounts: {7}, }};""".format( action_data, sale_items_data, sale_data, vat_rates_data, 'true' if self.is_pdf else 'false', 'true' if self.is_public else 'false', 'true' if is_read_only else 'false', discounts_data ) return context
def get_context_data(self, **kwargs): """get context data""" context = super(SalesDocumentViewMixin, self).get_context_data(**kwargs) if not self.is_public and not can_access(self.request.user): raise PermissionDenied action = self.get_action() sale = self.get_sale(action) if self.is_public: is_read_only = True else: if action.frozen: is_read_only = True else: if action.type: is_read_only = action.status in action.type.storemanagementactiontype.readonly_status.all( ) else: is_read_only = False action_serializer = ActionSerializer(self.get_action()) action_data = Utf8JSONRenderer().render(action_serializer.data) sale_serializer = SaleSerializer(sale) sale_data = Utf8JSONRenderer().render(sale_serializer.data) vat_total_serializer = VatTotalSerializer(sale.vat_total_amounts(), many=True) vat_total_data = Utf8JSONRenderer().render(vat_total_serializer.data) sale_items_serializer = SaleItemSerializer(self.get_sale_items(), many=True) sale_items_data = Utf8JSONRenderer().render(sale_items_serializer.data) vat_rates_serializer = VatRateSerializer(VatRate.objects.all(), many=True) vat_rates_data = Utf8JSONRenderer().render(vat_rates_serializer.data) discounts_serializer = DiscountSerializer( Discount.objects.filter(active=True), many=True) discounts_data = Utf8JSONRenderer().render(discounts_serializer.data) context['action'] = action context['is_read_only'] = is_read_only context['is_pdf'] = self.is_pdf context["references_text"] = sale.get_references_text() context['DJANGO_APP'] = """ var DJANGO_APP = {{ action: {0}, sale_items: {1}, sale: {2}, vat_rates: {3}, isPdf: {4}, isPublic: {5}, isReadOnly: {6}, discounts: {7}, vat_totals: {8}, showPercentage: {9}, }};""".format( action_data, sale_items_data, sale_data, vat_rates_data, 'true' if self.is_pdf else 'false', 'true' if self.is_public else 'false', 'true' if is_read_only else 'false', discounts_data, vat_total_data, 'true' if getattr( settings, 'BALAFON_STORE_SHOW_PERCENTAGE', False) else 'false') return context
def dispatch(self, *args, **kwargs): if self.only_staff and not can_access(self.request.user): raise PermissionDenied() return super(XlsExportView, self).dispatch(*args, **kwargs)