Advertisement
Guest User

Untitled

a guest
Mar 12th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. #! /usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. #
  4. from flask import Flask, request
  5. from flask_restful import Resource, Api
  6. from flask.ext.jsonpify import jsonify
  7. from flask_httpauth import HTTPBasicAuth
  8.  
  9. __all__ = ['API']
  10.  
  11. auth = HTTPBasicAuth()
  12.  
  13. class API:
  14.     def __init__(self, db, config):
  15.         self.db = db
  16.         self.config = config
  17.         self.app = Flask('election-core')
  18.         self.api = Api(self.app, prefix='/api')
  19.         self.api.add_resource(self.Status, '/')
  20.         self.api.add_resource(self.Poll, '/polls/<poll_id>')
  21.         self.api.add_resource(self.NewPoll, '/polls')
  22.  
  23.     @auth.verify_password
  24.     def checkLoginCredentials(self, username, password):
  25.         return(username == 'username' and password == 'password')
  26.  
  27.     class Poll(Resource):
  28.         @auth.login_required
  29.         def get(s, poll_id):
  30.             # get information
  31.             data = {}
  32.             data['name'] = 'Abstimmung xyz'
  33.             data['choices'] = ['Ja', 'Nein', 'Vielleicht']
  34.             data['maxSelect'] = 1
  35.             data['minSelect'] = 1
  36.             # prepared=you can see it, but the poll is not open
  37.             # open=you can vote
  38.             # closed=you cant vote anymore, result is hidden
  39.             # finished=you cant vote anymore, result is published
  40.             data['state'] = 'open'
  41.             return(jsonify(data))
  42.  
  43.         def patch(s, poll_id):
  44.             # edit preferences, close election, ...
  45.             pass
  46.  
  47.         def post(s, poll_id):
  48.             # vote
  49.             pass
  50.  
  51.     class NewPoll(Resource):
  52.         def get(s):
  53.             # create new poll
  54.             pass
  55.  
  56.     class Status(Resource):
  57.         def get(s):
  58.             return(jsonify({'status': 'OK'}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement