def invite(project_id, username): project = Project.query.get_or_404(project_id) form = InviteForm() if form.validate_on_submit(): user_email = form.email.data user = User.query.filter_by(email=user_email).first_or_404() subss = db.session.query(subs).filter_by(project_id=project_id, user_id=user.id).all() if len(subss) == 0: project.users_in.append(user) db.session.commit() flash(user_email + ' has successfully been added.', 'success') socketio.emit('listInvitedUser', { 'project_id': project_id, 'username': username, 'new_member_username': user.username, 'new_member_photo': user.image_file }, broadcast=True) else: flash(user_email + ' is already in this project', 'success') return redirect( url_for('project', project_id=project.id, username=current_user.username)) return render_template('invite.html', title='Invite a Member', form=form, legend='Invite a Member')
def invite(): form = InviteForm() if form.validate_on_submit(): user = User.query.filter_by(username=form.username.data).first() if user is None: flash('User does not exist') return redirect(url_for('invite')) flash('User will be notified of invite') return redirect(url_for('index')) return render_template('invite.html', form=form)
def index(): form = InviteForm() if form.validate_on_submit(): # reused from Company detection, git grep designation to find it designation = current_user.email.split("@")[1].split(".")[-2].upper() to_email = form.email.data.lower() if designation in to_email.upper() or current_user.is_super: to_name = form.firstname.data.capitalize() message = " ".join(form.message.data.split()) # flat 1 liner send_invite_email(current_user, to_name, to_email, message) flash('Email invitation sent to ' + to_name, category='success') else: flash( 'Sorry, you may send email invites Only Inside Your Company!', category='warning') return render_template('index.html', title=Company.query.get( current_user.company_id).name, form=form, refresh=app.config['PAGE_REFRESH'])
def invite(): """ Invite another human to join the site. """ form = InviteForm() if request.method == "POST": if form.validate(): site_url = "https://%s" % current_app.config["NOI_DEPLOY"] sender = current_app.config["MAIL_USERNAME"] mail.send_message( subject=gettext("%(user)s would like you to join the network!", user=current_user.full_name), body=gettext("Just visit %(url)s.", url=site_url), sender=sender, recipients=[form.email.data], ) flash(gettext("Invitation sent!")) return redirect(url_for("views.invite")) else: flash(gettext("Your form submission was invalid."), "error") return render_template("invite.html", form=form)
def invite(): ''' Invite another human to join the site. ''' form = InviteForm() if request.method == 'POST': if form.validate(): site_url = 'https://%s' % current_app.config['NOI_DEPLOY'] sender = current_app.config['MAIL_USERNAME'] mail.send_message( subject=gettext( "%(user)s would like you to join the Network of " "Innovators!", user=current_user.full_name, ), body=gettext( "%(user)s has invited you to join the " "Network of Innovators -- a new skill-sharing network " "for government and civic innovators worldwide.\n\n" "Join today. It's FREE. And in just a few minutes, " "you can get matched with innovators from around the " "world.\n\n" "Build your network now at %(url)s.", user=current_user.full_name, url=site_url, ), sender=sender, recipients=[form.email.data] ) flash(gettext("Invitation sent!")) return redirect(url_for('views.invite')) else: flash(gettext("Your form submission was invalid."), "error") return render_template('invite.html', form=form)
def invite(): ''' Invite another human to join the site. ''' form = InviteForm() if request.method == 'POST': if form.validate(): site_url = 'https://%s' % current_app.config['NOI_DEPLOY'] sender = current_app.config['MAIL_USERNAME'] mail.send_message( subject=gettext( "%(user)s would like you to join the Network of " "Innovators!", user=current_user.full_name, ), body=gettext( "%(user)s has invited you to join the " "Network of Innovators -- a new skill-sharing network " "for government and civic innovators worldwide.\n\n" "Join today. It's FREE. And in just a few minutes, " "you can get matched with innovators from around the " "world.\n\n" "Build your network now at %(url)s.", user=current_user.full_name, url=site_url, ), sender=sender, recipients=[form.email.data] ) flash(gettext("Invitation sent!")) return redirect(url_for('views.invite')) else: flash(gettext("Your form submission was invalid."), "error") return render_template('invite.html', form=form)
def view_slate(request, slate_id): slate = Slate.objects.get(id=slate_id) invites = Invitee.objects.filter(slate = slate_id) try: slate.users.get(id = request.user.id) except User.DoesNotExist: return redirect("slate") if request.method == 'POST': if 'submit_idea' in request.POST: idea = helpers.add_idea(request, slate_id=slate.id) if 'submit_idea_elaborate' in request.POST: idea = helpers.add_idea(request, slate_id=slate.id) if idea: return HttpResponseRedirect(reverse('edit-idea', args=[idea.id])) if 'invite' in request.POST: inviteForm = InviteForm(request.POST) if inviteForm.is_valid(): clean = inviteForm.cleaned_data invites = clean['invite_list'].split(',') participants = slate.users.count() if len(invites) > (6 - participants): messages.error(request, "You can\'t have"+ "more than 6 people on a slate." ) return redirect("view-slate", slate_id = slate.id) for invite in clean['invite_list'].split(','): invite = invite.strip() try: validate_email( invite ) except ValidationError: #not an email address, continue with next invite continue else: # user doesn't exist # create an invitee item try: invite = Invitee.objects.get(email = invite, slate = slate.id) except Invitee.DoesNotExist: pass else: #invite already exists, let's pass continue invite = Invitee.objects.create( email=invite,slate=slate) invite.save() link_url = request.build_absolute_uri( "/invite/slate/%i/%i/%s/"%(slate.id,invite.id,slugify(slate.name)) ) subject = ( "%s invited you to a slate on " "IdeaOtter" ) %( request.user.username ) from_email = "Idea Otter <*****@*****.**>" plaintext = get_template('email/slate_invite.txt') htmly = get_template('email/slate_invite.html') d = Context( { 'username': request.user.email, 'url': link_url, 'email': invite.email } ) text_content = plaintext.render(d) html_content = htmly.render(d) msg = EmailMultiAlternatives(subject, text_content, from_email, [invite.email]) msg.attach_alternative(html_content, "text/html") try: print "sending email" msg.send() except: print html_content pass ideaForm = IdeaForm() inviteForm = InviteForm() voteUpForm = VoteForm({'vote':'+'}) ideas = ideaForm participants = slate.users.all() slate_ideas = slate.ideas.all() slate_ideas = slate_ideas.order_by('-date') return render_to_response("main/view_slate.html", locals(), context_instance = RequestContext(request))