コード例 #1
0
ファイル: views.py プロジェクト: reallocate/reallocate
def view_project(request, pid=1):

    project = get_object_or_404(Project, pk=pid)
    opps = Opportunity.objects.filter(project=project).order_by("-sponsorship")
    engagement = OpportunityEngagement.objects.filter(project=project).filter(user__id__gt=1).distinct()
    context = {}

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

    if project.video_url:
        (project.video, foo) = base.embed_video(project.video_url)

    for u in context["updates"]:

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

    if request.user.is_authenticated():
        context["is_following"] = request.user in project.followed_by.all()
        context["is_owner"] = True if request.user == project.created_by else False
        context["is_admin"] = True if request.user.username == "admin" else False

    context["is_pending"] = True if project.status == "Pending" else False

    # temp var for testing stripe payments
    context["is_live"] = True if re.match(r"^beta", request.get_host()) else False

    return render(request, "project.html", context)
コード例 #2
0
ファイル: views.py プロジェクト: reallocate/reallocate
def view_opportunity(request, pid, oid):

    opp = get_object_or_404(Opportunity, pk=oid)
    updates = Update.objects.filter(opportunity=opp).order_by("-date_created")[0:10]
    context = {}

    context.update(
        {
            "opportunity": opp,
            "project": opp.project,
            "resources": opp.resources.split(","),
            "other_opps": [rec for rec in Opportunity.objects.filter(project=opp.project).all() if rec.id != opp.id],
            "updates": updates,
            "is_engaged": False,
            "is_open": True if opp.status != STATUS_CLOSED else False,
        }
    )

    for u in context["updates"]:

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

    if request.user.is_authenticated():

        context["is_following"] = request.user in opp.project.followed_by.all()
        context["is_owner"] = True if request.user == opp.project.created_by else False

        try:
            ue = OpportunityEngagement.objects.get(opportunity=opp.id, user=request.user.id)
        except ObjectDoesNotExist:
            ue = None

        if ue:
            if ue.status == "Unpublished" or ue.status == "Pending":
                context["pending"] = True
            if ue.status == STATUS_ACTIVE:
                context["engaged"] = True

    return render(request, "opportunity.html", context)
コード例 #3
0
ファイル: views.py プロジェクト: reallocate/reallocate
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)