Exemplo n.º 1
0
def remove_calendar_event(dash):
    if read_config('dashboard_remove_early', '0') == '1':
        if dash.fk_calendar_dashboard.exists():
            cal = dash.fk_calendar_dashboard.get()
            today_sh = JalaliDatetime.today()
            if cal.cal_day > today_sh.day and cal.cal_month >= today_sh.month and cal.cal_year >= today_sh.year:
                cal.delete()
            elif cal.cal_day == today_sh.day and cal.cal_month == today_sh.month and cal.cal_year == today_sh.year:
                if cal.work_time.start_time >= today_sh.time():
                    cal.delete()
Exemplo n.º 2
0
def generate_username():
    try:
        pat = read_config('login_pattern', '%Y')
        jd = JalaliDatetime.today()
        pat = jd.strftime(pat)
        rand = random.randint(100, 999)
        pat = pat.replace("RAND", str(rand))
        return pat
    except Exception as e:
        print e.message
        return ''
Exemplo n.º 3
0
def get_next_4_days(event_id, only_times_pk=False):
    init_days = int(read_config('calendar_show_days', 5))
    today = JalaliDatetime.today()
    res = []
    days_collected = False
    # for i in range(0, init_days + 1):
    i = 0
    while not days_collected:
        now = today + timedelta(days=i)
        while get_holidays(now.month, now.day):
            i += 1
            now = today + timedelta(days=i)
        qs = Calendar.objects.filter(cal_month=now.month,
                                     cal_year=now.year,
                                     cal_day=now.day,
                                     work_time__event_type=event_id)
        nw = get_match_day(now.weekday())
        if qs.exists():
            rsc = WorkingTime.objects.filter(
                week_day=nw, is_deleted=False, event_type=event_id).filter(
                    fk_calendar_working_time__cal_day=now.day,
                    fk_calendar_working_time__cal_month=now.month,
                    fk_calendar_working_time__cal_year=now.year).annotate(
                        rx=Count('fk_calendar_working_time__work_time')
                    ).filter(resource__lte=F('rx')).values_list('pk',
                                                                flat=True)
            times = WorkingTime.objects.filter(
                week_day=nw, event_type=event_id).exclude(pk__in=rsc)
            if now.day == today.day:
                times = times.filter(start_time__gte=datetime.today().time())
            # for r in rsc:
            #     print r.name,";", r.rx
            # times = rsc
        else:
            if now.day == today.day:
                times = WorkingTime.objects.filter(
                    week_day=nw,
                    is_deleted=False,
                    event_type=event_id,
                    start_time__gte=datetime.today().time())
            else:
                times = WorkingTime.objects.filter(week_day=nw,
                                                   is_deleted=False,
                                                   event_type=event_id)
        if only_times_pk:
            res.append(times.values_list('pk', flat=True))
        else:
            times = times.values('pk', 'name', 'start_time', 'end_time',
                                 'resource')
            res.append(FreeTimes(list(times), now.strftime('%Y-%m-%d %A')))
        i += 1
        if len(res) >= init_days:
            days_collected = True
    return res
Exemplo n.º 4
0
def get_month_expired_users_count():
    try:
        now = JalaliDatetime.today()
        last_month = JalaliDatetime(now.year, now.month - 1, day=now.day)
        next_month = JalaliDatetime(now.year, now.month, day=now.day)
        last_month = last_month.to_datetime()
        next_month = next_month.to_datetime()
        return UserCurrentService.objects.filter(
            expire_date__lt=next_month, expire_date__gt=last_month).count()
    except Exception as e:
        print e.message
        return 0
Exemplo n.º 5
0
 def generate_code():
     jd = JalaliDatetime.today()
     ix = jd.strftime(read_config('indicator_pattern', '%y-%m'))
     return ix