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 add_holiday():
    month = request.args.get('month')
    date = request.args.get('date')
    event = request.args.get('event')
    try:
        holiday = Holiday(month=month, date=date, event=event)
        db.session.add(holiday)
        db.session.commit()
        return "Holiday added. holiday id={}".format(holiday.id)
    except Exception as e:
        return (str(e))
Exemple #3
0
def add_book_form():
    if request.method == 'POST':
        month = request.form.get('month')
        date = request.form.get('date')
        event = request.form.get('event')
        try:
            holiday = Holiday(month=month, date=date, event=event)
            db.session.add(holiday)
            db.session.commit()
            return "Holiday added. holiday id={}".format(holiday.id)
        except Exception as e:
            return (str(e))
    return render_template("getdata.html")
Exemple #4
0
def add_info():
    if request.method == 'POST':
        name = request.form.get('name')
        address = request.form.get('address')
        city = request.form.get('event')
        try:
            table = Holiday(name=name, address=address, city=city)
            db.session.add(table)
            db.session.commit()
            return "Info added. info id={}".format(table.id)
        except Exception as e:
            return (str(e))
    return render_template("studentdata.html")
Exemple #5
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)
Exemple #7
0
    def mutate(self, info, start_date, end_date, holiday_type):
        current_user = get_jwt_identity()
        user = User.query.filter_by(email=current_user).first()
        end_date = end_date + timedelta(days=1)
        counted_holiday = 0
        annual_count = 0
        alternative_count = 0

        if start_date > end_date:
            raise GraphQLError('날짜가 올바르지 않습니다. 날짜를 다시 지정 해주세요.')

        if holiday_type != 'ALLDAY':
            if (end_date - start_date).days != 1:
                raise GraphQLError('반차는 하루 단위로 사용 가능합니다.')
            counted_holiday = 0.5
        else:
            counted_holiday = (end_date - start_date).days

        if user.annual + user.alternative < counted_holiday:
            raise GraphQLError('잔여 연차/대체휴무가 부족합니다.')
        else:
            if user.alternative > counted_holiday:
                user.alternative = user.alternative - counted_holiday
                alternative_count = counted_holiday
            else:
                counted_holiday = counted_holiday - user.alternative
                alternative_count = user.alternative
                annual_count = counted_holiday
                user.alternative = 0
                user.annual = user.annual - counted_holiday

        new_holiday = Holiday(start_date=start_date,
                              end_date=end_date,
                              user_id=user.id,
                              holiday_type=holiday_type,
                              annual_count=annual_count,
                              alternative_count=alternative_count)
        db.session.add(new_holiday)
        try:
            db.session.commit()
        except Exception as e:
            print(e)
            db.session.rollback()
            raise GraphQLError('Internal Server Error')
        return HolidayCreate(holiday=new_holiday)
Exemple #8
0
def get_weekday_display():
    now = datetime.datetime.now(pytz.timezone('America/Argentina/Buenos_Aires'))
    date = now.date()
    weekday = date.weekday()

    # This import MUST be here because if we put this at the top
    # a circular import is created between models.py and utils.py
    from models import Holiday

    # Check if today is declarated as Holiday and use that times
    holiday = Holiday.all()
    holiday.filter('date =', date)
    if holiday.count():
        return holiday[0].time_days

    # Testing
    # weekday = 6
    if weekday == 5:
        weekday = 'Sabados'
    elif weekday == 6:
        weekday = 'Domingos'
    else:
        weekday = 'Habiles'
    return weekday
Exemple #9
0
 def get(self, key):
     logging.info('get %s' % (key))
     return self.to_dto(Holiday.get(key))