From f5d17cfd5a9b5109d312aeadf73f9092974ef03d Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sat, 20 Apr 2013 00:17:48 +0530 Subject: [PATCH 1/5] middle of event wall --- alembic/env.py | 1 - hacknight/models/__init__.py | 3 ++- hacknight/models/comment.py | 6 ++---- hacknight/models/event.py | 33 ++++++++++++++------------------- hacknight/models/user.py | 2 +- hacknight/models/venue.py | 2 +- hacknight/models/vote.py | 6 +++--- 7 files changed, 23 insertions(+), 30 deletions(-) diff --git a/alembic/env.py b/alembic/env.py index bad6e54..36958d9 100644 --- a/alembic/env.py +++ b/alembic/env.py @@ -76,4 +76,3 @@ def run_migrations_online(): run_migrations_offline() else: run_migrations_online() - diff --git a/hacknight/models/__init__.py b/hacknight/models/__init__.py index daebcb6..f14a212 100644 --- a/hacknight/models/__init__.py +++ b/hacknight/models/__init__.py @@ -6,8 +6,9 @@ db = SQLAlchemy(app) -from hacknight.models.user import * from hacknight.models.event import * +from hacknight.models.user import * +from hacknight.models.profile import * from hacknight.models.venue import * from hacknight.models.project import * from hacknight.models.participant import * diff --git a/hacknight/models/comment.py b/hacknight/models/comment.py index fb0e744..748b41a 100644 --- a/hacknight/models/comment.py +++ b/hacknight/models/comment.py @@ -1,11 +1,9 @@ # -*- coding: utf-8- *- -from hacknight.models import BaseMixin, BaseScopedIdNameMixin, BaseScopedIdMixin +from hacknight.models import BaseMixin, BaseScopedIdMixin from hacknight.models import db -from hacknight.models.event import Event -from hacknight.models.participant import Participant from hacknight.models.user import User -from hacknight.models.vote import Vote, VoteSpace +from hacknight.models.vote import VoteSpace __all__ = ['CommentSpace', 'Comment'] diff --git a/hacknight/models/event.py b/hacknight/models/event.py index 9dc3c77..c13eaa8 100644 --- a/hacknight/models/event.py +++ b/hacknight/models/event.py @@ -1,9 +1,11 @@ # -*- coding: utf-8 -*- from flask import url_for -from hacknight.models import db, BaseNameMixin, BaseScopedNameMixin +from hacknight.models import db, BaseScopedNameMixin +from hacknight.models.profile import Profile +from hacknight.models.comment import CommentSpace -__all__ = ['Profile', 'Event', 'EVENT_STATUS', 'PROFILE_TYPE'] +__all__ = ['Event', 'EVENT_STATUS'] #need to add EventTurnOut, EventPayment later @@ -32,25 +34,9 @@ class EVENT_STATUS: WITHDRAWN = 7 -class Profile(BaseNameMixin, db.Model): - __tablename__ = 'profile' - - userid = db.Column(db.Unicode(22), nullable=False, unique=True) - description = db.Column(db.UnicodeText, default=u'', nullable=False) - type = db.Column(db.Integer, default=PROFILE_TYPE.UNDEFINED, nullable=False) - - def type_label(self): - return profile_types.get(self.type, profile_types[0]) - - def url_for(self, action='view', _external=True): - if action == 'view': - return url_for('profile_view', profile=self.name, _external=_external) - elif action == 'new-event': - return url_for('event_new', profile=self.name, _external=_external) - - class Event(BaseScopedNameMixin, db.Model): __tablename__ = 'event' + profile_id = db.Column(db.Integer, db.ForeignKey('profile.id'), nullable=False) profile = db.relationship(Profile) parent = db.synonym('profile') @@ -66,8 +52,17 @@ class Event(BaseScopedNameMixin, db.Model): status = db.Column(db.Integer, nullable=False, default=EVENT_STATUS.DRAFT) ticket_price = db.Column(db.Unicode(250), nullable=False, default=u'') + #event wall + comments_id = db.Column(db.Integer, db.ForeignKey('commentspace.id'), nullable=False) + comments = db.relationship(CommentSpace, uselist=False) + __table_args__ = (db.UniqueConstraint('name', 'profile_id'),) + def __init__(self, **kwargs): + super(Event, self).__init__(**kwargs) + if not self.comments: + self.comments = CommentSpace() + def owner_is(self, user): """Check if a user is an owner of this event""" return user is not None and self.profile.userid in user.user_organizations_owned_ids() diff --git a/hacknight/models/user.py b/hacknight/models/user.py index 3f6a286..7d6bc5a 100644 --- a/hacknight/models/user.py +++ b/hacknight/models/user.py @@ -3,7 +3,7 @@ from flask import url_for from flask.ext.lastuser.sqlalchemy import UserBase from hacknight.models import db -from hacknight.models.event import Profile +from hacknight.models.profile import Profile __all__ = ['User'] diff --git a/hacknight/models/venue.py b/hacknight/models/venue.py index af1ae74..2a4a2e6 100644 --- a/hacknight/models/venue.py +++ b/hacknight/models/venue.py @@ -3,7 +3,7 @@ from flask import url_for from hacknight.models import BaseNameMixin from hacknight.models import db -from hacknight.models.event import Profile +from hacknight.models.profile import Profile __all__ = ['Venue'] diff --git a/hacknight/models/vote.py b/hacknight/models/vote.py index b5eea3e..fcaf73a 100644 --- a/hacknight/models/vote.py +++ b/hacknight/models/vote.py @@ -1,13 +1,13 @@ # -*- coding: utf-8- *- -from hacknight.models import BaseMixin, BaseScopedIdNameMixin +from hacknight.models import BaseMixin from hacknight.models import db -from hacknight.models.event import Event -from hacknight.models.participant import Participant from hacknight.models.user import User + __all__ = ['VoteSpace', 'Vote'] + class VoteSpace(BaseMixin, db.Model): __tablename__ = 'votespace' type = db.Column(db.Integer, nullable=True) From 0a88efb66df23ed5898ad374476a0c25dc2b3ff4 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sat, 20 Apr 2013 13:55:28 +0530 Subject: [PATCH 2/5] added endpoints of wall comments --- hacknight/models/__init__.py | 1 + hacknight/templates/event.html | 53 ++++++++++++ hacknight/views/event.py | 147 +++++++++++++++++++++++++++++++-- 3 files changed, 196 insertions(+), 5 deletions(-) diff --git a/hacknight/models/__init__.py b/hacknight/models/__init__.py index f14a212..e720907 100644 --- a/hacknight/models/__init__.py +++ b/hacknight/models/__init__.py @@ -13,3 +13,4 @@ from hacknight.models.project import * from hacknight.models.participant import * from hacknight.models.sponsor import * +from hacknight.models.comment import * diff --git a/hacknight/templates/event.html b/hacknight/templates/event.html index 2615133..16ec9b8 100644 --- a/hacknight/templates/event.html +++ b/hacknight/templates/event.html @@ -1,4 +1,7 @@ {% extends "layout.html" %} +{% from "comments.html" import commenttree %} +{% from "forms.html" import renderform, ajaxform %} + {% block title %}{{ event.title }}{% endblock %} {% macro participant_list(event, participants) -%} @@ -109,6 +112,7 @@

