Exemple #1
0
def get_file(req, area):
    """

    :param req:
    :param area:
    :return:
    """
    if req.method == 'POST':
        try:
            obj = req.FILES.get('file')
            filename = obj.name
            path = os.getcwd() + r'\\static\\' + filename
            if not os.path.exists(path):
                with open(path, 'wb') as f:
                    for chunk in obj.chunks():
                        f.write(chunk)
                f.close()
            # workbook = open_workbook(path)
            workbook = None
            sheet = workbook.sheet_by_index(0)
            delall(area)
            for i in range(1, sheet.nrows):
                day = str(sheet.row_values(i)[0])
                d = day[0:4] + u'/' + str(int(day[4:6])) + u'/' + str(
                    int(day[6:8]))
                flag = int(sheet.row_values(i)[1])
                holiday = Holiday(day=d, flag=flag, area=area)
                holiday.save()
        except:
            print '文件不匹配'
Exemple #2
0
def api_holiday_add(request):
    name = request.POST.get('name')
    time = request.POST.get('time')
    holiday = Holiday(name=name)
    holiday.data = time
    holiday.year = time.split('-')[0]
    holiday.save()
    return render_json({'success': True})
 def test_holiday(self):
     """User should not be able to make a reservation on holiday day"""
     # Create a holiday
     holiday = Holiday(name="Test Holiday", active=True, date=dt.date(2032, 12, 13))
     holiday.save()
     # Try to make a reservation
     holiday_date = {"year": 2032, "month": 12, "day": 13}
     response = self.client.post(reverse('reservations_reservation'), holiday_date, follow=True)
     self.assertEqual(response.status_code, 403)
     self.assertEqual(SimpleReservation.objects.all().count(), 0)
     # Disable holiday and re-try to make a reservation
     holiday.active = False
     holiday.save()
     response = self.client.post(reverse('reservations_reservation'), holiday_date, follow=True)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(SimpleReservation.objects.all().count(), 1)