def subscribe(): info = (request.data).decode('utf-8') print(info) print(info) print(type(info)) subsEntry = Subscriber() subsEntry.set_subsinfo(info) item = Subscriber.query.filter_by(subscription_info= info).first() if item is None: db.session.add(subsEntry) db.session.commit() print('Subscription created!') else: print('Subscription exists!') response = jsonify() response.status_code = 201 response.id = subsEntry.id return response
def blog(): page = request.args.get("page", 1, type=int) posts = Post.query.paginate( page, app.config["POST_PER_PAGE"], False ) next_url = url_for('blog', page=posts.next_num) \ if posts.has_next else None prev_url = url_for('blog', page=posts.prev_num) \ if posts.has_prev else None if request.method == 'POST': email = request.form['email'] subscriber = Subscriber.query.filter_by(email=email).first() if subscriber: flash('Already subscribe our news least!', "warning") return redirect(url_for('blog')) new_sub = Subscriber(email=email) db.session.add(new_sub) admin = Owner.query.filter(Owner.id).first() admin.add_notification('unread_message_count', admin.new_subscriber()) db.session.commit() flash("Successfully subscribe our news least!", "success") return redirect(url_for('blog')) return render_template('client/blog.html', title='Blog', posts=posts.items, next_url=next_url, prev_url=prev_url, b64encode=b64encode)
def subscribe(): Page.set_nav() form = SubscribeForm() form.subscription.choices = Subscriber.SUBSCRIPTION_CHOICES for field in form: print(f"{field.name}: {field.data}") if form.validate_on_submit(): print("Validated") sub = Subscriber( email=form.email.data, first_name=form.first_name.data, last_name=form.last_name.data, ) current_app.logger.debug(form.subscription.choices) if "all" in form.subscription.data: choices = [c[0] for c in form.subscription.choices] current_app.logger.debug(choices) choices.remove("all") sub.subscription = "," + ",".join(choices) + "," else: sub.subscription = "," + ",".join(form.subscription.data) + "," current_app.logger.debug(sub.subscription) #raise Exception('pause') db.session.add(sub) db.session.commit() sub.welcome() current_app.logger.info(f'New Subscriber!\n {repr(sub)}') flash('You have subscribed successfully!', 'success') return redirect(url_for('page.home')) form.subscription.data = [i[0] for i in Subscriber.SUBSCRIPTION_CHOICES] return render_template('subscribe.html', form=form)
def insert_one(self, subscriber): new_subscriber = Subscriber() if "email" in subscriber: new_subscriber.email = subscriber["email"] if "phone" in subscriber: new_subscriber.phone = subscriber["phone"] if "endpoint" in subscriber: new_subscriber.endpoint = subscriber["endpoint"] if "auth_token" in subscriber: new_subscriber.auth_token = subscriber["auth_token"] if "type" in subscriber: new_subscriber.type = subscriber["type"] if "status" in subscriber: new_subscriber.status = subscriber["status"] if "external_id" in subscriber: new_subscriber.external_id = subscriber["external_id"] new_subscriber.save() return False if new_subscriber.pk is None else new_subscriber
def subscribe(): email = request.form.get('subscriber') new_subscriber = Subscriber(email = email) new_subscriber.save_subscriber() mail_message("Subscribed successfully to Steve's blogs","email/welcome_subscriber",new_subscriber.email,new_subscriber=new_subscriber) flash('Subscribed successfully to Steve\'s blogs') return redirect(url_for('main.index'))
def subscribe(): email = request.form.get('subscriber') new_subscriber = Subscriber(email = email) new_subscriber.save_subscriber() mail_message("Subscribed to D-Blog","email/welcome_subscriber",new_subscriber.email,new_subscriber=new_subscriber) flash('Sucessfuly subscribed') return redirect(url_for('main.index'))
def post_view(title): title = title.replace("-", " ") posts = Post.query.order_by(Post.timestamp.desc()).all()[0:9] post = Post.query.filter_by(title=title).first() image = b64encode(post.image).decode("utf-8") post.article_views = post.article_views + 1 db.session.commit() if request.method == 'POST': email = request.form['email'] subscriber = Subscriber.query.filter_by(email=email).first() if subscriber: flash('Already subscribe our news least!', "warning") return redirect(url_for('post_view', title=title.replace(' ', '-'))) new_sub = Subscriber(email=email) db.session.add(new_sub) admin = Owner.query.filter(Owner.id).first() admin.add_notification('unread_message_count', admin.new_subscriber()) db.session.commit() flash("Successfully subscribe our news least!", "success") return redirect(url_for('post_view', title=title)) return render_template('client/post_view.html', title='Blog Post', post=post, posts=posts, image=image)
def subscribe(): email = request.form.get('subscriber') new_subscriber = Subscriber(email=email) # new_subscriber.save_su/bscriber() db.session.add(new_subscriber) db.session.commit() # mail_message("Subscribed to BLOBBER","email/welcome_subscriber",new_subscriber.email) flash('Sucessfuly subscribed') return redirect(url_for('main.index'))
def subscriber_create(): try: data = json.loads(request.get_data()) subscriber = Subscriber(data['user_id'], data['subscriber_id']) db.session.add(subscriber) db.session.commit() except: return 'Failed' return json.dumps(subscriber.to_dict(), ensure_ascii = False)
def setUp(self): """ Runs before each test """ db.create_all() self.subscriber = Subscriber(email="*****@*****.**", first_name="John", last_name="Doe") self.user = User(user_name="victormainak")
def subscribe(): email = request.form.get('subscriber') new_subscriber = Subscriber(email=email) new_subscriber.save_subscriber() mail_message("Subscribed to Blog Today", "email/welcome_subscriber", new_subscriber.email, new_subscriber=new_subscriber) flash('You are Successfully subscribed to this Blog!') return redirect(url_for('main.index'))
def test_subscribers(self): """ Test case to check if subscribers property is created """ db.session.add(self.user) db.session.commit() sub = Subscriber(email="*****@*****.**") sub.subscriptions.append(self.user) db.session.add(sub) db.session.commit() self.assertTrue(len(self.user.subscribers) > 0)
def new_subscription(): email = request.json.get('email') ticker_name = request.json.get('ticker') max_price = request.json.get('max_price') min_price = request.json.get('min_price') if max_price is None and min_price is None: message = 'You haven\'t specified neither min_price nor max_price' return bad_request(request.json, message) if email == '': message = 'You haven\'t specified email' return bad_request(request.json, message) if ticker_name == '': message = 'You haven\'t specified ticker' return bad_request(request.json, message) subscriber = Subscriber.query.filter_by(email=email).first() if subscriber is None: subscriber = Subscriber(email=email) db.session.add(subscriber) db.session.flush() send_on_new_subscription(email, ticker_name) subscriber.subscribe(ticker_name, max_price, min_price) db.session.commit() elif subscriber.subscriptions.count() >= 5: message = 'You are subscribed to maximum number of tickers.' return bad_request(request.json, message) elif not subscriber.is_subscribed(ticker_name): subscriber.subscribe(ticker_name, max_price, min_price) db.session.commit() send_on_new_subscription(email, ticker_name) else: message = f'You are subscribed to {ticker_name} ticker already.' return bad_request(request.json, message) return ok_request(request.json, 1)
def shop(): products = Product.query.all() if request.method == 'POST': email = request.form['email'] subscriber = Subscriber.query.filter_by(email=email).first() if subscriber: flash('Already subscribe our news least!', "warning") return redirect(url_for('shop')) new_sub = Subscriber(email=email) db.session.add(new_sub) admin = Owner.query.filter(Owner.id).first() admin.add_notification('unread_message_count', admin.new_subscriber()) db.session.commit() flash("Successfully subscribe our news least!", "success") return redirect(url_for('shop')) return render_template('client/shop.html', title='Shop', products=products, b64encode=b64encode)
def index(): posts = Post.query.order_by(Post.timestamp.desc()).all()[0:6] if request.method == 'POST': email = request.form['email'] subscriber = Subscriber.query.filter_by(email=email).first() if subscriber: flash('Already subscribe our news least!', "warning") return redirect(url_for('index')) new_sub = Subscriber(email=email) db.session.add(new_sub) admin = Owner.query.filter(Owner.id).first() admin.add_notification('unread_message_count', admin.new_subscriber()) db.session.commit() flash("Successfully subscribe our news least!", "success") return redirect(url_for('index')) return render_template('client/index.html', title='Home Page', posts=posts, b64encode=b64encode)
def setUp(self): self.new_sub = Subscriber(username='******')
def setUp(self): self.new_subscriber = Subscriber(id = 1 , name = 'ha', email = 'he')
def setUp(self): """ This will create a new sub before each test """ self.new_sub = Subscriber(email="[email protected]")
def subscribe(): email = request.form.get('subscriber') new_subscriber = Subscriber(email=email) new_subscriber.save_subscriber() flash('Done') return redirect(url_for('main.index'))
def setUp(self): self.new_subscriber = Subscriber(email='*****@*****.**')
def setUp(self): ''' Set up method that will run before every Test ''' self.new_subscriber = Subscriber()
def setUp(self): ''' method to run before each test case ''' self.new_subscriber = Subscriber(email='*****@*****.**')
def setUp(self): """ This will create a new sub before each test """ self.new_sub = Subscriber(email="*****@*****.**")
def setUp(self): self.new_subscriber = Subscriber(email='*****@*****.**')
def setUp(self): self.new_sub = Subscriber(email="*****@*****.**")
def setUp(self): self.new_sub = Subscriber(username = '******')
def setUp(self): self.new_subscriber = Subscriber( email = '*****@*****.**' )
def setUp(self): self.new_subscriber = Subscriber(email='*****@*****.**')
def submit_comment(): form = AuthenticatedCommentForm( ) if current_user.is_authenticated else CommentForm() if form.validate_on_submit(): current_app.logger.debug(request.form) captcha_data = { 'secret': current_app.config['RECAPTCHA_SECRET'], 'response': request.form.get('token'), } resp = requests.post('https://www.google.com/recaptcha/api/siteverify', captcha_data) response_data = resp.json() current_app.logger.debug(response_data) if current_app.config.get('DEVELOPMENT'): response_data['success'] = True #REMOVE if response_data.get('success'): form.reply_id.data = form.reply_id.data if form.reply_id.data else None form.page_id.data = form.page_id.data if form.page_id.data else None form.product_id.data = form.product_id.data if form.product_id.data else None comment = Comment() form.populate_obj(comment) current_app.logger.debug(f'REPLY ID: {comment.reply_id}') comment.ip = request.remote_addr if current_user.is_authenticated: comment.user_id = current_user.id comment.name = current_user.display_name() comment.email = current_user.email db.session.add(comment) db.session.commit() log_new(comment, 'added a comment') flash('Comment added.', 'success') comment.notify() # notify admin if comment.email: subscriber = Subscriber.query.filter_by( email=comment.email).first() if not subscriber: subscriber = Subscriber(first_name=comment.name, email=comment.email, subscription=',Comment Replies,') if form.subscribe.data: subscriber.subscription += ','.join([ i[0] for i in current_app.config['SUBSCRIPTION_GROUPS'] ]) + ',' db.session.add(subscriber) db.session.commit() if form.subscribe.data: log_new(subscriber, 'subscribed') flash('Subscribed!', 'success') subscriber.welcome() else: log_orig = log_change(subscriber) subscriber.subscription = ',Comment Replies,' if form.subscribe.data: subscriber.subscription += ','.join([ i[0] for i in current_app.config['SUBSCRIPTION_GROUPS'] ]) + ',' log_change(log_orig, subscriber, 'updated subscriptions') db.session.commit() flash('You are already subscribed!', 'info') else: if form.subscribe.data: flash( 'You must provide an email address to subscribe. Please <a href="/subscribe">subscribe here</a> instead.', 'info') comment.notify_reply() # Notify commenter replied to else: flash( 'Unable to save comment. Recaptcha flagged you as a bot. If you are not a bot, please try submitting your comment again.', 'danger') return redirect(request.referrer)