def new_organization(request): context = {} user_profile = request.user.get_profile() context["COUNTRIES"] = COUNTRIES if user_profile.organization_id: org = Organization.objects.get(id=user_profile.organization_id) context["organization"] = org if request.method == "POST": if not request.POST.get("id"): org_form = OrganizationForm(request.POST) org = org_form.save(commit=False) if org_form.is_valid(): org.created_by = request.user org.save() user_profile.organization_id = org.id user_profile.save() org_url = org.URL if re.match(r"^http://", org.URL) else "http://" + org.URL # send admin email with link adminpanel to change project status subj = "[%s] New organization: %s" % (request.get_host(), org.name) body = "A new organization was added by %s:<br /><br /><b>%s</b><br /><br />" % ( org.created_by, org.name, ) if org.URL: body = body + "<a href='%s'>%s</a><br /><br />" % (org_url, org.URL) body = body + 'Country: %s<br /><br />Mission Statement:<br /><br />"%s"<br /><br />' % ( org.country, org.org_mission, ) base.send_admin_email(subj, body, html_content=body) else: return HttpResponse("error") org_id = request.POST["id"] if request.POST.get("id") else org.id next = "/project/new?org=%s" % org_id return HttpResponseRedirect(next) return render(request, "new_organization.html", context)
def engage_opportunity(request): context = {} pid = request.REQUEST.get('projectId') oid = request.REQUEST.get('opportunityId') response = {} if pid and oid: opp = get_object_or_404(Opportunity, pk=oid) message = request.REQUEST.get('message') link = request.REQUEST.get('link') if link: message += '<br /></br />%s' % link if OpportunityEngagement.objects.filter(user=request.user, opportunity=opp, project_id=pid): response['message'] = "You are already engaged with this opportunity." else: opp_eng = OpportunityEngagement(user=request.user, opportunity=opp, project_id=pid) opp_eng.response = response opp_eng.save() subject = "New engagement with %s by %s" % (opp.name, request.user.email) html_content = ""%s"<br/><br/>%s" % (message, opp.project.name) html_content = html_content + " / <a href='http://%s/project/%s/opportunity/%s'>%s</a><br /><br />" % (request.get_host(), opp.project.id, opp.id, opp.name) html_content = html_content + "<a href='http://%s/admin/website/opportunityengagement/%s'>approve</a>""" % (request.get_host(), opp_eng.id) base.send_email(opp.project.created_by.email, subject, html_content, html_content=html_content) base.send_admin_email(subject, html_content, html_content=html_content) response['message'] = "Thanks for your request. A project lead will get back to you as soon as possible." else: response['message'] = "No project or opportunity id." return HttpResponse(json.dumps(response), mimetype="application/json")
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)
def sign_up(request): context = {} context["referrer"] = request.META.get("HTTP_REFERER", "/") if re.search(r"\/get-started", context["referrer"]): context["next"] = "/organization/new" else: context["next"] = context["referrer"] if settings.INVITE_ONLY: if request.GET.get("invite") or request.COOKIES.get("invite"): response = render(request, "sign_up.html", context) if request.GET.get("invite"): response.set_cookie("invite", request.GET["invite"], max_age=2) return response else: return render(request, "request_invite.html", context) elif not request.POST: return render(request, "sign_up.html", context) response = HttpResponseRedirect(request.POST.get("next", "/")) if request.POST.get("request-invite"): email = request.POST.get("email") name = request.POST.get("name") subject = "%s" % email content = "A new account invite request has been submitted:\n\n\t- %s\n\t- %s" % (name, email) if request.POST.get("blurb"): content += "\n\n%s" % request.POST.get("blurb") if request.POST.get("contribute"): content += "\n\nI would like to contribute my skills, knowledge and/or resources." if request.POST.get("project"): content += "\n\nI have a project I would like to submit." base.send_email("*****@*****.**", subject, content) alert = { "type": "modal", "message": "Thank you for your interest in Reallocate. Your invite request has been received.", } response.set_cookie("alert", json.dumps(alert), max_age=2) else: email = request.POST.get("email") password = request.POST.get("password") # Create a new user and persist it to the database. user = User.objects.create_user(username=email, email=email, password=password) user.save() user = authenticate(username=email, password=password) login(request, user) email_context = {"email": email, "user": user} base.send_email_template(request, "welcome", email_context, "Welcome to ReAllocate!", [email]) subject = "[%s] %s %s has joined ReAllocate" % (request.get_host(), user.first_name, user.last_name) html_content = "Username: %s <br /><br />Name: %s %s<br /><br />Email: %s <br /><br />" % ( user.username, user.first_name, user.last_name, user.email, ) base.send_admin_email(subject, html_content, html_content=html_content) return response