def event_set_maybe(event_id): if not g.logged_in: abort(401) e = Event(redis=g.r, user=g.user) e.load(event_id) e.set_maybe() flash("You have been marked as maybe attending.", "success") return redirect(url_for("view_event", event_id=event_id))
def event_add_comment(event_id): e = Event(redis=g.r, user=g.user) e.load(event_id) try: e.add_comment(request.form["text"]) flash("Comment has been added.", "success") except EventCommentError as detail: flash(detail, "error") return redirect(url_for("view_event", event_id=event_id) + "#comments")
def event_del_comment(event_id, comment_id): e = Event(redis=g.r, user=g.user) e.load(event_id) user = e.comment_user(comment_id) if user != g.user.key and e.data["creator"] != g.user.username: abort(401) e.del_comment(comment_id) flash("Comment has been deleted.", "success") return redirect(url_for("view_event", event_id=event_id) + "#comments")
def save_event(event_id=False, new=False): try: g.user.username except AttributeError: abort(401) e = Event(redis=g.r, user=g.user) if not new: try: e.load(event_id) except EventNotFoundError: abort(404) print e.data if e.data["creator"] != g.user.username: abort(401) if request.method == "POST": e.update(request.form) try: image = request.files.get("image") if image: try: e.data["image"] = upload_event_image(image) flash("Upload successful.", "success") except UploadNotAllowed: flash("Upload not allowed.", "error") e.save() if new: flash("Event created.", "success") else: flash("Changes saved.", "success") if new: return redirect(url_for("view_event", event_id=e.key)) else: return redirect(url_for("edit_event", event_id=e.key)) except EventValidationError: for error in e.validation_errors: flash(error, "error") return render_template("forms/event.html", new=new, event=e)
def del_event(event_id): e = Event(redis=g.r, user=g.user) e.load(event_id) try: if g.user.username != e.data["creator"]: print e.data abort(401) except AttributeError: abort(401) if request.method == "POST": e.delete() flash("Event deleted.", "success") return redirect(url_for("list_events")) else: return render_template( "confirm.html", _message="Are you sure you wish to DELETE this thread?", _ok=url_for("del_event", event_id=event_id), _cancel=url_for("view_event", event_id=event_id), )
def view_event(event_id): e = Event(redis=g.r, user=g.user) e.load(event_id) return render_template("event.html", event=e, state=g.user.get_event_state(event_id))