def handle(self, *args, **options):
        base_url = getattr(settings, 'SC_URL', None)
        api_user = getattr(settings, 'SC_USER', None)
        api_pass = getattr(settings, 'SC_PASS', None)

        session = Sugarcrm(base_url, api_user, api_pass)
        modules = session.get_available_modules()
        print modules
        offset = 0
        result_count = 1
        while offset < 50:
            accounts = session.get_entry_list('Project', offset=offset)
            offset = accounts['next_offset']
            result_count = accounts['result_count']
            for json_data in accounts['entry_list']:
                name = json_data['name_value_list']['name']['value']
                date_entered = json_data['name_value_list']['date_entered']['value']
                sugar_id = json_data['id']
                print session.get_relationships(module='Project', module_id=sugar_id, link_field_name='accounts', related_fields=["id"])
                try:
                    project = Project.objects.get(name__icontains=name)
                    print "Match !!!", project.name
                    obj, created = ThirdParty.objects.get_or_create(
                        content_type=ContentType.objects.get(model='project'),
                        object_id=project.id,
                        service_item_label='sugarcrm_project_id',
                        service_item_value=sugar_id,
                    )
                except:
                    project = Project(
                        name=name,
                        owner_id=1,
                        start_dt=date_entered,
                        original_creator_id=1,
                        editor_id=1
                    )
                    project.save()
                    obj, created = ThirdParty.objects.get_or_create(
                        content_type=ContentType.objects.get(model='project'),
                        object_id=project.id,
                        service_item_label='sugarcrm_project_id',
                        service_item_value=sugar_id,
                    )
Exemple #2
0
def create_project(request):
    context = RequestContext(request)

    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            p = Project(
                name=form.cleaned_data['name'],
                requester=form.cleaned_data['requester'],
                project_manager=form.cleaned_data['project_manager'],
                program=form.cleaned_data['program'],
                description=form.cleaned_data['description'],
                start_date=form.cleaned_data['start_date'],
                due_date=form.cleaned_data['due_date'],
                date_complete=form.cleaned_data['date_complete'],
                sharepoint_ticket=form.cleaned_data['sharepoint_ticket'],
                priority=form.cleaned_data['priority'],
                status=form.cleaned_data['status'])
            p.save()

            for w in form.cleaned_data['workers']:
                w = Worker(
                    project=Project.objects.get(pk=p.id),
                    person=w,
                )
                w.save()

            return redirect('pm:index')
        else:
            # handle errors
            print form.cleaned_data
            pass
    else:
        form = ProjectForm(initial={'program': Program.objects.get(name="None")})

    return render_to_response("pm/project_new.html", {'form': form}, context)
Exemple #3
0
def project_create(request):
    for x in range(1, 55):
        project = Project()
        project.code = 'code' + str(x)
        project.name = 'name' + str(x)
        project.pm = 'pm' + str(x)

        project.save()

    return HttpResponse('true')
    def handle(self, *args, **options):
        total = 0
        ci = None
        try:
            content_import_pk = args[0]
        except:
            content_import_pk = None
        if content_import_pk:
            ci = get_object_or_404(ContentImport, pk=content_import_pk)
        data = Harvest().projects()
        if data:
            if ci:
                # divide by 3 because of Lost Time and Client Services projects
                cache.set(('content_import.total.%s') % ci.pk, round(len(data)/3))
                cache.set(('content_import.matched.%s') % ci.pk, 0)
                cache.set(('content_import.added.%s') % ci.pk, 0)
            print "Receiving data..."
            for d in data:
                p = d['project']
                if p['name'] != "Lost Time" and p['name'] != "Client Services":
                    try:
                        project_match = ThirdParty.objects.get(
                            service_item_value=p['id'],
                            service_item_label="harvest_project_id",
                            content_type=ContentType.objects.get(model='project')
                        )
                        match = Project.objects.get(id=project_match.object_id)
                        if ci:
                            cache.incr(('content_import.matched.%s') % ci.pk)
                        print "MATCH!!! ", match
                    except:
                        if p['notes']:
                            desc = p['notes']
                        else:
                            desc = ""

                        if "tendenci" in p['name'].lower() or "t5" in p['name'].lower():
                            tech = "Tendenci"
                        elif "word" in p['name'].lower() or "wp" in p['name'].lower():
                            tech = "Wordpress"
                        elif "drupal" in p['name'].lower():
                            tech = "Drupal"
                        else:
                            tech = "Other"

                        if "sem" in p['name'].lower() or "seo" in p['name'].lower() or "ppc" in p['name'].lower() or "creative" in p['name'].lower():
                            ongoing = True
                        else:
                            ongoing = False

                        owner = Profile.objects.filter(user__is_active=True, user__is_staff=True).order_by('?')[0].pk

                        if p['active']:
                            status = "In Progress"
                            end_dt = None
                        else:
                            status = "Done"
                            end_dt = p["updated_at"]

                        if p['cost_budget']:
                            budget = round(float(p['cost_budget']))/100
                        else:
                            budget = 100

                        try:
                            tp = ThirdParty.objects.get(
                                content_type=ContentType.objects.get(model='client'),
                                service_item_label='harvest_client_id',
                                service_item_value=p['client_id'],
                            )
                            client = Client.objects.get(id=tp.object_id)
                        except:
                            client = None

                        project = Project(
                            name=p['name'], 
                            description=desc,
                            technology=tech,
                            status=status,
                            ongoing=ongoing,
                            task_budget=budget,
                            owner_id=owner,
                            start_dt=p['created_at'],
                            end_dt=end_dt,
                            original_creator_id=1,
                            client=client,
                            editor_id=1)
                        project.save()
                        project.original = project
                        project.save()

                        obj, created = ThirdParty.objects.get_or_create(
                            content_type=ContentType.objects.get(model='project'),
                            object_id=project.id,
                            service_item_label='harvest_project_id',
                            service_item_value=p['id'],
                        )

                        obj, created = ThirdParty.objects.get_or_create(
                            content_type=ContentType.objects.get(model='project'),
                            object_id=project.id,
                            service_item_label='harvest_project_client_id',
                            service_item_value=p['client_id'],
                        )

                        if ci:
                            cache.incr(('content_import.added.%s') % ci.pk)
                        total += 1
            print "Done. Added %s of %s Projects" % (total, len(data))
        if ci:
            ci.complete_dt = timezone.now()
            cache.set(('content_import.complete_dt.%s') % ci.pk, ci.complete_dt)
            ci.matched = cache.get(('content_import.matched.%s') % ci.pk)
            ci.added = cache.get(('content_import.added.%s') % ci.pk)
            ci.estimated_total = cache.get(('content_import.total.%s') % ci.pk)
            ci.save()