Exemple #1
0
def index(request):
    profile = request.user.get_profile()

    if request.method == 'POST':
        f = ProjectForm(request.POST)
        if f.is_valid():
            new_project = f.save(commit=False)
            new_project.wiki = '/project/wiki/' + new_project.unix_name

            user = User.objects.get(username__exact=request.user.username)
            new_project.owner = user

            new_project.save()
            user.project_set.add(new_project)
            f.save_m2m()

            profile = user.get_profile()
            profile.projects.add(new_project)
            profile.save()

            return HttpResponseRedirect('/dashboard/')
    else:
        f = ProjectForm()

    template = loader.get_template('project/create.html')
    context = Context({'id': request.user, 'profile': profile, 'form': f})

    return HttpResponse(template.render(context))
Exemple #2
0
def index(request):
    profile = request.user.get_profile()

    if request.method == 'POST':
        f = ProjectForm(request.POST)
        if f.is_valid():
            new_project = f.save(commit=False)
            new_project.wiki = '/project/wiki/' + new_project.unix_name

            user = User.objects.get(username__exact = request.user.username)
            new_project.owner = user

            new_project.save()
            user.project_set.add(new_project)
            f.save_m2m()

            profile = user.get_profile()
            profile.projects.add(new_project)
            profile.save()

            return HttpResponseRedirect('/dashboard/')
    else:
        f = ProjectForm()

    template = loader.get_template('project/create.html')
    context = Context( {'id': request.user, 'profile': profile, 'form': f } )

    return HttpResponse(template.render(context))
Exemple #3
0
def create_project(request):
    if request.method == 'POST':
        form = ProjectForm(request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect('/projects/')
    else:
        form = ProjectForm()

    return render_to_response('create_project.html', {'form': form},
                              context_instance=RequestContext(request))
Exemple #4
0
def new_project(request):

    # Show the sign page and collect emails
    context = {}
    context["causes"] = CAUSES

    allow_sponsorship = True

    if request.GET.get("org"):
        org = Organization.objects.get(id=request.GET.get("org"))

    elif request.user and request.user.get_profile().organization:
        org = request.user.get_profile().organization

    else:
        context["alert"] = {"type": "danger", "message": "Could not find a valid organization"}
        return render(request, "new_project.html", context)

    if request.method == "POST":

        context["organization"] = org

        project_form = ProjectForm(request.POST)
        project = project_form.save(commit=False)

        if project_form.is_valid():

            project.organization = org
            project.created_by = request.user

            project.save()

            project.sites = [settings.SITE_ID]
            project.save()

            if allow_sponsorship:

                project.create_sponsorship()

            # this has to occur after initial save b/c we use pk id as part of the s3 filepath
            media_file = request.FILES.get("file")
            if media_file:
                project.media_url = base.send_to_remote_storage(
                    media_file, project.make_s3_media_url(media_file), "image/png"
                )
                project.save()

            # send admin email with link adminpanel to change project status
            created_by = project.created_by.first_name + " " + project.created_by.last_name
            subj = "[%s] A new project submission" % request.get_host()
            body = """
                A new project has been submitted by %s:<br /><br />
                <b>%s</b><br /><br />
                %s<br /><br />
                <a href='%s'>View this project</a><br />
                """ % (
                created_by,
                project.name,
                project.short_desc,
                project.get_url(request),
            )

            base.send_admin_email(subj, body, html_content=body)

            return HttpResponseRedirect("/project/%s/opportunity/add" % project.id)

        else:

            context["alert"] = {"type": "danger", "message": "The form is invalid"}
            return render(request, "new_project.html", context)

    else:

        return render(request, "new_project.html", context)
Exemple #5
0
def manage_project(request, pid=1):

    project = get_object_or_404(Project, pk=pid)

    if (not request.user.is_authenticated() or project.created_by != request.user) and not request.user.is_staff:
        return HttpResponseRedirect("/")

    opps = Opportunity.objects.filter(project=project)

    context = {}
    context["no_sponsorship"] = False if opps.filter(sponsorship=True) else True
    context["COUNTRIES"] = COUNTRIES

    engagements = OpportunityEngagement.objects.filter(project_id=pid)
    context.update(
        {
            "project": project,
            "opportunities": opps,
            "engagements": engagements,
            "updates": Update.objects.filter(project=project).order_by("-date_created"),
        }
    )

    for u in context["updates"]:

        (u.video, u.text) = base.embed_video(u.text)

    if request.user.is_authenticated():
        context["is_following"] = request.user in project.followed_by.all()

    if request.method == "POST":

        if request.POST.get("type", "") == "opportunity":

            opportunity = get_object_or_404(Opportunity, pk=request.POST["id"])
            opportunity_form = OpportunityForm(request.POST or None, instance=opportunity)
            opportunity = opportunity_form.save(commit=False)

            media_file = request.FILES.get("file")
            if media_file:
                opportunity.media_url = base.send_to_remote_storage(
                    media_file, opportunity.make_s3_media_url(media_file), "image/png"
                )

            if opportunity_form.is_valid():
                opportunity.save()
            else:
                context["error"] = "failed to update opportunity"

        else:

            project_form = ProjectForm(request.POST or None, instance=project)
            original_media_url = project.media_url
            project = project_form.save(commit=False)

            media_file = request.FILES.get("file")

            if media_file:
                project.media_url = base.send_to_remote_storage(
                    media_file, project.make_s3_media_url(media_file), "image/png"
                )
            else:
                project.media_url = original_media_url

            if project_form.is_valid():

                project.save()

            else:

                context["error"] = "failed to update project"

    return render(request, "manage_project.html", context)