Beispiel #1
0
def generate_schedules(request):
    if request.method == "POST":

        # 開始
        log = Log()
        log.name = u"generate schedules"
        log.started_at = datetime.now()

        # ユーザ全員を取得
        users = User.all().fetch(1000)

        # 日付を取得
        today = datetime.today()
        target_day = date(today.year, today.month + 1, 1)
        nn_month = date(today.year, today.month + 2, 1)

        # 1日ずつスケジュールを入れる
        schedules = []
        while target_day < nn_month:

            # 時間をずらす
            for hour in range(9, 24):
                # 分をずらす
                for minutes in [0, 30]:
                    # ユーザずつ
                    for user in users:
                        # シフト
                        # 0/1: 月曜休みAM/月曜休みPM
                        # 2/3: 火曜休みAM/火曜休みPM
                        weekday = target_day.weekday()
                        if user.shift == weekday * 2 or user.shift == weekday * 2 + 1:
                            continue

                        # AM: 9 - 17
                        # PM: 15 - 23
                        if user.shift % 2 == 0 and hour > 18:
                            continue
                        if user.shift % 2 == 1 and hour < 15:
                            continue

                        # スケジュール入れる
                        target_datetime = datetime(target_day.year, target_day.month, target_day.day, hour, minutes)
                        schedule = Schedule(
                            name=generate_string(20), user=user, title=generate_string(100), schedule_at=target_datetime
                        )
                        # リストに追加
                        schedules.append(schedule)

            # 追加
            db.put(schedules)
            schedules = []
            # 1日追加
            target_day = target_day + timedelta(days=1)

        # 終了
        log.ended_at = datetime.now()
        log.put()

        return Response(status=200)
Beispiel #2
0
def index(request):
    user_count = User.all().count(999999)
    schedule_count = Schedule.all().count(999999)
    log_count = Log.all().count(999999)
    processes = Process.all().order('-created_at').fetch(1)
    process = processes[0] if len(processes) > 0 else None
    return render_to_response('index/index.html', {
        'user_count': user_count,
        'schedule_count': schedule_count,
        'log_count': log_count,
        'process': process,
    })
Beispiel #3
0
def delete_all_users(request):
    if request.method == "POST":
        db.delete(User.all())
    return Response(status=200)