Beispiel #1
0
 def save(self, *args, **kwargs):
     show_amount_as_pre_tax = self.cleaned_data['show_amount_as_pre_tax']
     recalculate = False
     if self.instance and self.initial_show_amount_as_pre_tax != show_amount_as_pre_tax:
         recalculate = True
     ret = super(StoreManagementActionTypeAdminForm,
                 self).save(*args, **kwargs)
     if recalculate:
         action_type = self.instance.action_type
         for action in action_type.action_set.all():
             try:
                 update_action_amount(action.sale)
             except (AttributeError,
                     StoreManagementActionType.DoesNotExist):
                 pass
         try:
             request = RequestManager().get_request()
             if request:
                 messages.success(
                     request,
                     _('Recalculate {0} {1}').format(
                         action_type.action_set.count(), action_type))
         except (RequestNotFound, AttributeError):
             pass
     return ret
Beispiel #2
0
 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
Beispiel #3
0
    def get_url(self, *args, **kwargs):
        """return the url to display"""
        if hasattr(self, '_cached_url'):
            return getattr(self, '_cached_url')
        url = ''
        if self.url:
            url = self.url
        elif self.reverse:
            reverse_kwargs = {}
            if self.reverse_kwargs:
                args_keywords = self.reverse_kwargs.split(',')
                for arg_keyword in args_keywords:
                    if ':' in arg_keyword:
                        slices = arg_keyword.split(':')
                        keyword = slices[0]
                        default_value = ":".join(slices[1:])
                    else:
                        keyword = arg_keyword
                        default_value = None
                    reverse_kwargs[keyword] = kwargs.get(
                        keyword, default_value)
            try:
                if not self.query_string:
                    query_string = ''
                    request = RequestManager().get_request()
                    if request:
                        query_string = "?" + request.META['QUERY_STRING'] or ''
                else:
                    query_string = self.query_string
                try:
                    url = reverse(self.reverse,
                                  kwargs=reverse_kwargs) + query_string
                except TypeError:
                    pass
            except NoReverseMatch as err:
                if settings.DEBUG:
                    print("NoReverseMatch", err)

        if url:
            setattr(self, '_cached_url', url)
        return url
Beispiel #4
0
 def setUp(self):
     """before each test"""
     RequestManager().clean()
     logging.disable(logging.CRITICAL)
     self._clean_files()
Beispiel #5
0
 def test_get_request_no_middleware(self):
     """if no request"""
     RequestManager().clean()
     self.assertRaises(RequestNotFound, RequestManager().get_request)
Beispiel #6
0
 def test_get_request(self):
     """retrieve request"""
     request1 = {'user': "******"}
     RequestMiddleware().process_request(request1)
     request2 = RequestManager().get_request()
     self.assertEqual(request1, request2)