Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3
- # -*- coding: utf-8 -*-
- #
- from flask import Flask, request
- from flask_restful import Resource, Api
- from flask.ext.jsonpify import jsonify
- from flask_httpauth import HTTPBasicAuth
- __all__ = ['API']
- auth = HTTPBasicAuth()
- class API:
- def __init__(self, db, config):
- self.db = db
- self.config = config
- self.app = Flask('election-core')
- self.api = Api(self.app, prefix='/api')
- self.api.add_resource(self.Status, '/')
- self.api.add_resource(self.Poll, '/polls/<poll_id>')
- self.api.add_resource(self.NewPoll, '/polls')
- @auth.verify_password
- def checkLoginCredentials(self, username, password):
- return(username == 'username' and password == 'password')
- class Poll(Resource):
- @auth.login_required
- def get(s, poll_id):
- # get information
- data = {}
- data['name'] = 'Abstimmung xyz'
- data['choices'] = ['Ja', 'Nein', 'Vielleicht']
- data['maxSelect'] = 1
- data['minSelect'] = 1
- # prepared=you can see it, but the poll is not open
- # open=you can vote
- # closed=you cant vote anymore, result is hidden
- # finished=you cant vote anymore, result is published
- data['state'] = 'open'
- return(jsonify(data))
- def patch(s, poll_id):
- # edit preferences, close election, ...
- pass
- def post(s, poll_id):
- # vote
- pass
- class NewPoll(Resource):
- def get(s):
- # create new poll
- pass
- class Status(Resource):
- def get(s):
- return(jsonify({'status': 'OK'}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement