def update_harvest_projects(request): """ Update all projects from harvest. sequence 2/3 """ response = [] h = Harvest( settings.HARVEST_ADDRESS, settings.HARVEST_USER, settings.HARVEST_PASS ) for hproject in h.projects(): existing = False try: p = Project.objects.get(harvest_id=hproject.id) response.append({'harvest_id':hproject.id,'name':p.name,'status':'skipped'}) existing = True except: p = Project(harvest_id=hproject.id,name=hproject.name, notes=hproject.notes, client=Client.objects.get(harvest_id=hproject.client_id)) response.append({'harvest_id':hproject.id,'name':hproject.name,'status':'added'}) p.save() if not existing: # get task assignments per project for assignment in hproject.task_assignments: try: t = TaskType.objects.get(harvest_id=assignment.task_id) except: t = TaskType(harvest_id=assignment.task_id) t.save() t.projects.add(p) response.append({"tasktype":assignment.task_id, "created":True}) #time.sleep(5) return HttpResponse(simplejson.dumps(response,indent=2, ensure_ascii=False),mimetype='application/json')
gd_client.source = 'opengeo-solutions_dashboard-1' gd_client.ProgrammaticLogin() #gd_client.debug = True key = '0AgQ7XY0Atfx5dERpQ2VDcEtGUVpOQVRvVng4Tm1DMGc' worksheet = 'od6' def update_project(row, name, client, total, billable, non_billable): CellsUpdateAction(gd_client, key, worksheet, row, 1, name) CellsUpdateAction(gd_client, key, worksheet, row, 2, client) CellsUpdateAction(gd_client, key, worksheet, row, 3, str(total)) CellsUpdateAction(gd_client, key, worksheet, row, 4, str(billable)) CellsUpdateAction(gd_client, key, worksheet, row, 5, str(non_billable)) project_count = 1 for project in h.projects(): total = 0 tasks = {} billable = 0 non_billable = 0 for assignment in project.task_assignments: task_dict = {} name = assignment.task.name task_dict['name'] = name task_dict['billable'] = assignment.billable task_dict['hours'] = 0 task_dict['budget'] = assignment.budget tasks[name] = task_dict for entry in project.entries(start, end): task = tasks[entry.task.name] total += entry.hours