Sponsors

@@ -159,6 +163,55 @@

New project...

+
+
+
+
+

Comments

+ {% if comments %} +
    + {{ commenttree(comments, event, g.user, request.base_url) }} +
+ {% endif %} + {% if not g.user -%} +

+ Login with Twitter or Google to leave a comment → +

+ {% else -%} + +
+ +

+ {{ commentform.message() }} +

+

+ +

+
+ + {% endif %} +
+
+
+
{% if event.venue.latitude and event.venue.longitude %}
diff --git a/hacknight/views/event.py b/hacknight/views/event.py index f5d87c8..99c5a91 100644 --- a/hacknight/views/event.py +++ b/hacknight/views/event.py @@ -1,18 +1,24 @@ # -*- coding: utf-8 -*- +from datetime import datetime from sqlalchemy.orm import joinedload from sqlalchemy import func from html2text import html2text from flask.ext.mail import Message -from flask import render_template, abort, flash, url_for, g, request, Response, Markup -from coaster.views import load_model, load_models +from flask import render_template, abort, flash, url_for, g, request, Response, Markup, redirect +from coaster.views import load_model, load_models, jsonp from baseframe.forms import render_redirect, render_form, render_delete_sqla from hacknight import app, mail -from hacknight.models import db, Profile, Event, User, Participant, PARTICIPANT_STATUS +from hacknight.models import db, Profile, Event, User, Participant, PARTICIPANT_STATUS, Comment from hacknight.forms.event import EventForm, ConfirmWithdrawForm, SendEmailForm from hacknight.forms.participant import ParticipantForm +from hacknight.forms.comment import CommentForm, DeleteCommentForm from hacknight.views.login import lastuser from hacknight.views.workflow import ParticipantWorkflow +from markdown import Markdown +import bleach + +markdown = Markdown(safe_mode="escape").convert def send_email(sender, to, subject, body, html=None): @@ -23,7 +29,7 @@ def send_email(sender, to, subject, body, html=None): mail.send(msg) -@app.route('//', methods=["GET"]) +@app.route('//', methods=["GET", "POST"]) @load_models( (Profile, {'name': 'profile'}, 'profile'), (Event, {'name': 'event', 'profile': 'profile'}, 'event')) @@ -41,14 +47,145 @@ def event_view(profile, event): if p.user == g.user: applied = True break + email_ids = [] + owner = User.query.filter_by(userid=event.profile.userid).first() + if owner and owner.email: + email_ids.append(owner.email) + email_ids.extend([participant.email for participant in accepted_participants if participant.email]) current_participant = Participant.get(user=g.user, event=event) if g.user else None + comments = sorted(Comment.query.filter_by(commentspace=event.comments, reply_to=None).order_by('created_at').all(), + key=lambda c: c.votes.count, reverse=True) + commentform = CommentForm() + delcommentform = DeleteCommentForm() + commentspace = event.comments + if request.method == 'POST': + if request.form.get('form.id') == 'newcomment' and commentform.validate(): + if commentform.edit_id.data: + comment = commentspace.get_comment(int(commentform.edit_id.data)) + if comment: + if comment.user == g.user: + comment.message = commentform.message.data + comment.message_html = markdown(comment.message) + comment.edited_at = datetime.utcnow() + flash("Your comment has been edited", "info") + else: + flash("You can only edit your own comments", "info") + else: + flash("No such comment", "error") + else: + comment = Comment(user=g.user, commentspace=event.comments, message=commentform.message.data) + send_email_info = [] + if commentform.reply_to_id.data: + reply_to = commentspace.get_comment(int(commentform.reply_to_id.data)) + if reply_to and reply_to.commentspace == event.comments: + comment.reply_to = reply_to + if not reply_to.user == g.user: + send_email_info.append({"to": reply_to.user.email, + "subject": "Hacknight: %s " % (event.title), + "template": 'comment_owner_email.md'}) + try: + email_ids.remove(owner.email) + email_ids.remove(reply_to.user.email) + except ValueError: + pass + if owner != reply_to.user: + send_email_info.append({"to": owner.email, + "subject": "Hacknight: %s " % (event.title), + "template": 'project_owner_email.md'}) + try: + email_ids.remove(g.user.email) + except ValueError: + pass + for email_id in email_ids: + send_email_info.append({"to": email_id, + "subject": "Hacknight: %s " % (event.title), + "template": 'project_team_email.md'}) + else: + if not g.user == owner: + try: + email_ids.remove(owner.email) + except ValueError: + pass + send_email_info.append({"to": owner.email, + "subject": "Hacknight: %s " % (event.title), + "template": 'project_owner_email.md'}) + try: + email_ids.remove(g.user.email) + except ValueError: + pass + for email_id in email_ids: + send_email_info.append({"to": email_id, + "subject": "Hacknight: %s " % (event.title), + "template": 'project_team_email.md'}) + + comment.message_html = bleach.linkify(markdown(commentform.message.data)) + event.comments.count += 1 + comment.votes.vote(g.user) # Vote for your own comment + comment.make_id() + db.session.add(comment) + flash("Your comment has been posted", "info") + db.session.commit() return render_template('event.html', profile=profile, event=event, projects=event.projects, accepted_participants=accepted_participants, rest_participants=rest_participants, applied=applied, current_participant=current_participant, - sponsors=event.sponsors) + sponsors=event.sponsors, + comments=comments, + commentform=commentform, + delcommentform=delcommentform) + + +@app.route('///comments//voteup', methods=['GET', 'POST']) +@lastuser.requires_login +@load_models( + (Profile, {'name': 'profile'}, 'profile'), + (Event, {'name': 'event', 'profile': 'profile'}, 'event'), + (Comment, {'url_id': 'cid', 'commentspace': 'event.comments'}, 'comment')) +def wall_voteupcomment(profile, event, comment): + comment.votes.vote(g.user, votedown=False) + db.session.commit() + flash("Your vote has been recorded", "info") + return redirect(event.url_for() + "#wall") + + +@app.route('///comments//votedown', methods=['GET', 'POST']) +@lastuser.requires_login +@load_models( + (Profile, {'name': 'profile'}, 'profile'), + (Event, {'name': 'event', 'profile': 'profile'}, 'event'), + (Comment, {'url_id': 'cid', 'commentspace': 'event.comments'}, 'comment')) +def wall_votedowncomment(profile, event, comment): + comment.votes.vote(g.user, votedown=True) + db.session.commit() + flash("Your vote has been recorded", "info") + return redirect(event.url_for() + "#wall", code=302) + + +@app.route('///comments//json') +@load_models( + (Profile, {'name': 'profile'}, 'profile'), + (Event, {'name': 'event', 'profile': 'profile'}, 'event'), + (Comment, {'url_id': 'cid', 'commentspace': 'event.comments'}, 'comment')) +def wall_jsoncomment(profile, event, comment): + # comment = Comment.query.get(cid) + if comment: + return jsonp(message=comment.message) + return jsonp(message='') + + +@app.route('///comments//cancelvote', methods=['GET', 'POST']) +@lastuser.requires_login +@load_models( + (Profile, {'name': 'profile'}, 'profile'), + (Event, {'name': 'event', 'profile': 'profile'}, 'event'), + (Comment, {'url_id': 'cid', 'commentspace': 'event.comments'}, 'comment')) +def wall_votecancelcomment(profile, event, comment): + comment.votes.cancelvote(g.user) + db.session.commit() + flash("Your vote has been withdrawn", "info") + return redirect(event.url_for() + "#wall", code=302) @app.route('//new', methods=['GET', 'POST']) From ce9dab9e08add1c22a231f86599cbc6f80081d57 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sat, 20 Apr 2013 16:45:44 +0530 Subject: [PATCH 3/5] added wall feature to event --- .../29c2cf7cd05f_add_comments_to_even.py | 22 +++++++++++ hacknight/models/profile.py | 37 +++++++++++++++++++ hacknight/templates/comment_owner_email.md | 2 +- hacknight/templates/event.html | 5 ++- hacknight/templates/project_owner_email.md | 2 +- hacknight/templates/project_team_email.md | 2 +- hacknight/views/event.py | 22 +++++++++++ hacknight/views/project.py | 2 +- 8 files changed, 88 insertions(+), 6 deletions(-) create mode 100644 alembic/versions/29c2cf7cd05f_add_comments_to_even.py create mode 100644 hacknight/models/profile.py diff --git a/alembic/versions/29c2cf7cd05f_add_comments_to_even.py b/alembic/versions/29c2cf7cd05f_add_comments_to_even.py new file mode 100644 index 0000000..8e45bfe --- /dev/null +++ b/alembic/versions/29c2cf7cd05f_add_comments_to_even.py @@ -0,0 +1,22 @@ +"""Add comments to events + +Revision ID: 29c2cf7cd05f +Revises: 2e8783dd05 +Create Date: 2013-04-19 21:29:32.485229 + +""" + +# revision identifiers, used by Alembic. +revision = '29c2cf7cd05f' +down_revision = '2e8783dd05' + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + op.add_column('event', sa.Column('comments_id', sa.Integer, sa.ForeigenKey('commentspace.id'))) + + +def downgrade(): + op.remove_column('event', 'comments_id') diff --git a/hacknight/models/profile.py b/hacknight/models/profile.py new file mode 100644 index 0000000..31dc04a --- /dev/null +++ b/hacknight/models/profile.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +from flask import url_for +from hacknight.models import db, BaseNameMixin + +__all__ = ['Profile', 'PROFILE_TYPE'] + + +class PROFILE_TYPE: + UNDEFINED = 0 + PERSON = 1 + ORGANIZATION = 2 + EVENTSERIES = 3 + +profile_types = { + 0: u"Undefined", + 1: u"Person", + 2: u"Organization", + 3: u"Event Series", + } + + +class Profile(BaseNameMixin, db.Model): + __tablename__ = 'profile' + + userid = db.Column(db.Unicode(22), nullable=False, unique=True) + description = db.Column(db.UnicodeText, default=u'', nullable=False) + type = db.Column(db.Integer, default=PROFILE_TYPE.UNDEFINED, nullable=False) + + def type_label(self): + return profile_types.get(self.type, profile_types[0]) + + def url_for(self, action='view', _external=True): + if action == 'view': + return url_for('profile_view', profile=self.name, _external=_external) + elif action == 'new-event': + return url_for('event_new', profile=self.name, _external=_external) diff --git a/hacknight/templates/comment_owner_email.md b/hacknight/templates/comment_owner_email.md index 6d0a33a..8132b99 100644 --- a/hacknight/templates/comment_owner_email.md +++ b/hacknight/templates/comment_owner_email.md @@ -1,4 +1,4 @@ -**{{ g.user.username }}** replied to you in the project **{{ project.title }}** +**{{ g.user.username }}** replied to you in the {% if wall %} event wall {% else %} project {% endif %} **{{ project.title }}** {{ comment.message }} diff --git a/hacknight/templates/event.html b/hacknight/templates/event.html index 16ec9b8..95d405c 100644 --- a/hacknight/templates/event.html +++ b/hacknight/templates/event.html @@ -166,7 +166,7 @@

