Example #1
0
 def post(self, request, id):
     category = get_object_or_404(Category, id=id)
     self.check_login()
     if request.user.id != category.user_id:
         self.raise_error('Permission denied.', status=403)
     category_name = request.POST.get('name')
     if not category_name:
         self.raise_error(u'분류 이름을 입력하세요.',
             status=400) # 400 Bad Request
     category.name = category_name
     category.save()
     return serialize_category(category)
Example #2
0
 def post(self, request, name):
     self.check_login()
     if request.user.username != name:
         self.raise_error('Permission denied.', status=403)
     category_name = request.POST.get('name')
     if not category_name:
         self.raise_error(u'분류 이름을 입력하세요.',
             status=400) # 400 Bad Request
     category = Category.objects.create(
         user=request.user,
         name=category_name
     )
     record_ids = request.POST.getlist('record_ids[]')
     Record.objects.filter(user=request.user, id__in=record_ids) \
         .update(category=category)
     return serialize_category(category)
Example #3
0
 def post(self, request, name):
     self.check_login()
     if request.user.username != name:
         self.raise_error('Permission denied.', status=403)
     category_name = request.POST.get('name')
     if not category_name:
         # 400 Bad Request
         self.raise_error(u'분류 이름을 입력하세요.', status=400)
     max = (request.user.category_set
            .aggregate(models.Max('position'))['position__max'])
     if max is None:
         next_pos = 0
     else:
         next_pos = max + 1
     category = Category.objects.create(
         user=request.user,
         name=category_name,
         position=next_pos,
     )
     record_ids = request.POST.getlist('record_ids[]')
     Record.objects.filter(user=request.user, id__in=record_ids) \
         .update(category=category)
     return serialize_category(category)