def send_reminder_email(email_template, volunteer_relation): project = volunteer_relation.project volunteer = volunteer_relation.volunteer context = { 'first_name': volunteer.first_name, 'project_name': project.project_name, 'project_end_date': datetime_to_string( datetime_field_to_datetime(volunteer_relation.projected_end_date), DateTimeFormats.DATE_LOCALIZED), 'volunteer_start_date': datetime_to_string( datetime_field_to_datetime(volunteer_relation.application_date), DateTimeFormats.DATE_LOCALIZED) } email_msg = EmailMessage( subject="You're making a difference at " + project.project_name, from_email=_get_account_from_email(settings.EMAIL_VOLUNTEER_ACCT), to=[volunteer.email], ) email_msg = email_template.render(email_msg, context) send_email(email_msg, settings.EMAIL_VOLUNTEER_ACCT)
def update_if_commit_after_project_updated_time(project, latest_commit_date_string): project_updated_time = datetime_field_to_datetime(project.project_date_modified) latest_commit_time = datetime_field_to_datetime(latest_commit_date_string) # Need to add timezone info to time from github latest_commit_time = pytz.timezone("UTC").localize(latest_commit_time) if project_updated_time < latest_commit_time: print('Updating project {id} to latest timestamp: {time}'.format(id=project.id, time=latest_commit_date_string)) project.update_timestamp(latest_commit_time) project.recache() else: print('Did not update project {id} because last commit at {commit_time} before project updated time {project_update}'.format( id=project.id, commit_time=latest_commit_date_string, project_update=project_updated_time))
def handle_project_github_updates(project_github_link): project = project_github_link.link_project print('Handling updates for project {id} github link: {url}'.format( id=project.id, url=project_github_link.link_url)) last_updated_time = datetime_field_to_datetime( get_project_latest_commit_date(project_github_link.link_project)) owner_repo_name = get_owner_repo_name_from_public_url( project_github_link.link_url) repo_names = get_repo_names_from_owner_repo_name(owner_repo_name) raw_commits = [] for repo_name in repo_names: repo_url = get_repo_endpoint_from_owner_repo_name( repo_name, last_updated_time) print('Ingesting: ' + repo_url) repo_info = fetch_github_info(repo_url) if repo_info is not None and len(repo_info) > 0: repo_display_name = repo_name[0] + '/' + repo_name[1] raw_commits = raw_commits + list( map(lambda commit: [repo_display_name, commit], repo_info)) if len(raw_commits) > 0: # Take the most recent top X commits raw_commits.sort( key=lambda commit: commit[1]['commit']['author']['date'], reverse=True) raw_commits = raw_commits[:settings.MAX_COMMITS_PER_PROJECT] add_commits_to_database(project, raw_commits) latest_commit_date = raw_commits[0][1]['commit']['author']['date'] update_if_commit_after_project_updated_time(project, latest_commit_date) remove_old_commits(project)
def notify_project_owners_volunteer_renewed_email(volunteer_relation, comments): email_template = notify_volunteer_renewed_email_with_comments if comments else notify_volunteer_renewed_email_no_comment project_name = volunteer_relation.project.project_name projected_end_date = datetime_to_string(datetime_field_to_datetime(volunteer_relation.projected_end_date), DateTimeFormats.DATE_LOCALIZED) volunteer_name = volunteer_relation.volunteer.full_name() context = { 'volunteer_name': volunteer_name, 'project_name': project_name, 'projected_end_date': projected_end_date, 'comments': comments } email_msg = EmailMessage( subject=volunteer_name + " has renewed their volunteer commitment with " + project_name, from_email=_get_account_from_email(settings.EMAIL_VOLUNTEER_ACCT), to=_get_co_owner_emails(volunteer_relation.project) ) email_msg = email_template.render(email_msg, context) send_email(email_msg, settings.EMAIL_VOLUNTEER_ACCT)