Skip to content
Open

Test #21

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .coafile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Python]
files = *.py, app/*.py
language = Python
bears = QuotesBear, PEP8Bear
bears = QuotesBear
preferred_quotation = '
default_actions = *: ApplyPatchAction
max_line_length = 249
max_line_length = 249
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/static/* linguist-vendored
**/templates/* linguist-vendored
10 changes: 10 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
language: python
python:
- 3.6
install:
- pip install coala
- pip install coala-bears
script:
- echo "Running Tests"
- echo "Running coala"
- coala --non-interactive
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Polling Application

![Generic badge](https://img.shields.io/badge/build-success-green.svg?longCache=true&style=flat-square)

This is a simple Polling Application in which a user can create polls and vote.

*Features of Application :-
## Features of Application :-

1. Create user.
2. Login User
3. Create a Poll
4. Vote to Current Polls

*Tec
36 changes: 18 additions & 18 deletions app/firebase_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
messagingSenderId = os.environ.get('messagingSenderId')

config={
"apiKey": apiKey,
"authDomain": authDomain,
"databaseURL": databaseURL,
"projectId": projectId,
"storageBucket": storageBucket,
"messagingSenderId": messagingSenderId
'apiKey': apiKey,
'authDomain': authDomain,
'databaseURL': databaseURL,
'projectId': projectId,
'storageBucket': storageBucket,
'messagingSenderId': messagingSenderId
}

firebase = pyrebase.initialize_app(config)
Expand All @@ -24,21 +24,21 @@

class Add_Poll:
def add_poll(self, poll_data, group):
db.child("polls-data").child("group").child(group).push(poll_data)
return "Done"
db.child('polls-data').child('group').child(group).push(poll_data)
return 'Done'

class Get_Polls:
def get_poll_by_group(self, group):
get_polls=db.child("polls-data").child("group").child(group).get()
get_polls=db.child('polls-data').child('group').child(group).get()
return get_polls.val()

class SignUp:
def signup_user(self, email, password, user_name, user_group):
user = auth.create_user_with_email_and_password(email, password)
data = {"email": email,"group":user_group}
member = {"user_name" : user_name}
results = db.child("users").child(user_name).set(data, user['idToken'])
db.child("polls-data").child("group").child(user_group).child("members").push(member)
data = {'email': email,'group':user_group}
member = {'user_name' : user_name}
results = db.child('users').child(user_name).set(data, user['idToken'])
db.child('polls-data').child('group').child(user_group).child('members').push(member)

class SignIn:
def signin_user(self, email, password):
Expand All @@ -47,17 +47,17 @@ def signin_user(self, email, password):

class Poll_Vote:
def submit_vote(self, choice_no, poll_id,group,user_name):
get_choice=db.child("polls-data").child("group").child(group).child(poll_id).child('choices').get()
get_choice=db.child('polls-data').child('group').child(group).child(poll_id).child('choices').get()
current_votes=get_choice.val()[int(choice_no)]['votes']
updated_votes=current_votes+1
user_polls=db.child("users").child(user_name).child("prev-polls").push({"id":poll_id})
res=db.child("polls-data").child("group").child(group).child(poll_id).child('choices').child(choice_no).child('votes').set(updated_votes)
user_polls=db.child('users').child(user_name).child('prev-polls').push({'id':poll_id})
res=db.child('polls-data').child('group').child(group).child(poll_id).child('choices').child(choice_no).child('votes').set(updated_votes)
return res

class Prev_Polls:
def get_previous_polls(self, user_name):
user_polls_array=[]
user_polls=db.child("users").child(user_name).child("prev-polls").get()
user_polls=db.child('users').child(user_name).child('prev-polls').get()
user_polls=user_polls.val()
try:
user_polls_array=[user_polls[poll]['id'] for poll in user_polls]
Expand All @@ -67,7 +67,7 @@ def get_previous_polls(self, user_name):

class Get_Members:
def get_group_members(self, user_name, group):
get_members=db.child("polls-data").child("group").child(group).child("members").get()
get_members=db.child('polls-data').child('group').child(group).child('members').get()
group_members=get_members.val()
res=[group_members[a]['user_name'] for a in group_members]
return res
8 changes: 4 additions & 4 deletions app/form_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ def group1():
ques=request.form['question_g1']
i=0
for choice in user_data.keys():
choice_dict={"number":i,"string":user_data[choice], "votes":0}
choice_dict={'number':i,'string':user_data[choice], 'votes':0}
if not choice=='question_g1':
choice_array.append(choice_dict)
i+=1
choice_array={"question":ques,"choices":choice_array}
choice_array={'question':ques,'choices':choice_array}
g1=Add_Poll()
g1.add_poll(choice_array,session['group'])
return json.dumps({'status':'OK'})
Expand All @@ -32,11 +32,11 @@ def fbsignup():

@app.route('/login', methods=['POST'])
def login():
error_msg="Wrong Email/Password"
error_msg='Wrong Email/Password'
user_login=request.form
user_name=user_login['username']
passwd=user_login['password']
user=db.child("users").child(user_name).get()
user=db.child('users').child(user_name).get()
try:
email=user.val()['email']
group=user.val()['group']
Expand Down