Skip to content

Commit

Permalink
Merge pull request #4 from vasu-gupta/master
Browse files Browse the repository at this point in the history
from Team no-08 Bits_please
  • Loading branch information
kroy96 authored Dec 23, 2019
2 parents 3b03231 + 815d1c5 commit 325b52f
Show file tree
Hide file tree
Showing 37 changed files with 848 additions and 0 deletions.
Binary file added Bits_please/Bits_please.pptx
Binary file not shown.
Binary file added Bits_please/Bits_please.txt.docx
Binary file not shown.
2 changes: 2 additions & 0 deletions Bits_please/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Get-Testers
A Portal for beta testers to test new apps. A portal for new apps to get beta testers
15 changes: 15 additions & 0 deletions Bits_please/gettesters/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_bcrypt import Bcrypt
from flask_login import LoginManager

app = Flask(__name__)
app.config['SECRET_KEY'] = '5791628bb0b13ce0c676dfde280ba245'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'
db = SQLAlchemy(app)
bcrypt = Bcrypt(app)
login_manager = LoginManager(app)
login_manager.login_view = 'login'
login_manager.login_message_category = 'info'

from gettesters import routes
1 change: 1 addition & 0 deletions Bits_please/gettesters/__pycache__/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
68 changes: 68 additions & 0 deletions Bits_please/gettesters/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from flask_login import current_user
from wtforms import StringField, PasswordField, SubmitField, BooleanField, TextAreaField
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError
from gettesters.models import User


class RegistrationForm(FlaskForm):
username = StringField('Username',
validators=[DataRequired(), Length(min=2, max=20)])
email = StringField('Email',
validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
confirm_password = PasswordField('Confirm Password',
validators=[DataRequired(), EqualTo('password')])
skills = StringField('Skills')
submit = SubmitField('Sign Up')

def validate_username(self, username):
user = User.query.filter_by(username=username.data).first()
if user:
raise ValidationError('That username is taken. Please choose a different one.')

def validate_email(self, email):
user = User.query.filter_by(email=email.data).first()
if user:
raise ValidationError('That email is taken. Please choose a different one.')


class LoginForm(FlaskForm):
email = StringField('Email',
validators=[DataRequired(), Email()])
password = PasswordField('Password', validators=[DataRequired()])
remember = BooleanField('Remember Me')
submit = SubmitField('Login')


class UpdateAccountForm(FlaskForm):
username = StringField('Username',
validators=[DataRequired(), Length(min=2, max=20)])
email = StringField('Email',
validators=[DataRequired(), Email()])
picture = FileField('Update Profile Picture', validators=[FileAllowed(['jpg', 'png'])])
skills = StringField('Skills')
submit = SubmitField('Update')

def validate_username(self, username):
if username.data != current_user.username:
user = User.query.filter_by(username=username.data).first()
if user:
raise ValidationError('That username is taken. Please choose a different one.')

def validate_email(self, email):
if email.data != current_user.email:
user = User.query.filter_by(email=email.data).first()
if user:
raise ValidationError('That email is taken. Please choose a different one.')


class PostForm(FlaskForm):
title = StringField('Title', validators=[DataRequired()])
content = TextAreaField('Content', validators=[DataRequired()])
link1 = StringField('Product/App Link')
link2 = StringField('Company Website Link')
skills = StringField('Skills')
author = StringField('Your Email Address')
submit = SubmitField('Post')
9 changes: 9 additions & 0 deletions Bits_please/gettesters/loadd.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import pickle


with open("wordvecpickleslash.pickle", 'rb') as f:
word_vec = pickle.load(f, encoding="latin1")
for i in range(100):
x = input("Enter a word")
print(word_vec[x])
print(word_vec.most_similar(x))
35 changes: 35 additions & 0 deletions Bits_please/gettesters/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from datetime import datetime
from gettesters import db, login_manager
from flask_login import UserMixin


@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))


