示例#1
0
def cronjob():
    today = datetime.date.today()
    users = User.objects.filter(is_active=1).order_by('id')
    for i in users:
        if i.date_joined.month == today.month and i.date_joined.day == today.day:
            delta = today.year - i.date_joined.year
            if delta < len(year_delta):
                last = year_delta[delta]
            else:
                last = year_delta[-1]
            v = Vacation(user=i, begin=datetime.date.today(), last=last, note='ANNUAL')
            print i.username, last
            v.save()
示例#2
0
def vacation_setup():
    if not google.authorized:
        return redirect(url_for('google.login'))
    form = VacationForm()
    if form.validate_on_submit():
        vacation_request = Vacation(start_period=form.start.data,
                                    end_period=form.end.data,
                                    author=current_user)
        db.session.add(vacation_request)
        db.session.commit()
        flash(f'Leaving request submitted!', 'success')
        return redirect(url_for('index'))
    return render_template('setup.html', title='Vacation Setup', form=form)
示例#3
0
def import_user():
    with open('/Users/fred/work/mysite/a.txt', 'r') as f:
        for line in f:
            i = line.split()
            print i
            last_name = i[1].strip().decode('utf8')
            username = str(''.join(pypinyin.lazy_pinyin(last_name)))
            print last_name
            print username
            y, m, d = map(int, i[2].split('.'))
            print y, m, d
            u = User(
                is_staff=True,
                is_active=True,
                username=username,
                date_joined=datetime.datetime(y, m, d),
                last_name=last_name,
            )
            print u
            u.set_password(username)
            u.save()
            v = Vacation(user=u, begin=datetime.date.today(), last=i[0], note='INIT')
            v.save()
            print u.username, v.last