def init_database_models(self): db_conf = config.app_cfg['postgresql_teamleader'] table_names = config.app_cfg['table_names'] self.companies = Companies(db_conf, table_names) self.contacts = Contacts(db_conf, table_names) self.departments = Departments(db_conf, table_names) self.events = Events(db_conf, table_names) self.invoices = Invoices(db_conf, table_names) self.projects = Projects(db_conf, table_names) self.users = Users(db_conf, table_names)
def home(): """Render home page.""" counts = { 'projects': Projects().select('owner=%(user_id)s', { 'user_id': g.user.id }).rowcount, 'contributions': Revisions().select('contributor_id=%(user_id)s', { 'user_id': g.user.id }).rowcount } top_projects = Projects().get_top_projects(g.user.id) return render_template('home.html', counts=counts, top_projects=top_projects)
def project(project_id): """Page with the list of all projects.""" project = Projects().get(id=project_id) revisions = Revisions().all_by_field('project_id', project_id) issues = Issues().all_by_field('project_id', project_id) return render_template('project.html', revisions=revisions, project=project, issues=issues)
def projects(): """Page with the list of all projects.""" proj = Projects() projects = proj.all_by_field('owner', g.user.id) proj.join('contributors', 'id=project_id', ['user_id', 'permissions']) contributions = proj.all_by_field('user_id', g.user.id) proj.clear_joins() return render_template('projects.html', projects=projects, contributions=contributions)
def revision(project_id, revision_id): """Page with the list of all projects.""" project = Projects().get(id=project_id) revision = Revisions().get(project_id=project_id, revision_id=revision_id) diff = revision.get('diff') lexer = get_lexer_by_name("diff", stripall=True) formatter = HtmlFormatter(style=get_style_by_name('colorful')) formatted_diff = highlight(diff, lexer, formatter) user = Users().get(id=revision.get('contributor_id')) return render_template( 'revision.html', revision=revision, project=project, user=user, diff=formatted_diff, diff_styles=HtmlFormatter().get_style_defs('.highlight'))
def create_project(): """Page to create a new project.""" status = '' if request.method == 'POST': name = request.form.get('name') desc = request.form.get('description', '') if name: try: Projects().create(name, desc) return redirect(url_for('routes.projects')) except Exception as e: status = 'Error: {}'.format(str(e)) else: status = 'Please specify the name of the project.' return render_template('projects-new.html', status=status)
def create_issue(project_id): """Page with the list of all projects.""" project = Projects().get(id=project_id) if request.method == 'POST': new_issue_id = db.execute( 'SELECT new_issue_id({}) AS id;'.format(project_id)).fetchone() form = { 'project_id': project_id, 'issue_id': new_issue_id.get('id'), 'name': request.form.get('name'), 'description': request.form.get('description') } Issues().add(form) return redirect(url_for('routes.project', project_id=project_id)) return render_template('issue-new.html', project=project)
def issue(project_id, issue_id): """Return the list of issues.""" project = Projects().get(id=project_id) issue = Issues().get(project_id=project_id, issue_id=issue_id) if request.method == 'POST': new_comment_id = db.execute( 'SELECT new_issue_comment_id({}, {}) AS id;'.format( project_id, issue_id)).fetchone() form = { 'project_id': project_id, 'issue_id': issue_id, 'comment_id': new_comment_id.get('id'), 'title': request.form.get('title'), 'comment': request.form.get('comment'), 'commenter': g.user.id } Issue_comments().add(form) if request.args.get('resolve'): Issues().update({'status': 'resolved'}, where='project_id={} AND issue_id={}'.format( project_id, issue_id)) return redirect( url_for('routes.issue', issue_id=issue_id, project_id=project_id)) if request.args.get('close'): Issues().update({'status': 'closed'}, where='project_id={} AND issue_id={}'.format( project_id, issue_id)) return redirect( url_for('routes.issue', issue_id=issue_id, project_id=project_id)) comments = Issue_comments().all( 'issue_id=%(issue_id)s AND project_id=%(project_id)s', { 'issue_id': issue_id, 'project_id': project_id }) for comment in comments: comment['user'] = Users().get(id=comment.get('commenter')) return render_template('issues.html', project=project, issue=issue, comments=comments)
def contributions(): """Page to list user's contributions.""" contributions = Revisions().all_by_field('contributor_id', g.user.id) for cont in contributions: cont['project'] = Projects().get(id=cont.get('project_id')) return render_template('contributions.html', contributions=contributions)
education = Education(user=me, school="Marymount Manhattan College", degree="Bachelor of Arts (B.A.)", major="International Studies", gpa=3.5, start_date=datetime.date(2007, 8, 1), end_date=datetime.date(2011, 5, 15)) projects = [ Projects( user=me, name="Apploi for Hiring Managers - (Android)", role="Lead Engineer", project_type="professional", description= """Ionic2 Hybrid App for Hiring Managers to quickly review candidates.""", release_date=datetime.date(2016, 6, 1), link= "https://play.google.com/store/apps/details?id=com.ionicframework.trumobe215950&hl=en" ), Projects( user=me, name="Apploi for Hiring Managers - (iOS)", role="Lead Engineer", project_type="professional", description= """Ionic2 Hybrid App for Hiring Managers to quickly review candidates.""", release_date=datetime.date(2016, 6, 1), link= "https://fnd.io/#/us/ios-universal-app/1132659182-apploi-for-hiring-managers-by-apploi-cor"
def projects(self, postgresql_wrapper_mock): config = ConfigParser() db_conf = config.app_cfg['postgresql_teamleader'] table_names = config.app_cfg['table_names'] self.projects = Projects(db_conf, table_names) return self.projects
class App: def __init__(self): self.init_teamleader_client() self.init_database_models() def init_teamleader_client(self): self.tlc = TeamleaderClient(config.app_cfg) def init_database_models(self): db_conf = config.app_cfg['postgresql_teamleader'] table_names = config.app_cfg['table_names'] self.companies = Companies(db_conf, table_names) self.contacts = Contacts(db_conf, table_names) self.departments = Departments(db_conf, table_names) self.events = Events(db_conf, table_names) self.invoices = Invoices(db_conf, table_names) self.projects = Projects(db_conf, table_names) self.users = Users(db_conf, table_names) def auth_callback(self, code, state): return self.tlc.authcode_callback(code, state) def resource_sync(self, list_call, details_call, model, full_sync=False): if full_sync: model.truncate_table() modified_since = model.max_last_modified_timestamp() if modified_since: logger.info( f"{model.name} delta since {modified_since.isoformat()} started.") else: logger.info(f"{model.name} full synchronization started.") page = 1 resp = [1] total_synced = 0 while len(resp) > 0: resp = list_call(page, 100, modified_since) if len(resp) > 0: detailed_list = [] for res in resp: print('.', end='', flush=True) detailed_list.append(details_call(res['id'])) model.upsert_results([(detailed_list, model.name)]) page += 1 total_synced += len(resp) print(f"\n{model.name} synced {len(resp)} records", flush=True) logger.info(f"Done, synchronized {total_synced} {model.name}") def companies_sync(self, full_sync=False): """ Syncs teamleader companies into target database Arguments: modified_since -- Filters teamleader results with updated_since If None, it will retrieve all teamleader companies. """ self.resource_sync(self.tlc.list_companies, self.tlc.get_company, self.companies, full_sync) def contacts_sync(self, full_sync=False): """ Syncs teamleader contacts into target database Arguments: modified_since -- Filters teamleader results with updated_since If None, it will retrieve all teamleader contacts. """ self.resource_sync(self.tlc.list_contacts, self.tlc.get_contact, self.contacts, full_sync) def departments_sync(self, full_sync=False): """ Syncs teamleader departments into target database Arguments: modified_since -- Filters teamleader results with updated_since If None, it will retrieve all teamleader departments. """ self.resource_sync(self.tlc.list_departments, self.tlc.get_department, self.departments, full_sync) def events_sync(self, full_sync=False): """ Syncs teamleader events into target database Arguments: modified_since -- Filters teamleader results with updated_since If None, it will retrieve all teamleader events. """ self.resource_sync(self.tlc.list_events, self.tlc.get_event, self.events, full_sync) def invoices_sync(self, full_sync=False): """ Syncs teamleader invoices into target database Arguments: modified_since -- Filters teamleader results with updated_since If None, it will retrieve all teamleader invoices. """ self.resource_sync(self.tlc.list_invoices, self.tlc.get_invoice, self.invoices, full_sync) def projects_sync(self, full_sync=False): """ Syncs teamleader projects into target database Arguments: modified_since -- Filters teamleader projects with updated_since If None, it will retrieve all teamleader projects. """ self.resource_sync(self.tlc.list_projects, self.tlc.get_project, self.projects, full_sync) def users_sync(self, full_sync=False): """ Syncs teamleader users into target database Arguments: modified_since -- Filters teamleader users with updated_since If None, it will retrieve all teamleader users. """ self.resource_sync(self.tlc.list_users, self.tlc.get_user, self.users, full_sync) def teamleader_sync(self, full_sync=False): if full_sync: logger.info("Start full sync from teamleader") else: logger.info("Start delta sync from teamleader") self.companies_sync(full_sync) self.contacts_sync(full_sync) self.departments_sync(full_sync) self.events_sync(full_sync) self.invoices_sync(full_sync) self.projects_sync(full_sync) self.users_sync(full_sync) logger.info("Teamleader sync completed") def teamleader_status(self): status = {} status['companies'] = self.companies.status() status['contacts'] = self.contacts.status() status['departments'] = self.departments.status() status['events'] = self.events.status() status['invoices'] = self.invoices.status() status['projects'] = self.projects.status() status['users'] = self.users.status() return status def csv_path(self): return "contacts_export.csv" def export_csv(self): self.contacts.export_csv(self.csv_path()) def main(self): try: argh.dispatch_commands([ self.companies_sync, self.departments_sync, self.events_sync, self.invoices_sync, self.projects_sync, self.users_sync, self.teamleader_sync, self.teamleader_status ]) except (PSQLError) as e: logger.error(e) raise e