def producentname(telnr): db = psycopg2.connect(dbname="aj1200", user="******", password="******", host="pgserver.mah.se") connect = db.cursor() if request.method == "POST": telnr = request.form.get('telnr') rating = request.form.get('rating') email = session['emailKonsument'] connect.execute( "INSERT INTO rating(email, telnr, rating) VALUES(%s,%s,%s);", (email, telnr, rating)) db.commit() return redirect(url_for("home")) elif request.method == "GET": print(telnr) if 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) != False: listWithProducent = other.getProducentInfo(telnr) newnumber = "'" + telnr + "'" connect.execute( "SELECT sum(rating) AS total FROM rating WHERE telnr='%s'" % (telnr)) total = connect.fetchall() db.commit() if len(listWithProducent) != 0: return render_template("producent.html", rating=total, listWithProducent=listWithProducent) else: return redirect(url_for('home')) else: return redirect(url_for('notVerified')) elif 'usernameKonsument' in session: listWithProducent = other.getProducentInfo(telnr) newnumber = "'" + telnr + "'" connect.execute( "SELECT sum(rating.rating) AS total FROM rating WHERE telnr='%s'" % (telnr)) total = connect.fetchone() rating = total[0] db.commit() if len(listWithProducent) != 0: return render_template("producent.html", rating=rating, listWithProducent=listWithProducent) else: return redirect(url_for('home')) else: return redirect(url_for('login'))
def myorders(): if 'usernameProducent' in session or 'usernameKonsument' in session: if request.method == 'POST': kvitto = buyArticle.buyArticle() if 'usernameKonsument' in session: buyArticle.addToOrders(kvitto, session['emailKonsument']) buyArticle.sendEmail(session['emailKonsument'], kvitto) article.removeArticleAntal() return redirect(url_for('myorders')) else: buyArticle.addToOrders(kvitto, session['telnrProducent']) buyArticle.sendEmail(session['telnrProducent'], kvitto) article.removeArticleAntal() return redirect(url_for('myorders')) else: if 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == True: listWithOrder = buyArticle.orders( session['telnrProducent'], session['usernameProducent']) return render_template("myorders.html", listWithOrder=listWithOrder, empty=len(listWithOrder)) else: return redirect(url_for('notVerified')) else: listWithOrder = buyArticle.orders(session['emailKonsument'], session['usernameKonsument']) summa = 0 for i in listWithOrder: summa += i[5] * i[13] return render_template("myorders.html", summa=summa, listWithOrder=listWithOrder, empty=len(listWithOrder)) else: return redirect(url_for('login'))
def notVerified(): if 'usernameKonsument' in session: return redirect(url_for('home')) elif 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == False: return render_template("notVerified.html", username=session['usernameProducent']) elif other.verifyProducent(session['telnrProducent']) == True: return redirect(url_for('home')) else: return redirect(url_for('foodtell')) else: return redirect(url_for('login'))
def addarticle(): if 'usernameKonsument' in session: return redirect(url_for('home')) elif 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == True: return render_template("form.html") else: return redirect(url_for('notVerified')) else: return redirect(url_for('login'))
def register(): if 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == True: return redirect(url_for('home')) else: return redirect(url_for(('notVerified'))) elif 'usernameKonsument' in session: return redirect(url_for('home')) else: return render_template("register.html")
def index(): if 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == True: return redirect(url_for('home')) else: return redirect(url_for(('notVerified'))) # SKAPA EN HTML FIL elif 'usernameKonsument' in session: return redirect(url_for('home')) else: return render_template("index.html")
def myArticlesExpired(): if 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == True: article.removeArticleTime() producentArticles = article.producentArticles( session['telnrProducent']) return render_template("myarticles1.html", Expired=producentArticles[1], empty=len(producentArticles[1])) else: return redirect(url_for('notVerified')) elif 'usernameKonsument' in session: return redirect(url_for('home')) else: return redirect(url_for('login'))
def producent(): if 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) != False: listWithProducentName = other.getAllProducentName() return render_template("producentmain.html", listWithProducentName=listWithProducentName) else: return redirect(url_for('notVerified')) elif 'usernameKonsument' in session: listWithProducentName = other.getAllProducentName() return render_template("producentmain.html", listWithProducentName=listWithProducentName) else: return redirect(url_for('login'))
def removeorder(): if 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == True: if request.method == 'POST': buyArticle.removeOrder() return redirect(url_for('home')) else: return redirect(url_for('home')) else: return redirect(url_for('notVerified')) elif 'usernameKonsument' in session: return redirect(url_for('home')) else: return redirect(url_for('login'))
def orders(): if 'usernameKonsument' in session: return redirect(url_for('home')) elif 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == True: listWithOrder = buyArticle.producentOrders( session['telnrProducent']) return render_template("manageorder.html", listWithOrder=listWithOrder, producent=True, lenOrder=len(listWithOrder)) else: return redirect(url_for('notVerified')) else: return redirect(url_for('login'))
def home(): producent = None if 'usernameKonsument' in session: return render_template("home.html", username=session['usernameKonsument']) elif 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == True: producent = True return render_template("home.html", username=session['usernameProducent'], producent=producent) else: return redirect(url_for('notVerified')) elif request.method == 'POST': if request.form.get('registerKonsument') == "REGISTRERA": tryRegister = reg.tryRegisterKonsument() if tryRegister == 'User exist ON EMAIL AND TELNR': flash('USER ALREADY EXIST ON EMAIL AND TELNR', 'error') return redirect(url_for('register')) elif tryRegister == 'User exist ON EMAIL': flash('USER ALREADY EXIST ON EMAIL', 'error') return redirect(url_for('register')) elif tryRegister == 'User exist ON TELNR': flash('USER ALREADY EXIST ON TELNR', 'error') return redirect(url_for('register')) else: session['usernameKonsument'] = tryRegister[ 1] + " " + tryRegister[2] session['emailKonsument'] = tryRegister[0] return redirect(url_for('home')) elif request.form.get('registerProducent') == "REGISTRERA": tryRegister = reg.tryRegisterProducent() if tryRegister == 'User exist': flash('USER ALREADY EXIST ON TELNR', 'error') return redirect(url_for('register')) else: session['telnrProducent'] = tryRegister[0] session['emailProducent'] = tryRegister[1] session['usernameProducent'] = tryRegister[2] return redirect(url_for('home')) elif request.form.get('loginKonsument') == "LOGGA IN": tryLogin = log.tryLoginKonsument() if tryLogin == 'Invalid': flash('INVALID DETAILS', 'error') return redirect(url_for('login')) elif isinstance(tryLogin, (list, )): session['usernameKonsument'] = tryLogin[1] + " " + tryLogin[2] session['emailKonsument'] = tryLogin[0] return redirect(url_for('home')) else: flash('INVALID DETAILS', 'error') return redirect(url_for('login')) else: tryLogin = log.tryLoginProducent() if tryLogin == 'Invalid': flash('INVALID DETAILS', 'error') return redirect(url_for('login')) elif isinstance(tryLogin, (list, )): if len(tryLogin) == 3: # Om det är annan producent än Foodtell session['telnrProducent'] = tryLogin[0] session['emailProducent'] = tryLogin[1] session['usernameProducent'] = tryLogin[2] return redirect(url_for('home')) else: session['telnrFoodtell'] = tryLogin[0] session['emailFoodtell'] = tryLogin[1] session['usernameFoodtell'] = tryLogin[2] return redirect(url_for('foodtell')) else: flash('INVALID DETAILS', 'error') return redirect(url_for('login')) elif 'usernameFoodtell' in session: return redirect(url_for('foodtell')) else: return redirect(url_for('login'))
def articles(): category = 'Alla' if request.method == "POST": post_type = request.form.get('post_type') if post_type == '0': category = request.form.get('category') print(category) elif post_type == '1': db = psycopg2.connect(dbname="aj1200", user="******", password="******", host="pgserver.mah.se") connect = db.cursor() rating = request.form.get('rating') article_rated = request.form.get('article_rated') if rating == '1': connect.execute( "UPDATE artikel SET rating = rating + 1 WHERE id=%s;" % (article_rated)) db.commit() elif rating == '-1': connect.execute( "UPDATE artikel SET rating = rating - 1 WHERE id=%s;" % (article_rated)) db.commit() if 'usernameKonsument' in session or 'usernameProducent' in session: article.removeArticleTime() if 'usernameProducent' in session: if other.verifyProducent(session['telnrProducent']) == True: listArticle = article.presentArticleProducent( session['telnrProducent']) if request.method == 'POST': article.addArticle(session['telnrProducent']) listArticle = article.presentArticleProducent( session['telnrProducent']) return redirect(url_for('articles')) else: return render_template( "artiklar.html", listArticle=listArticle, checkIfEmpty=len(listArticle), username=session['usernameProducent']) else: return redirect(url_for('notVerified')) else: listArticle = article.presentArticleKonsument(category) return render_template("artiklar.html", listArticle=listArticle, checkIfEmpty=len(listArticle), username=session['usernameKonsument']) else: return redirect(url_for('login'))