def subscribe(): form = SubscribeForm() if form.validate_on_submit(): channel = db.channel_get_by_id(form.channel_id.data) current_user.subscribe(channel) print current_user.subscribes db.session.commit() return redirect(url_for('channel_list'))
def subscribe_event(event_id): is_user_subscribed = UserEvents.query.filter_by(user_id=current_user.id, event_id=event_id).first() if is_user_subscribed: return redirect(url_for('event.index')) else: current_user.subscribe(event_id=event_id) return redirect(url_for('event.index'))
def subscribe(feed): """ Subscribe user to given feed :param feed: feed to subscribe to :return: """ current_user.subscribe(feed) return redirect(feed.route)
def subscription(): subscription_id = int(request.form['id']) if current_user.is_anonymous: return "failure", 500 elif current_user.is_subscribed(subscription_id): current_user.unsubscribe(subscription_id) else: current_user.subscribe(subscription_id) return "success", 200
def subscribe(): user_id = int(request.form['user_id']) source_id = int(request.form['source_id']) if current_user.id != user_id: abort(404) if not current_user.is_subscribed(source_id): current_user.subscribe(source_id) return jsonify(source_id=source_id, user_id=user_id) abort(404)
def subscribe(tag, post_title, action): tag = Tags.query.filter_by(tag=tag).first_or_404() post = Posts.query.filter_by(title=post_title, tag=tag).first_or_404() if action == 'subscribe': current_user.subscribe(post) db.session.commit() elif action == 'unsubscribe': current_user.unsubscribe(post) db.session.commit() return redirect(request.referrer)
def subscribe(feed_id): feed = Feed.query.filter_by(id=feed_id).first_or_404() user = User.query.filter_by(id=feed.owner_id).first() if user.id == current_user.id: flash('You are subscribed to your feeds by default') return redirect(url_for('user', user=user)) current_user.subscribe(feed) db.session.commit() flash('You have subscribed to {} feed'.format(feed.name)) return redirect(url_for('user', user=user))
def subscribe(id): topic = Topic.query.filter_by(id=id).first() if topic is None: flash('Invalid topic.') return redirect(url_for('main.index')) if current_user.is_subscribed(topic): flash('You are already subscribed.') return redirect(url_for('main.index')) current_user.subscribe(topic) return redirect(url_for('main.topic', name=topic.name))
def subscribe(id): event = Event.query.filter_by(id=id).first() if event is None: flash('Event not found.') return redirect(url_for('index')) if current_user.is_subscribed(event): flash('You are already subscribed') return redirect(url_for('event', id=id)) current_user.subscribe(event) db.session.commit() flash('You are now subscribed to {}'.format(event.title)) return redirect(url_for('event', id=id))
def subscribe(username): form = EmptyForm() if form.validate_on_submit(): user = User.query.filter_by(username=username).first() if user is None: flash('User {} not found.'.format(username)) return redirect(url_for('index')) if user == current_user: flash('You cannot subscribe yourself!') return redirect(url_for('user', username=username)) current_user.subscribe(user) db.session.commit() flash('You are subscribing {}!'.format(username)) return redirect(url_for('user', username=username)) else: return redirect(url_for('index'))
def create(_name, _description): """ Creates a room if all criteria is met If the route has arrived here, the user has already been authenticated 1. Room name doesn't exist """ try: roomname = Room.query.filter_by(name=_name).first() except: roomname = None if roomname is not None: flash(u"Room {name} already exists".format(name=_name), 'error') return render_template('index/rooms.htm.j2') try: room = Room(name=_name.lower(), description=_description) room.set_owner(g.user.id, g.user.username) room.set_id(''.join(choice(ascii_uppercase) for i in range(12))) db.session.add(room) current_user.subscribe(room) db.session.commit() except Exception as e: logging.error(f"{e}") flash(u"An error has occured", 'error') return render_template('index/index.htm.j2') print(f"Room: {room.name} [created]") data = { 'type': 'room', 'name': room.name, 'id': room.id, 'description': room.description, 'owner': [{ 'id': room.owner }, { 'username': room.owner_username }], 'created_date': str(room.created) } file = f"{api_directory}/room/{room.id}.json" if os.path.exists(f"{api_directory}/room/"): if not os.path.exists(file): open(file, "w") with open(file, "w") as json_file: json.dump(data, json_file) return redirect(url_for('routes.show_room', name=room.name))
def add_events(): form = EventForm() if form.validate_on_submit(): event = Event(title=form.title.data, description=form.description.data, start_date=form.start_date.data, start_time=form.start_time.data, end_date=form.end_date.data, end_time=form.end_time.data, address=form.address.data, zipcode=form.zipcode.data, category=form.category.data, creater=current_user) db.session.add(event) current_user.subscribe(event) db.session.commit() flash('Your event has been added to the calendar') return redirect(url_for('index')) return render_template('add_events.html', title='Add Events', form=form)
def subscribe(_id): """ Adds a subscription to specified_room by current_user Adds a subscriber to specified_room by current_user """ try: room = Room.query.filter_by(id=_id).first() except Exception as e: room = None if room is not None: try: current_user.subscribe(room) db.session.commit() except Exception as e: db.session.rollback() logging.error(f"{e}") return ErrorController.error(e) return redirect(url_for("routes.show_room", name=room.name)) flash(u"Room: {id} doesn't exist".format(id=_id)) return redirect(url_for("routes.index"))
def duplicate_events(id): form = EventForm() event = Event.query.filter_by(id=int(id)).first_or_404() if form.validate_on_submit() and event.creater == current_user: new_event = Event(title=form.title.data, description=form.description.data, hyperlink=form.hyperlink.data, start_date=form.start_date.data, start_time=form.start_time.data, end_date=form.end_date.data, end_time=form.end_time.data, address=form.address.data, zipcode=form.zipcode.data, category=form.category.data, creater=current_user) db.session.add(new_event) current_user.subscribe(new_event) db.session.commit() flash('Your changes have been saved') return redirect(url_for('calendar')) elif request.method == 'GET' and event != None: form.title.data = event.title form.description.data = event.description form.hyperlink.data = event.hyperlink form.start_date.data = event.start_date + datetime.timedelta(days=7) form.start_time.data = event.start_time if event.end_date: form.end_date.data = event.end_date + datetime.timedelta(days=7) form.end_time.data = event.end_time form.address.data = event.address form.zipcode.data = event.zipcode form.category.data = event.category else: return redirect(url_for('event', id=id)) return render_template('add_events.html', title='Edit Event', form=form)
def subscribe(): current_user.subscribe() db.session.commit() return jsonify()