New project...

-
+
Discussion space for Hacknight

Comments

{% if comments %}
    @@ -258,7 +258,8 @@

    Comments

    function onZoomend(){ map.setView(venue, map.getZoom()); }; - {% endif %} + {% endif %} + commentsInit("{{ request.base_url }}"); }); diff --git a/hacknight/templates/project_owner_email.md b/hacknight/templates/project_owner_email.md index 0587e14..0ed1b29 100644 --- a/hacknight/templates/project_owner_email.md +++ b/hacknight/templates/project_owner_email.md @@ -1,4 +1,4 @@ -**{{ g.user.username }}** left a comment on your project **{{ project.title }}** +**{{ g.user.username }}** left a comment {% if wall %} in event wall {% else %} on your project {% endif %} **{{ project.title }}** {{ comment.message }} diff --git a/hacknight/templates/project_team_email.md b/hacknight/templates/project_team_email.md index d9fce8a..021e2ab 100644 --- a/hacknight/templates/project_team_email.md +++ b/hacknight/templates/project_team_email.md @@ -1,4 +1,4 @@ -**{{ g.user.username }}** left a comment in the project **{{ project.title }}** +**{{ g.user.username }}** left a comment in the {% if wall %} event wall {% else %} project {% endif %} **{{ project.title }}** {{ comment.message }} diff --git a/hacknight/views/event.py b/hacknight/views/event.py index 99c5a91..f76fc45 100644 --- a/hacknight/views/event.py +++ b/hacknight/views/event.py @@ -125,6 +125,28 @@ def event_view(profile, event): db.session.add(comment) flash("Your comment has been posted", "info") db.session.commit() + link = event.url_for("view", _external=True) + "#c" + str(comment.id) + for item in send_email_info: + email_body = render_template(item.pop('template'), project=event, comment=comment, wall=True, link=link) + if item['to']: + send_email(sender=None, html=markdown(email_body), body=email_body, **item) + # Redirect despite this being the same page because HTTP 303 is required to not break + # the browser Back button + return redirect(event.url_for() + "#wall") + + elif request.form.get('form.id') == 'delcomment' and delcommentform.validate(): + comment = commentspace.get_comment(int(delcommentform.comment_id.data)) + if comment: + if comment.user == g.user: + comment.delete() + event.comments.count -= 1 + db.session.commit() + flash("Your comment was deleted.", "info") + else: + flash("You did not post that comment.", "error") + else: + flash("No such comment.", "error") + return redirect(event.url_for() + "#wall") return render_template('event.html', profile=profile, event=event, projects=event.projects, accepted_participants=accepted_participants, diff --git a/hacknight/views/project.py b/hacknight/views/project.py index e36660c..b3207c7 100644 --- a/hacknight/views/project.py +++ b/hacknight/views/project.py @@ -213,7 +213,7 @@ def project_view(profile, event, project): db.session.commit() link = project.url_for("view", _external=True) + "#c" + str(comment.id) for item in send_email_info: - email_body = render_template(item.pop('template'), project=project, comment=comment, link=link) + email_body = render_template(item.pop('template'), project=project, comment=comment, wall=False, link=link) if item['to']: send_email(sender=None, html=markdown(email_body), body=email_body, **item) # Redirect despite this being the same page because HTTP 303 is required to not break From 20e28094f8e737abeb476f1d8f16b989afc97fa2 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Sun, 21 Apr 2013 12:15:45 +0530 Subject: [PATCH 4/5] Removed accepted participants from email lists --- hacknight/views/event.py | 1 - 1 file changed, 1 deletion(-) diff --git a/hacknight/views/event.py b/hacknight/views/event.py index f76fc45..14504db 100644 --- a/hacknight/views/event.py +++ b/hacknight/views/event.py @@ -51,7 +51,6 @@ def event_view(profile, event): owner = User.query.filter_by(userid=event.profile.userid).first() if owner and owner.email: email_ids.append(owner.email) - email_ids.extend([participant.email for participant in accepted_participants if participant.email]) current_participant = Participant.get(user=g.user, event=event) if g.user else None comments = sorted(Comment.query.filter_by(commentspace=event.comments, reply_to=None).order_by('created_at').all(), key=lambda c: c.votes.count, reverse=True) From 3f94e2c0bd67d7d4b735139a853ffc65677ea721 Mon Sep 17 00:00:00 2001 From: kracekumar Date: Thu, 25 Apr 2013 19:39:24 +0530 Subject: [PATCH 5/5] Removed notification for event wall and modified grammar mistakes --- hacknight/templates/comment_owner_email.md | 2 +- hacknight/templates/project_owner_email.md | 2 +- hacknight/templates/project_team_email.md | 2 +- hacknight/views/event.py | 53 ---------------------- 4 files changed, 3 insertions(+), 56 deletions(-) diff --git a/hacknight/templates/comment_owner_email.md b/hacknight/templates/comment_owner_email.md index 8132b99..407eab5 100644 --- a/hacknight/templates/comment_owner_email.md +++ b/hacknight/templates/comment_owner_email.md @@ -1,4 +1,4 @@ -**{{ g.user.username }}** replied to you in the {% if wall %} event wall {% else %} project {% endif %} **{{ project.title }}** +**{{ g.user.username }}** replied to you {% if wall %} on the event wall {% else %} in the project {% endif %} **{{ project.title }}** {{ comment.message }} diff --git a/hacknight/templates/project_owner_email.md b/hacknight/templates/project_owner_email.md index 0ed1b29..4f7c7ff 100644 --- a/hacknight/templates/project_owner_email.md +++ b/hacknight/templates/project_owner_email.md @@ -1,4 +1,4 @@ -**{{ g.user.username }}** left a comment {% if wall %} in event wall {% else %} on your project {% endif %} **{{ project.title }}** +**{{ g.user.username }}** left a comment {% if wall %} on the event wall {% else %} on your project {% endif %} **{{ project.title }}** {{ comment.message }} diff --git a/hacknight/templates/project_team_email.md b/hacknight/templates/project_team_email.md index 021e2ab..0e50a37 100644 --- a/hacknight/templates/project_team_email.md +++ b/hacknight/templates/project_team_email.md @@ -1,4 +1,4 @@ -**{{ g.user.username }}** left a comment in the {% if wall %} event wall {% else %} project {% endif %} **{{ project.title }}** +**{{ g.user.username }}** left a comment {% if wall %} on the event wall {% else %} in the project {% endif %} **{{ project.title }}** {{ comment.message }} diff --git a/hacknight/views/event.py b/hacknight/views/event.py index 14504db..f6e0a0a 100644 --- a/hacknight/views/event.py +++ b/hacknight/views/event.py @@ -47,10 +47,6 @@ def event_view(profile, event): if p.user == g.user: applied = True break - email_ids = [] - owner = User.query.filter_by(userid=event.profile.userid).first() - if owner and owner.email: - email_ids.append(owner.email) current_participant = Participant.get(user=g.user, event=event) if g.user else None comments = sorted(Comment.query.filter_by(commentspace=event.comments, reply_to=None).order_by('created_at').all(), key=lambda c: c.votes.count, reverse=True) @@ -73,50 +69,6 @@ def event_view(profile, event): flash("No such comment", "error") else: comment = Comment(user=g.user, commentspace=event.comments, message=commentform.message.data) - send_email_info = [] - if commentform.reply_to_id.data: - reply_to = commentspace.get_comment(int(commentform.reply_to_id.data)) - if reply_to and reply_to.commentspace == event.comments: - comment.reply_to = reply_to - if not reply_to.user == g.user: - send_email_info.append({"to": reply_to.user.email, - "subject": "Hacknight: %s " % (event.title), - "template": 'comment_owner_email.md'}) - try: - email_ids.remove(owner.email) - email_ids.remove(reply_to.user.email) - except ValueError: - pass - if owner != reply_to.user: - send_email_info.append({"to": owner.email, - "subject": "Hacknight: %s " % (event.title), - "template": 'project_owner_email.md'}) - try: - email_ids.remove(g.user.email) - except ValueError: - pass - for email_id in email_ids: - send_email_info.append({"to": email_id, - "subject": "Hacknight: %s " % (event.title), - "template": 'project_team_email.md'}) - else: - if not g.user == owner: - try: - email_ids.remove(owner.email) - except ValueError: - pass - send_email_info.append({"to": owner.email, - "subject": "Hacknight: %s " % (event.title), - "template": 'project_owner_email.md'}) - try: - email_ids.remove(g.user.email) - except ValueError: - pass - for email_id in email_ids: - send_email_info.append({"to": email_id, - "subject": "Hacknight: %s " % (event.title), - "template": 'project_team_email.md'}) - comment.message_html = bleach.linkify(markdown(commentform.message.data)) event.comments.count += 1 comment.votes.vote(g.user) # Vote for your own comment @@ -124,11 +76,6 @@ def event_view(profile, event): db.session.add(comment) flash("Your comment has been posted", "info") db.session.commit() - link = event.url_for("view", _external=True) + "#c" + str(comment.id) - for item in send_email_info: - email_body = render_template(item.pop('template'), project=event, comment=comment, wall=True, link=link) - if item['to']: - send_email(sender=None, html=markdown(email_body), body=email_body, **item) # Redirect despite this being the same page because HTTP 303 is required to not break # the browser Back button return redirect(event.url_for() + "#wall")