Beispiel #1
0
def email_digest():
    timezone = pytz.timezone('US/Eastern')
    date = doneit.timezone.localize(datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)) # midnight today

    doneit.log("Sending digest for %s at %s" % (request.forms.get('name'), request.forms.get('email')))
    r = requests.get("%s/%s?date=%s" % (doneit.digest_composition_service_url,
                                        request.forms.get('project_id'),
                                        date.strftime(doneit.date_format_url)))
    tasks = r.json['tasks']
    to = request.forms.get('email')
    subject = "Daily digest for %s" % doneit.get_by_id('projects', request.forms.get('project_id'))['name']
    body = []
    body.append("Project status as of %s\n\n" % datetime.datetime.now().strftime(doneit.date_format_digest))
    for task_type in tasks:
        body.append("%s:\n" % task_type.title())
        task_list = json_util.loads(r.json['tasks'][task_type])
        if len(task_list) > 0:
            for task in task_list:
                user = doneit.get_by_id('users', task['user_id'])
                body.append("%s %s - %s\n" % (u'\u2022', task['comment'], user['name']))
        else:
            body.append("%s None\n" % (u'\u2022'))
        body.append('\n')

    sign(body)
    body = ''.join(body)

    doneit.send_email(to, subject, body)
Beispiel #2
0
def get_project(id):
    entity = doneit.get_by_id('projects', id)
    entity['admin'] = doneit.get_by_id("users", entity['admin_id'])
    if request.query.date:
        entity['date'] = doneit.timezone.localize(datetime.datetime.fromtimestamp(time.mktime(time.strptime(request.query.date, "%y-%m-%d"))))
    else:
        entity['date'] = doneit.timezone.localize(datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)) # midnight today
        if (doneit.timezone.localize(datetime.datetime.now()).hour > int(entity['digest-hour'])):
            # Cutoff has already passed for today
            entity['date'] = entity['date'] + timedelta(days=1)

    # Offset date based on when digest is sent (plus a magic number)
    entity['date'] = entity['date'] + timedelta(hours=int(entity['digest-hour']))

    for task_type in ['done', 'todo', 'block', 'doing']:
        entity[task_type] = doneit.get_tasks(task_type, entity['_id'], entity['date'])
    return template('project', loggedin=check(request), project=entity)
Beispiel #3
0
def email_reminder():
    doneit.log("Sending reminder for %s at %s" % (request.forms.get('name'), request.forms.get('email')))

    project = doneit.get_by_id('projects', request.forms.get('project_id'))

    to = request.forms.get('email')
    subject = "Daily reminder for %s" % project['name']
    body = []
    body.append("Please remember to provide your status for %s.\n" % project['name'])
    sign(body)
    body = ''.join(body)

    doneit.send_email(to, subject, body)
Beispiel #4
0
def post_tasks():
    if check(request):
        entity = dict()
        user_id = request.get_cookie("_id")
        project_id = doneit.get_by_id('users', user_id)["project_id"]
        for field in ['type', 'comment']:
            entity[field] = request.forms.get(field)
        entity['user_id'] = user_id
        entity['project_id'] = project_id
        r = requests.post(doneit.entry_input_service_url + "/task", entity)
        if r.json['status'] == "success":
            redirect("/projects/%s" % (project_id))
        else:
            redirect("/tasks")
    else:
        redirect("/login?ret=%s" % (request.path))
Beispiel #5
0
def github_post_commit():
    _id = request.query.id
    key = request.query.key
    if _id and key and doneit.get_by_id("projects", _id)["secret-key"] == key:
        for commit in json.loads(request.forms["payload"])["commits"]:
            author = commit["author"]["email"]
            try:
                task = dict()
                task["user_id"] = ObjectId(doneit.get_user_by_email(author)["_id"])
                task["project_id"] = ObjectId(_id)
                task["type"] = "done"
                task["comment"] = commit["message"]
                task["date"] = datetime.datetime.utcnow()
                doneit.log("Added commit from " + author)
                doneit.add_task(task)
            except:
                doneit.log("Unknown git commit author:" + author_email)
    else:
        doneit.log("Tried to add task from github but authorization failed")
Beispiel #6
0
def digest_composition(project_id):
    project = doneit.get_by_id('projects', project_id)

    timezone = pytz.timezone('US/Eastern')
    if request.query.date:
        date = doneit.timezone.localize(datetime.datetime.fromtimestamp(time.mktime(time.strptime(request.query.date, "%y-%m-%d"))))
        doneit.log(request.query.date)
    else:
        date = doneit.timezone.localize(datetime.datetime.now().replace(hour=0,minute=0,second=0,microsecond=0)) # midnight today

    # Offset date based on when digest is sent
    date = date + timedelta(hours=int(project['digest-hour']))

    doneit.log("Digest requested for %s as of %s" % (project['name'], date))

    response = {'status':'success', 'tasks':{'done':[], 'todo':[], 'block':[], 'doing':[]}}
    for task_type in response['tasks']:
        task_list = doneit.get_tasks(task_type, project['_id'], date)
        response['tasks'][task_type] = json_util.dumps(task_list)

    return response
Beispiel #7
0
def get_project(message):
    # lookup from user id
    user = get_user(message)
    project = doneit.get_by_id('projects', user['project_id'])
    return project
Beispiel #8
0
def get_user(id):
    entity = doneit.get_by_id('users', id)
    return template('user', loggedin=check(request), user=entity)