def proposal_messages(proposal_id): if current_user.is_anonymous(): return redirect(url_for("users.login", next=url_for(".proposal_messages", proposal_id=proposal_id))) proposal = Proposal.query.get_or_404(proposal_id) if proposal.user_id != current_user.id: abort(404) form = MessagesForm() if request.method == "POST": if form.send.data and form.message.data: msg = CFPMessage() msg.is_to_admin = True msg.from_user_id = current_user.id msg.proposal_id = proposal_id msg.message = form.message.data db.session.add(msg) db.session.commit() if form.mark_read or form.send.data: count = proposal.mark_messages_read(current_user) app.logger.info("Marked %s messages to admin on proposal %s as read" % (count, proposal.id)) return redirect(url_for(".proposal_messages", proposal_id=proposal_id)) messages = CFPMessage.query.filter_by(proposal_id=proposal_id).order_by("created").all() return render_template("cfp/messages.html", proposal=proposal, messages=messages, form=form)
def proposal_messages(proposal_id): if current_user.is_anonymous: return redirect(url_for('users.login', next=url_for('.proposal_messages', proposal_id=proposal_id))) proposal = Proposal.query.get_or_404(proposal_id) if proposal.user_id != current_user.id: abort(404) form = MessagesForm() if form.validate_on_submit(): if form.send.data: msg = CFPMessage() msg.is_to_admin = True msg.from_user_id = current_user.id msg.proposal_id = proposal_id msg.message = form.message.data db.session.add(msg) db.session.commit() count = proposal.mark_messages_read(current_user) db.session.commit() app.logger.info('Marked %s messages to admin on proposal %s as read' % (count, proposal.id)) return redirect(url_for('.proposal_messages', proposal_id=proposal_id)) messages = CFPMessage.query.filter_by( proposal_id=proposal_id ).order_by('created').all() return render_template('cfp/messages.html', proposal=proposal, messages=messages, form=form)
def message_batch(): proposals, filtered = filter_proposal_request() form = SendMessageForm() if form.validate_on_submit(): if form.send.data: for proposal in proposals: msg = CFPMessage() msg.is_to_admin = False msg.from_user_id = current_user.id msg.proposal_id = proposal.id msg.message = form.message.data db.session.add(msg) db.session.commit() app.logger.info('Sending message from %s to %s', current_user.id, proposal.user_id) msg_url = external_url('cfp.proposal_messages', proposal_id=proposal.id) msg = Message('New message about your EMF proposal', sender=app.config['CONTENT_EMAIL'], recipients=[proposal.user.email]) msg.body = render_template('cfp_review/email/new_message.txt', url=msg_url, to_user=proposal.user, from_user=current_user, proposal=proposal) mail.send(msg) flash('Messaged %s proposals' % len(proposals), 'info') return redirect(url_for('.proposals', **request.args)) return render_template('cfp_review/message_batch.html', form=form, proposals=proposals)
def proposal_messages(proposal_id): if current_user.is_anonymous: return redirect( url_for( "users.login", next=url_for(".proposal_messages", proposal_id=proposal_id), )) proposal = Proposal.query.get_or_404(proposal_id) if proposal.user_id != current_user.id: abort(404) form = MessagesForm() if form.validate_on_submit(): if form.send.data: msg = CFPMessage() msg.is_to_admin = True msg.from_user_id = current_user.id msg.proposal_id = proposal_id msg.message = form.message.data db.session.add(msg) db.session.commit() if channel := app.config.get("CONTENT_IRC_CHANNEL"): # WARNING: don't send personal information via this (the channel is public) irc_send( f"{channel} New CfP message for {proposal.human_type}: {external_url('cfp_review.message_proposer', proposal_id=proposal_id)}" ) count = proposal.mark_messages_read(current_user) db.session.commit() app.logger.info("Marked %s messages to admin on proposal %s as read" % (count, proposal.id)) return redirect(url_for(".proposal_messages", proposal_id=proposal_id))
def withdraw_proposal(proposal_id): if current_user.is_anonymous: return redirect( url_for("users.login", next=url_for(".edit_proposal", proposal_id=proposal_id))) proposal = Proposal.query.get_or_404(proposal_id) if proposal.user != current_user: abort(404) form = WithdrawalForm() if form.validate_on_submit(): if form.confirm_withdrawal.data: app.logger.info("Proposal %s is being withdrawn.", proposal_id) proposal.set_state("withdrawn") msg = CFPMessage() msg.is_to_admin = True msg.from_user_id = current_user.id msg.proposal_id = proposal_id msg.message = form.message.data db.session.add(msg) db.session.commit() flash("We've withdrawn your {0.type}, {0.title}.".format(proposal)) return redirect(url_for("cfp.proposals")) return render_template("cfp/withdraw.html", form=form, proposal=proposal)
def message_proposer(proposal_id): form = SendMessageForm() proposal = Proposal.query.get_or_404(proposal_id) if form.validate_on_submit(): if form.send.data: msg = CFPMessage() msg.is_to_admin = False msg.from_user_id = current_user.id msg.proposal_id = proposal_id msg.message = form.message.data db.session.add(msg) db.session.commit() app.logger.info( "Sending message from %s to %s", current_user.id, proposal.user_id ) msg_url = external_url("cfp.proposal_messages", proposal_id=proposal_id) msg = EmailMessage( "New message about your EMF proposal", from_email=from_email("CONTENT_EMAIL"), to=[proposal.user.email], ) msg.body = render_template( "cfp_review/email/new_message.txt", url=msg_url, to_user=proposal.user, from_user=current_user, proposal=proposal, ) msg.send() count = proposal.mark_messages_read(current_user) db.session.commit() app.logger.info( "Marked %s messages to admin on proposal %s as read" % (count, proposal.id) ) return redirect(url_for(".message_proposer", proposal_id=proposal_id)) # Admin can see all messages sent in relation to a proposal messages = ( CFPMessage.query.filter_by(proposal_id=proposal_id).order_by("created").all() ) return render_template( "cfp_review/message_proposer.html", form=form, messages=messages, proposal=proposal, )
def message_proposer(proposal_id): form = SendMessageForm() proposal = Proposal.query.get_or_404(proposal_id) if request.method == 'POST': if form.send.data and form.message.data: msg = CFPMessage() msg.is_to_admin = False msg.from_user_id = current_user.id msg.proposal_id = proposal_id msg.message = form.message.data db.session.add(msg) db.session.commit() app.logger.info('Sending message from %s to %s', current_user.id, proposal.user_id) msg_url = external_url('cfp.proposal_messages', proposal_id=proposal_id) msg = Message('New message about your EMF proposal', sender=app.config['CONTENT_EMAIL'], recipients=[proposal.user.email]) msg.body = render_template('cfp_review/email/new_message.txt', url=msg_url, to_user=proposal.user, from_user=current_user, proposal=proposal) mail.send(msg) if form.mark_read.data or form.send.data: count = proposal.mark_messages_read(current_user) app.logger.info( 'Marked %s messages to admin on proposal %s as read' % (count, proposal.id)) return redirect(url_for('.message_proposer', proposal_id=proposal_id)) # Admin can see all messages sent in relation to a proposal messages = CFPMessage.query.filter_by( proposal_id=proposal_id).order_by('created').all() return render_template('cfp_review/message_proposer.html', form=form, messages=messages, proposal=proposal)
def message_batch(): proposals, filtered = filter_proposal_request() form = SendMessageForm() if form.validate_on_submit(): if form.send.data: for proposal in proposals: msg = CFPMessage() msg.is_to_admin = False msg.from_user_id = current_user.id msg.proposal_id = proposal.id msg.message = form.message.data db.session.add(msg) db.session.commit() app.logger.info( "Sending message from %s to %s", current_user.id, proposal.user_id ) msg_url = external_url("cfp.proposal_messages", proposal_id=proposal.id) msg = EmailMessage( "New message about your EMF proposal", from_email=from_email("CONTENT_EMAIL"), to=[proposal.user.email], ) msg.body = render_template( "cfp_review/email/new_message.txt", url=msg_url, to_user=proposal.user, from_user=current_user, proposal=proposal, ) msg.send() flash("Messaged %s proposals" % len(proposals), "info") return redirect(url_for(".proposals", **request.args)) return render_template( "cfp_review/message_batch.html", form=form, proposals=proposals )
def message_proposer(proposal_id): form = SendMessageForm() proposal = Proposal.query.get_or_404(proposal_id) if form.validate_on_submit(): if form.send.data: msg = CFPMessage() msg.is_to_admin = False msg.from_user_id = current_user.id msg.proposal_id = proposal_id msg.message = form.message.data db.session.add(msg) db.session.commit() app.logger.info('Sending message from %s to %s', current_user.id, proposal.user_id) msg_url = external_url('cfp.proposal_messages', proposal_id=proposal_id) msg = Message('New message about your EMF proposal', sender=app.config['CONTENT_EMAIL'], recipients=[proposal.user.email]) msg.body = render_template('cfp_review/email/new_message.txt', url=msg_url, to_user=proposal.user, from_user=current_user, proposal=proposal) mail.send(msg) count = proposal.mark_messages_read(current_user) db.session.commit() app.logger.info('Marked %s messages to admin on proposal %s as read' % (count, proposal.id)) return redirect(url_for('.message_proposer', proposal_id=proposal_id)) # Admin can see all messages sent in relation to a proposal messages = CFPMessage.query.filter_by( proposal_id=proposal_id ).order_by('created').all() return render_template('cfp_review/message_proposer.html', form=form, messages=messages, proposal=proposal)
def message_proposer(proposal_id): form = SendMessageForm() proposal = Proposal.query.get_or_404(proposal_id) if request.method == "POST": if form.send.data and form.message.data: msg = CFPMessage() msg.is_to_admin = False msg.from_user_id = current_user.id msg.proposal_id = proposal_id msg.message = form.message.data db.session.add(msg) db.session.commit() app.logger.info("Sending message from %s to %s", current_user.id, proposal.user_id) msg_url = external_url("cfp.proposal_messages", proposal_id=proposal_id) send_template_email( "New message about your EMF proposal", proposal.user.email, app.config["CONTENT_EMAIL"], "cfp_review/email/new_message.txt", url=msg_url, to_user=proposal.user, from_user=current_user, proposal=proposal, ) if form.mark_read.data or form.send.data: count = proposal.mark_messages_read(current_user) app.logger.info("Marked %s messages to admin on proposal %s as read" % (count, proposal.id)) return redirect(url_for(".message_proposer", proposal_id=proposal_id)) # Admin can see all messages sent in relation to a proposal messages = CFPMessage.query.filter_by(proposal_id=proposal_id).order_by("created").all() return render_template("cfp_review/message_proposer.html", form=form, messages=messages, proposal=proposal)