示例#1
0
    def post(self, request, *args, **kwargs):
        if "year" not in request.POST or "month" not in request.POST or "day" not in request.POST or "method" not in request.POST:
            return HttpResponseBadRequest(
                json.dumps({"message": "missing parameter"}))

        method_pk = request.POST.get("method")
        try:
            new_date = date(int(request.POST.get("year")),
                            int(request.POST.get("month")),
                            int(request.POST.get("day")))

            # 指定日以前のを全部チェック
            if "check_all" in request.POST and request.POST.get(
                    "check_all") == "1":
                Data.filter_checkeds(
                    Data.get_method_data(Data.get_range_data(None, new_date),
                                         method_pk),
                    [False]).update(checked=True)
        except ValueError:
            return HttpResponseBadRequest(
                json.dumps({"message": "date format is invalid"}))

        try:
            # チェック日を更新
            CheckedDate.set(method_pk, new_date)
        except CheckedDate.DoesNotExist:
            return HttpResponseBadRequest(
                json.dumps({"message": "method id is invalid"}))

        return HttpResponse()
示例#2
0
 def test_set(self):
     CheckedDate.set(1, date(2001, 1, 1))
     self.assertEqual(CheckedDate.get(1).date, date(2001, 1, 1))