Exemple #1
0
def timetable_filler(facility, weekday, index, opening, closing):
    if weekday >= 0 and index >= 0:
        try:
            op_time = facility.openingtime_set.get(
                weekday=weekday,
                index=index
            )
        except OpeningTime.DoesNotExist:
            op = OpeningTime(
                facility=facility,
                weekday=weekday,
                opening=(opening or None),
                closing=(closing or None),
                index=index
            )
            try:
                op.save()
            except ValidationError, exc:
                return {"success": False, "error": "%r" % exc}
        else:
            if opening is None and closing is None:
                op_time.delete()
            else:
                op_time.opening = opening or op_time.opening
                op_time.closing = closing or op_time.closing
                try:
                    op_time.save(force_update=True)
                except ValidationError, exc:
                    return {"success": False, "error": "%r" % exc}
Exemple #2
0
def timetable_filler(facility, weekday, index, opening, closing):
    if weekday >= 0 and index >= 0:
        try:
            op_time = facility.openingtime_set.get(weekday=weekday,
                                                   index=index)
        except OpeningTime.DoesNotExist:
            op = OpeningTime(facility=facility,
                             weekday=weekday,
                             opening=(opening or None),
                             closing=(closing or None),
                             index=index)
            try:
                op.save()
            except ValidationError, exc:
                return {"success": False, "error": "%r" % exc}
        else:
            if opening is None and closing is None:
                op_time.delete()
            else:
                op_time.opening = opening or op_time.opening
                op_time.closing = closing or op_time.closing
                try:
                    op_time.save(force_update=True)
                except ValidationError, exc:
                    return {"success": False, "error": "%r" % exc}
Exemple #3
0
def edit_hospital(request, id_):
    form = FacilityForm(request.POST)
    if form.is_valid():
        try:
            current_obj = Facility.objects.get(id=id_)
        except Facility.DoesNotExist:
            return {'success': False, 'error': 'Not found'}

        data = form.cleaned_data

        # timetable data
        weekday = data["weekday"]
        optime = data["optime"]
        opening = data["opening"]
        closing = data["closing"]
        del data["weekday"], data["optime"], data["opening"], \
            data["closing"]

        if weekday >= 0 and optime >= 0:
            try:
                op_time = current_obj.openingtime_set.get(
                    weekday=weekday,
                    index=optime
                )
            except OpeningTime.DoesNotExist:
                op = OpeningTime(
                    facility=current_obj,
                    weekday=weekday,
                    opening=(opening or None),
                    closing=(closing or None),
                    index=optime
                )
                try:
                    op.save()
                except ValidationError, exc:
                    return {"success": False, "error": "%r" % exc}
            else:
                if opening is None and closing is None:
                    op_time.delete()
                else:
                    op_time.opening = opening or op_time.opening
                    op_time.closing = closing or op_time.closing
                    try:
                        op_time.save(force_update=True)
                    except ValidationError, exc:
                        return {"success": False, "error": "%r" % exc}