Exemplo n.º 1
0
def clone_project(modeladmin,request,queryset):
    for project in queryset:
        data = copy.deepcopy(project.__dict__)
        del data['id']
        del data['_state']
        del data['_owner_cache']
        del data['_project_type_cache']
        data['name'] = data['name'].strip() + ' (Copy)'
        clone = Project(**data)
        clone.save()
        clone.admins = project.admins.all()
        clone.members = project.members.all()
        clone.save()
        messages.info(request, "Cloned project %s to %s"%(project.name,clone.name))
Exemplo n.º 2
0
def create_startup_for_user(modeladmin,request,queryset):
    for user in queryset:
        owned_startups=[x for x in user.owned_projects.all() if x.project_type.slug=="S"]
        if not owned_startups:
            name="S%s"%get_next_proj_id("S")
            startup=Project(name=name,title="Startup alloction for %s %s"%(user.first_name,user.last_name),
                owner=user,awarded=50000,current_balance=0,balance_used=0,type=ProjectType.objects.get(slug="S") )
            startup.save()
            startup.admins.add(user)
            startup.managers.add(user)
            startup.members.add(user)
            startup.save()
            u=reverse("admin:porkbelly_project_change", args=(startup.id,) )
            messages.info(request, "Created startup %s (<a href='%s'>%s</a>) for %s" % ( name, u,u, user.username) )
            qs=Project.objects.filter(pk=startup.id)
            create_bankaccount_for_award(modeladmin,request,qs)
            assign_default_project(modeladmin,request,[user])
Exemplo n.º 3
0
def approve_request(modeladmin,request,queryset,pt):
    
    for ar in queryset:

        #Make sure the request has not already been approved
        if ar.project:
            messages.error(request, "Request previously approved: %s" % project.name)
            continue

        #If time_awarded is 0, default to awarding request in full
        if ar.time_awarded == 0:
            n_award = ar.time_requested
        else:
            n_award = ar.time_awarded

        pname="%s%s"%(pt.slug,get_next_proj_id(pt.slug))

        new_project = Project(name=pname, title=ar.title, project_type=pt,
                    owner=ar.primary_investigator, initial_award=n_award,
                    credit=0,used=0)
        new_project.save()

        messages.info(request,"Created project %s"%pname)
        new_project.admins.add(ar.primary_investigator)
        new_project.members.add(ar.primary_investigator)
        for m in ar.collaborators.all():
            new_project.members.add(m)
        new_project.save()

        ar.project=new_project
        ar.approval_status='a'
        ar.approved_on=datetime.datetime.now()
        ar.approval_modifier=ProjectUser.objects.get(username=request.user.username)
        ar.save()

        create_bankaccount_for_award(modeladmin,request,[new_project])
        assign_default_project(modeladmin,request,new_project.members.all())
        allocation_request_approved.send(sender=ar,allocation_request=ar,project=new_project)