class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), unique=True, nullable=False)
email = db.Column(db.String(120), unique=True, nullable=False)
image_file = db.Column(db.String(20), nullable=False, default='default.jpg')
password = db.Column(db.String(60), nullable=False)
skills = db.Column(db.String())
# posts = db.relationship('Post', backref='author', lazy=True)

def __repr__(self):
return f"User('{self.username}', '{self.email}', '{self.image_file}')"


class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
date_posted = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
content = db.Column(db.Text, nullable=False)
link1 = db.Column(db.String())
link2 = db.Column(db.String())
skills = db.Column(db.String())
author = db.Column(db.String())

def __repr__(self):
return f"Post('{self.title}', '{self.date_posted}')"
171 changes: 171 additions & 0 deletions Bits_please/gettesters/routes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
import os
import secrets
from PIL import Image
from flask import render_template, url_for, flash, redirect, request, abort
from gettesters import app, db, bcrypt
from gettesters.forms import RegistrationForm, LoginForm, UpdateAccountForm, PostForm
from gettesters.models import User, Post
from flask_login import login_user, current_user, logout_user, login_required
import pickle

@app.route("/")
@app.route("/home")
def home():
if current_user.is_authenticated:
kl = current_user.skills
kl = kl.replace(" ","").lower()
listOfUser = list(kl.split(","))
with open("wordvecpickleslash.pickle", 'rb') as f:
word_vec = pickle.load(f, encoding="latin1")
final = listOfUser
for x in listOfUser:
res_list = [i[0] for i in word_vec.most_similar(x)[0:5]]
final = final + res_list
final = final[0:15]
# print(final)
# posts = Post.query.filter(Post.skills.contains('data'))
for i in final:
# print(Post.query.filter(Post.skills.contains("web-services")))
if Post.query.filter(Post.skills.contains(i)).first() is not None:
posts = Post.query.filter(Post.skills.contains(i))
break

# posts = Post.query.filter(Post.skills.in_(final))
# print(Post.query.filter(Post.skills.in_(final)))
else:
posts = Post.query.all()
return render_template('home.html', posts=posts)




@app.route("/register", methods=['GET', 'POST'])
def register():
if current_user.is_authenticated:
return redirect(url_for('home'))
form = RegistrationForm()
if form.validate_on_submit():
hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
user = User(username=form.username.data, email=form.email.data, password=hashed_password, skills = form.skills.data)
db.session.add(user)
db.session.commit()
flash('Your account has been created! You are now able to log in', 'success')
return redirect(url_for('login'))
return render_template('register.html', title='Register', form=form)


@app.route("/login", methods=['GET', 'POST'])
def login():
if current_user.is_authenticated:
return redirect(url_for('home'))
form = LoginForm()
if form.validate_on_submit():
user = User.query.filter_by(email=form.email.data).first()
if user and bcrypt.check_password_hash(user.password, form.password.data):
login_user(user, remember=form.remember.data)
next_page = request.args.get('next')
return redirect(next_page) if next_page else redirect(url_for('home'))
else:
flash('Login Unsuccessful. Please check email and password', 'danger')
return render_template('login.html', title='Login', form=form)


@app.route("/logout")
def logout():
logout_user()
return redirect(url_for('home'))


def save_picture(form_picture):
random_hex = secrets.token_hex(8)
_, f_ext = os.path.splitext(form_picture.filename)
picture_fn = random_hex + f_ext
picture_path = os.path.join(app.root_path, 'static/profile_pics', picture_fn)

output_size = (125, 125)
i = Image.open(form_picture)
i.thumbnail(output_size)
i.save(picture_path)

return picture_fn


@app.route("/account", methods=['GET', 'POST'])
@login_required
def account():
form = UpdateAccountForm()
if form.validate_on_submit():
if form.picture.data:
picture_file = save_picture(form.picture.data)
current_user.image_file = picture_file
current_user.username = form.username.data
current_user.email = form.email.data
current_user.skills = form.skills.data
db.session.commit()
flash('Your account has been updated!', 'success')
return redirect(url_for('account'))
elif request.method == 'GET':
form.username.data = current_user.username
form.email.data = current_user.email
form.skills.data = current_user.skills
image_file = url_for('static', filename='profile_pics/' + current_user.image_file)
return render_template('account.html', title='Account',
image_file=image_file, form=form)


@app.route("/post/new", methods=['GET', 'POST'])
# @login_required
def new_post():
form = PostForm()
if form.validate_on_submit():
post = Post(title=form.title.data, link1 =form.link1.data, link2 = form.link2.data, skills = form.skills.data.lower().replace(" ",""), content=form.content.data, author = form.author.data)
db.session.add(post)
db.session.commit()
flash('Your post has been created!', 'success')
return redirect(url_for('home'))
return render_template('create_post.html', title='New Post',
form=form, legend='New Product Listing')


@app.route("/post/<int:post_id>")
def post(post_id):
post = Post.query.get_or_404(post_id)
return render_template('post.html', title=post.title, post=post, link1 = post.link1, link2= post.link2, author = post.author)


@app.route("/post/<int:post_id>/update", methods=['GET', 'POST'])
@login_required
def update_post(post_id):
post = Post.query.get_or_404(post_id)
if post.author != current_user:
abort(403)
form = PostForm()
if form.validate_on_submit():
post.title = form.title.data
post.content = form.content.data
post.link1 = form.link1.data
post.link2 = form.link2.data
post.skills = form.skills.data
db.session.commit()
flash('Your post has been updated!', 'success')
return redirect(url_for('post', post_id=post.id))
elif request.method == 'GET':
form.title.data = post.title
form.content.data = post.content
form.link1.data = post.link1
form.link2.data = post.link2
form.skills.data = post.skills
return render_template('create_post.html', title='Update Product',
form=form, legend='Update Product')


@app.route("/post/<int:post_id>/delete", methods=['POST'])
@login_required
def delete_post(post_id):
post = Post.query.get_or_404(post_id)
if post.author != current_user:
abort(403)
db.session.delete(post)
db.session.commit()
flash('Your post has been deleted!', 'success')
return redirect(url_for('home'))
Binary file added Bits_please/gettesters/site.db
Binary file not shown.
80 changes: 80 additions & 0 deletions Bits_please/gettesters/static/main.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
body {
background: #fafafa;
color: #333333;
margin-top: 5rem;
}

h1, h2, h3, h4, h5, h6 {
color: #444444;
}

.bg-steel {
background-color: #5f788a;
}

.site-header .navbar-nav .nav-link {
color: #cbd5db;
}

.site-header .navbar-nav .nav-link:hover {
color: #ffffff;
}

.site-header .navbar-nav .nav-link.active {
font-weight: 500;
}

.content-section {
background: #ffffff;
padding: 10px 20px;
border: 1px solid #dddddd;
border-radius: 3px;
margin-bottom: 20px;
}

.article-title {
color: #444444;
}

a.article-title:hover {
color: #428bca;
text-decoration: none;
}

.article-content {
white-space: pre-line;
}

.article-img {
height: 65px;
width: 65px;
margin-right: 16px;
}

.article-metadata {
padding-bottom: 1px;
margin-bottom: 4px;
border-bottom: 1px solid #e3e3e3
}

.article-metadata a:hover {
color: #333;
text-decoration: none;
}

.article-svg {
width: 25px;
height: 25px;
vertical-align: middle;
}

.account-img {
height: 125px;
width: 125px;
margin-right: 20px;
margin-bottom: 16px;
}

.account-heading {
font-size: 2.5rem;
}
1 change: 1 addition & 0 deletions Bits_please/gettesters/static/profile_pics/.gitkeep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Bits_please/gettesters/templates/about.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{% extends "layout.html" %}
{% block content %}
<h1>About Page</h1>
{% endblock content %}
Loading

0 comments on commit 325b52f

Please sign in to comment.