def setUpClass(cls): user = User.objects.create_user(username = '******', password = '******') order = Order(user=user, title = 'test_title', uri = 'test_uri', vendor = 'test_vendor', date = '1234/56/78', phase=0, volume = -1) order.save() user = User.objects.create_user(username = '******', password = '******') order = Order(user=user, title = 'test_title', uri = 'test_uri', vendor = 'test_vendor', date = '1234/56/78', phase=0, volume = -1) order.save()
def save(request): args = getArgs(request) # purify keys args = { k: args[k] for k in ('title', 'new_title', 'vendor', 'date', 'uri', 'thumb', 'phase', 'volume') if k in args } # title should not be null if not args['title']: raise ValueError('`title` is empty') newTitle = None if 'new_title' in args: newTitle = args['new_title'] del args['new_title'] thumbUri = None if 'thumb' in args: thumbUri = args['thumb'] del args['thumb'] try: result = Order.objects.get(user__exact=request.user, title__exact=args['title']) del args['title'] # item exists, update for k in args: setattr(result, k, args[k]) if newTitle: result.title = newTitle except Order.DoesNotExist: # new item, insert result = Order(user=request.user, **args) result.retrieve_thumb(thumbUri) except Order.MultipleObjectsReturned: # TODO new exception raise result.save() return { 'title': result.title, 'vendor': result.vendor, 'date': result.date, 'uri': result.uri, 'thumb': '' if not result.thumb else result.thumb.url, 'phase': result.phase, 'volume': result.volume, }
def setUpClass(cls): user = User.objects.create_user(username='******', password='******') order = Order(user=user, title='test_title', uri='test_uri', vendor='test_vendor', date='1234/56/78', phase=0, volume=-1) order.save() user = User.objects.create_user(username='******', password='******') order = Order(user=user, title='test_title', uri='test_uri', vendor='test_vendor', date='1234/56/78', phase=0, volume=-1) order.save()
def setUpClass(cls): user = User.objects.create_user(username = '******', password = '******') o = Order(title = 'to-be-deleted', phase = -1, volume = -1, user=user) o.save()
def setUpClass(cls): user = User.objects.create_user(username='******', password='******') o = Order(title='to-be-deleted', phase=-1, volume=-1, user=user) o.save()