def drop_users(): print "Dropping" User.objects().delete() SongRoom.objects().delete() Song.objects().delete() SongQueue.objects().delete() Vote.objects().delete() return "OK"
def post(): values = {} vote_value = request.form['vote'] vote = Vote() for item in request.form.getlist('value[]'): if vote.get_vote_title(item) is not None: values[item] = vote.get_vote_title(item) elif int(item) == Vote.CUSTOM_VOTE_ID and vote_value: values[item] = vote_value if values: # add vote vote.ip = request.remote_addr vote.votes = values try: vote_current = Vote.objects(ip=request.remote_addr, created_at__gte=(datetime.datetime.now() - datetime.timedelta(minutes=15))) if vote_current: raise ValueError("You've already voted!") vote.save() suffix = VoteView.ordinal(len(Vote.objects)) return jsonify({'status': 'ok', 'message': 'Thank your for voting! You are the %s fan of python' % suffix}) except ValueError as e: return jsonify({'status': 'error', 'message': e.message}) except Exception: return jsonify({'status': 'error', 'message': 'Error while saving vote. Sorry :('}) else: return jsonify({'status': 'error', 'message': 'Choose any option to vote'})
def total_voted_last_month(): """ Get total number of people voted for last 31 days :return: int """ return len( Vote.objects(created_at__gte=(datetime.datetime.now() - datetime.timedelta(days=31))))
def post(): values = {} vote_value = request.form['vote'] vote = Vote() for item in request.form.getlist('value[]'): if vote.get_vote_title(item) is not None: values[item] = vote.get_vote_title(item) elif int(item) == Vote.CUSTOM_VOTE_ID and vote_value: values[item] = vote_value if values: # add vote vote.ip = request.remote_addr vote.votes = values try: vote_current = Vote.objects( ip=request.remote_addr, created_at__gte=(datetime.datetime.now() - datetime.timedelta(minutes=15))) if vote_current: raise ValueError("You've already voted!") vote.save() suffix = VoteView.ordinal(len(Vote.objects)) return jsonify({ 'status': 'ok', 'message': 'Thank your for voting! You are the %s fan of python' % suffix }) except ValueError as e: return jsonify({'status': 'error', 'message': e.message}) except Exception: return jsonify({ 'status': 'error', 'message': 'Error while saving vote. Sorry :(' }) else: return jsonify({ 'status': 'error', 'message': 'Choose any option to vote' })
def total_voted_last_month(): """ Get total number of people voted for last 31 days :return: int """ return len(Vote.objects(created_at__gte=(datetime.datetime.now() - datetime.timedelta(days=31))))