示例#1
0
 def load_tournament_list(self):
     my_list = Tournament.load_all()
     for tournament in my_list:
         player_list = [
             Participant(participant['id'], participant['score'], set(participant['old_matchs']))
             for participant in tournament['players']
         ]
         round_list = self.round_controller.load_round(tournament['round_list'])
         tournoi = Tournament(
             tournament.doc_id,
             tournament['name'],
             tournament['start_date'],
             tournament['end_date'],
             tournament['location'],
             player_list,
             tournament['time_control'],
             tournament['max_turn']
         )
         tournoi.round_list = round_list
         tournoi.actual_turn = tournament['actual_turn']
         self.tournament_list.append(tournoi)
示例#2
0
 def create_new_tournament(self):
     while True:
         (
             t_name,
             t_location,
             t_start_date,
             t_end_date,
             t_max_turn,
             t_player_cnt,
             t_play_style
         ) = self.view.new_tournament()
         tournament_validator = TournamentForm(
             t_name, t_location,
             t_start_date, t_end_date,
             t_max_turn, t_player_cnt, t_play_style
         )
         if tournament_validator.is_valid():
             break
     tournoi = Tournament(
         len(self.tournament_list),
         t_name,
         t_start_date,
         t_end_date,
         t_location,
         [],
         t_play_style,
         int(t_max_turn)
     )
     while len(tournoi.players) < int(t_player_cnt):
         player = self.player_controller.get_player()
         if not tournoi.check_by_id(player.id):
             tournoi.players.append(Participant(player.id))
         else:
             print('Ce joueur est déja présent dans le tournoi')
     self.tournament_list.append(tournoi)
     return tournoi
示例#3
0
文件: pv.py 项目: sirzerator/spvm
 def __init__(self, db):
     self.db = db
     self.pv_hook = PV(db)
     self.point_hook = Point(db)
     self.participant_hook = Participant(db)
示例#4
0
文件: pv.py 项目: sirzerator/spvm
class PV_Controller:
    def __init__(self, db):
        self.db = db
        self.pv_hook = PV(db)
        self.point_hook = Point(db)
        self.participant_hook = Participant(db)

    ### New
    def get_new_pv(self):
        return template('pv/new',
                        title="New PV",
                        errors=dict(),
                        data=defaultdict(lambda: ''))

    get_new_pv.route = '/pv/new'
    get_new_pv.method = 'GET'

    def ajax_get_new_pv(self):
        return template('pv/new',
                        ajax=True,
                        title="New PV",
                        errors=dict(),
                        data=defaultdict(lambda: ''))

    ajax_get_new_pv.route = '/pv/ajax/new'
    ajax_get_new_pv.method = 'GET'

    def post_new_pv(self):
        fields = dict()
        fields['title'] = request.forms.title
        fields['date'] = request.forms.date
        fields['time'] = request.forms.time
        fields['location'] = request.forms.location
        fields['description'] = request.forms.description

        validation_result = self.pv_hook.create(fields)
        if isinstance(validation_result, dict):
            return template('pv/new',
                            title="New PV",
                            errors=validation_result,
                            data=request.forms)
        else:
            redirect('/')

    post_new_pv.route = '/pv/new'
    post_new_pv.method = 'POST'

    def ajax_post_new_pv(self):
        fields = dict()
        fields['title'] = request.forms.title
        fields['date'] = request.forms.date
        fields['time'] = request.forms.time
        fields['location'] = request.forms.location
        fields['description'] = request.forms.description

        validation_result = self.pv_hook.create(fields)
        if isinstance(validation_result, dict):
            return validation_result
        else:
            return {'id': validation_result}

    ajax_post_new_pv.route = '/pv/ajax/new'
    ajax_post_new_pv.method = 'POST'

    ### Edit
    def get_edit_pv(self, pv_id=None):
        data = self.pv_hook.retrieve_one(where={'id': pv_id})

        return template('pv/edit', title="New PV", data=data, errors=dict())

    get_edit_pv.route = '/pv/edit/<pv_id>'
    get_edit_pv.method = 'GET'

    def ajax_get_edit_pv(self):
        data = self.pv_hook.retrieve_one(where={'id': request.query.pv_id})

        return template('pv/edit',
                        ajax=True,
                        title="New PV",
                        data=data,
                        errors=dict())

    ajax_get_edit_pv.route = '/pv/ajax/edit'
    ajax_get_edit_pv.method = 'GET'

    def post_edit_pv(self):
        fields = dict()
        fields['id'] = request.forms.pv_id
        fields['title'] = request.forms.title
        fields['date'] = request.forms.date
        fields['time'] = request.forms.time
        fields['location'] = request.forms.location
        fields['description'] = request.forms.description

        validation_result = self.pv_hook.update(fields, {'id': fields['id']})

        if isinstance(validation_result, dict):
            return template('pv/edit', data=fields, errors=validation_result)
        else:
            redirect('/')

    post_edit_pv.route = '/pv/edit'
    post_edit_pv.method = 'POST'

    def ajax_post_edit_pv(self):
        fields = dict()
        fields['id'] = request.forms.pv_id
        fields['title'] = request.forms.title
        fields['date'] = request.forms.date
        fields['time'] = request.forms.time
        fields['location'] = request.forms.location
        fields['description'] = request.forms.description

        validation_result = self.pv_hook.update(fields, {'id': fields['id']})
        if isinstance(validation_result, dict):
            return validation_result
        else:
            return {'id': validation_result}

    ajax_post_edit_pv.route = '/pv/ajax/edit'
    ajax_post_edit_pv.method = 'POST'

    ### Delete
    def get_delete_pv(self, pv_id=None):
        if pv_id is None:
            redirect('/')
        else:
            return template('pv/delete', title="Delete PV", pv_id=pv_id)

    get_delete_pv.route = '/pv/delete/<pv_id>'
    get_delete_pv.method = 'GET'

    def ajax_get_delete_pv(self):
        pv_id = request.query.pv_id
        return template('pv/delete', ajax=True, title="Delete PV", pv_id=pv_id)

    ajax_get_delete_pv.route = '/pv/ajax/delete'
    ajax_get_delete_pv.method = 'GET'

    def post_delete_pv(self):
        pv_id = request.forms.pv_id
        if 'yes' not in request.forms or 'no' in request.forms or pv_id is None:
            redirect('/')
        else:
            if self.pv_hook.delete({'id': pv_id}):
                redirect('/')
            else:
                print('Error. Do something.')  # TODO

    post_delete_pv.route = '/pv/delete'
    post_delete_pv.method = 'POST'

    def ajax_post_delete_pv(self):
        pv_id = request.forms.pv_id
        print(pv_id)
        if pv_id is None:
            redirect('/')
        else:
            if self.pv_hook.delete({'id': pv_id}):
                redirect('/')
            else:
                print('Error. Do something.')  # TODO

    ajax_post_delete_pv.route = '/pv/ajax/delete'
    ajax_post_delete_pv.method = 'POST'

    ### Select
    def get_pv(self, pv_id=None):
        if pv_id is None:
            redirect('/')
        else:
            try:
                isinstance(int(pv_id), int)
            except ValueError:
                redirect('/')

            cookie_data = request.get_cookie('spvm', dict(), secret='secret')

            if not isinstance(cookie_data,
                              dict) and cookie_is_encoded(cookie_data):
                cookie_data = cookie_decode(cookie_data, 'key')

            cookie_data['pv_id'] = pv_id

            response.set_cookie('spvm',
                                cookie_encode(cookie_data, 'key'),
                                secret='secret',
                                path='/')

            pv_data = self.pv_hook.retrieve_one(where={'id': pv_id})

            points = self.point_hook.retrieve(where={
                'pv_id': pv_id,
                'parent_id': ''
            },
                                              order="rank ASC",
                                              recursion=3)

            participants = self.participant_hook.retrieve(
                where={'pv_id': pv_id})

            return template('main',
                            pv_id=pv_id,
                            pv_data=pv_data,
                            points=points,
                            participants=participants)

    get_pv.route = '/pv/<pv_id>'
    get_pv.method = 'GET'

    ### Unselect
    def close_pv(self):
        cookie_data = request.get_cookie('spvm', dict(), secret='secret')

        if not isinstance(cookie_data,
                          dict) and cookie_is_encoded(cookie_data):
            cookie_data = cookie_decode(cookie_data, 'key')

        cookie_data['pv_id'] = 0

        response.set_cookie('spvm',
                            cookie_encode(cookie_data, 'key'),
                            secret='secret',
                            path='/')

        redirect('/')

    close_pv.route = '/pv/close'
    close_pv.method = 'GET'

    ### Configure TODO
    def config_pv(self):
        redirect('/')

    config_pv.route = '/pv/config'
    config_pv.method = 'GET'
示例#5
0
 def __init__(self, db):
     self.db = db
     self.participant_hook = Participant(db)
示例#6
0
class Participant_Controller:
    def __init__(self, db):
        self.db = db
        self.participant_hook = Participant(db)

    # Utility
    def get_current_pv_id(self):
        cookie_data = request.get_cookie('spvm', dict(), secret='secret')

        if not isinstance(cookie_data,
                          dict) and cookie_is_encoded(cookie_data):
            cookie_data = cookie_decode(cookie_data, 'key')

        if 'pv_id' not in cookie_data or cookie_data['pv_id'] is None:
            redirect('/')

        return cookie_data['pv_id']

    ### New
    def get_new_participant(self):
        return template('participant/new',
                        title="New participant",
                        pv_id=self.get_current_pv_id(),
                        errors=dict(),
                        data=defaultdict(lambda: ''))

    get_new_participant.route = '/participant/new'
    get_new_participant.method = 'GET'

    def ajax_get_new_participant(self):
        return template('participant/new',
                        ajax=True,
                        title="New participant",
                        pv_id=self.get_current_pv_id(),
                        errors=dict(),
                        data=defaultdict(lambda: ''))

    ajax_get_new_participant.route = '/participant/ajax/new'
    ajax_get_new_participant.method = 'GET'

    def post_new_participant(self):
        fields = dict()
        fields['pv_id'] = request.forms.pv_id
        fields['full_name'] = request.forms.full_name

        validation_result = self.participant_hook.create(fields)

        if isinstance(validation_result, dict):
            return template('participant/new',
                            ajax=True,
                            title="New participant",
                            pv_id=self.get_current_pv_id(),
                            errors=dict(),
                            data=validation_result)
        else:
            redirect('/pv/' + fields['pv_id'])

    post_new_participant.route = '/participant/new'
    post_new_participant.method = 'POST'

    def ajax_post_new_participant(self):
        fields = dict()
        fields['pv_id'] = request.forms.pv_id
        fields['full_name'] = request.forms.full_name

        validation_result = self.participant_hook.create(fields)

        if isinstance(validation_result, dict):
            response.status = 400
            return validation_result
        else:
            return {'id': validation_result}

    ajax_post_new_participant.route = '/participant/ajax/new'
    ajax_post_new_participant.method = 'POST'

    ### Edit
    def get_edit_participant(self, participant_id=None):
        data = self.participant_hook.retrieve_one(where={'id': participant_id})

        return template('participant/edit',
                        title="Edit participant",
                        data=data,
                        errors=dict())

    get_edit_participant.route = '/participant/edit/<participant_id>'
    get_edit_participant.method = 'GET'

    def ajax_get_edit_participant(self):
        data = self.participant_hook.retrieve_one(
            where={'id': request.query.participant_id})

        return template('participant/edit',
                        ajax=True,
                        title="Edit participant",
                        data=data,
                        errors=dict())

    ajax_get_edit_participant.route = '/participant/ajax/edit'
    ajax_get_edit_participant.method = 'GET'

    def post_edit_participant(self):
        fields = dict()
        fields['id'] = request.forms.participant_id
        fields['pv_id'] = request.forms.pv_id
        fields['full_name'] = request.forms.full_name

        validation_result = self.participant_hook.update(
            fields, {'id': fields['id']})

        if isinstance(validation_result, dict):
            data = self.participant_hook.retrieve_one(
                where={'id': fields['id']})

            return template('participant/edit',
                            data=data,
                            errors=validation_result)
        else:
            redirect('/pv/' + fields['pv_id'])

    post_edit_participant.route = '/participant/edit'
    post_edit_participant.method = 'POST'

    def ajax_post_edit_participant(self):
        fields = dict()
        fields['id'] = request.forms.participant_id
        fields['pv_id'] = request.forms.pv_id
        fields['full_name'] = request.forms.full_name

        validation_result = self.participant_hook.update(
            fields, {'id': fields['id']})

        if isinstance(validation_result, dict):
            return validation_result
        else:
            return {'id': validation_result}

    ajax_post_edit_participant.route = '/participant/ajax/edit'
    ajax_post_edit_participant.method = 'POST'

    ### Delete
    def get_delete_participant(self, participant_id=None):
        if participant_id is None:
            redirect('/')
        else:
            return template('participant/delete',
                            title="Delete participant",
                            participant_id=participant_id)

    get_delete_participant.route = '/participant/delete/<participant_id>'
    get_delete_participant.method = 'GET'

    def ajax_get_delete_participant(self):
        participant_id = request.query.participant_id
        return template('participant/delete',
                        ajax=True,
                        title="Delete participant",
                        participant_id=participant_id)

    ajax_get_delete_participant.route = '/participant/ajax/delete'
    ajax_get_delete_participant.method = 'GET'

    def post_delete_participant(self):
        participant_id = request.forms.participant_id

        pv_id = self.participant_hook.retrieve_one(
            where={'id': participant_id})['pv_id']

        if 'yes' not in request.forms or 'no' in request.forms or participant_id is None:
            redirect('/pv/' + str(pv_id))
        else:
            if self.participant_hook.delete({'id': participant_id}):
                redirect('/pv/' + str(pv_id))
            else:
                print('Error. Do something.')  # TODO

    post_delete_participant.route = '/participant/delete'
    post_delete_participant.method = 'POST'

    def ajax_post_delete_participant(self):
        participant_id = request.forms.participant_id
        if participant_id is None:
            redirect('/')
        else:
            if self.participant_hook.delete({'id': participant_id}):
                redirect('/')
            else:
                print('Error. Do something.')  # TODO

    ajax_post_delete_participant.route = '/participant/ajax/delete'
    ajax_post_delete_participant.method = 'POST'
示例#7
0
    def __init__(self, db):
        self.service_hook = Participant(db)

        self.service_name = "participant"

        super(Participant_Service, self).__init__()
示例#8
0
	def __init__(self, db):
		self.db = db
		self.participant_hook = Participant(db)
示例#9
0
class Participant_Controller:
	def __init__(self, db):
		self.db = db
		self.participant_hook = Participant(db)

	# Utility
	def get_current_pv_id(self):
		cookie_data = request.get_cookie('spvm', dict(), secret='secret')

		if not isinstance(cookie_data, dict) and cookie_is_encoded(cookie_data):
			cookie_data = cookie_decode(cookie_data, 'key')

		if 'pv_id' not in cookie_data or cookie_data['pv_id'] is None:
			redirect('/')

		return cookie_data['pv_id']

	### New
	def get_new_participant(self):
		return template('participant/new', title="New participant", pv_id=self.get_current_pv_id(), errors=dict(), data=defaultdict(lambda:''))
	get_new_participant.route = '/participant/new'
	get_new_participant.method = 'GET'

	def ajax_get_new_participant(self):
		return template('participant/new', ajax=True, title="New participant", pv_id=self.get_current_pv_id(), errors=dict(), data=defaultdict(lambda:''))
	ajax_get_new_participant.route = '/participant/ajax/new'
	ajax_get_new_participant.method = 'GET'

	def post_new_participant(self):
		fields = dict()
		fields['pv_id'] = request.forms.pv_id
		fields['full_name'] = request.forms.full_name

		validation_result = self.participant_hook.create(fields)

		if isinstance(validation_result, dict):
			return template('participant/new', ajax=True, title="New participant", pv_id=self.get_current_pv_id(), errors=dict(), data=validation_result)
		else:
			redirect('/pv/'+fields['pv_id'])
	post_new_participant.route = '/participant/new'
	post_new_participant.method = 'POST'

	def ajax_post_new_participant(self):
		fields = dict()
		fields['pv_id'] = request.forms.pv_id
		fields['full_name'] = request.forms.full_name

		validation_result = self.participant_hook.create(fields)

		if isinstance(validation_result, dict):
			response.status = 400
			return validation_result
		else:
			return {'id': validation_result}
	ajax_post_new_participant.route = '/participant/ajax/new'
	ajax_post_new_participant.method = 'POST'

	### Edit
	def get_edit_participant(self, participant_id=None):
		data = self.participant_hook.retrieve_one(where={'id':participant_id})

		return template('participant/edit', title="Edit participant", data=data, errors=dict())
	get_edit_participant.route = '/participant/edit/<participant_id>'
	get_edit_participant.method = 'GET'

	def ajax_get_edit_participant(self):
		data = self.participant_hook.retrieve_one(where={'id':request.query.participant_id})

		return template('participant/edit', ajax=True, title="Edit participant", data=data, errors=dict())
	ajax_get_edit_participant.route = '/participant/ajax/edit'
	ajax_get_edit_participant.method = 'GET'

	def post_edit_participant(self):
		fields = dict()
		fields['id'] = request.forms.participant_id
		fields['pv_id'] = request.forms.pv_id
		fields['full_name'] = request.forms.full_name

		validation_result = self.participant_hook.update(fields, {'id': fields['id']})

		if isinstance(validation_result, dict):
			data = self.participant_hook.retrieve_one(where={'id':fields['id']})

			return template('participant/edit', data=data, errors=validation_result)
		else:
			redirect('/pv/'+fields['pv_id'])
	post_edit_participant.route = '/participant/edit'
	post_edit_participant.method = 'POST'

	def ajax_post_edit_participant(self):
		fields = dict()
		fields['id'] = request.forms.participant_id
		fields['pv_id'] = request.forms.pv_id
		fields['full_name'] = request.forms.full_name

		validation_result = self.participant_hook.update(fields, {'id': fields['id']})

		if isinstance(validation_result, dict):
			return validation_result
		else:
			return {'id': validation_result}
	ajax_post_edit_participant.route = '/participant/ajax/edit'
	ajax_post_edit_participant.method = 'POST'

	### Delete
	def get_delete_participant(self, participant_id=None):
		if participant_id is None:
			redirect('/')
		else:
			return template('participant/delete', title="Delete participant", participant_id=participant_id)
	get_delete_participant.route = '/participant/delete/<participant_id>'
	get_delete_participant.method = 'GET'

	def ajax_get_delete_participant(self):
		participant_id = request.query.participant_id
		return template('participant/delete', ajax=True, title="Delete participant", participant_id=participant_id)
	ajax_get_delete_participant.route = '/participant/ajax/delete'
	ajax_get_delete_participant.method = 'GET'

	def post_delete_participant(self):
		participant_id = request.forms.participant_id

		pv_id = self.participant_hook.retrieve_one(where={'id':participant_id})['pv_id']

		if 'yes' not in request.forms or 'no' in request.forms or participant_id is None:
			redirect('/pv/' + str(pv_id))
		else:
			if self.participant_hook.delete({'id':participant_id}):
				redirect('/pv/' + str(pv_id))
			else:
				print('Error. Do something.') # TODO
	post_delete_participant.route = '/participant/delete'
	post_delete_participant.method = 'POST'

	def ajax_post_delete_participant(self):
		participant_id = request.forms.participant_id
		if participant_id is None:
			redirect('/')
		else:
			if self.participant_hook.delete({'id':participant_id}):
				redirect('/')
			else:
				print('Error. Do something.') # TODO
	ajax_post_delete_participant.route = '/participant/ajax/delete'
	ajax_post_delete_participant.method = 'POST'
 def post( self ):
     new_participant = Participant( name=request.json[ 'name' ] )
     db.session.add( new_participant )
     db.session.commit()
     return participant_schema.dump( new_participant )
示例#11
0
文件: pv.py 项目: sirzerator/spvm
	def __init__(self, db):
		self.db = db
		self.pv_hook = PV(db)
		self.point_hook = Point(db)
		self.participant_hook = Participant(db)
示例#12
0
文件: pv.py 项目: sirzerator/spvm
class PV_Controller:
	def __init__(self, db):
		self.db = db
		self.pv_hook = PV(db)
		self.point_hook = Point(db)
		self.participant_hook = Participant(db)

	### New
	def get_new_pv(self):
		return template('pv/new', title="New PV", errors=dict(), data=defaultdict(lambda:''))
	get_new_pv.route = '/pv/new'
	get_new_pv.method = 'GET'

	def ajax_get_new_pv(self):
		return template('pv/new', ajax=True, title="New PV", errors=dict(), data=defaultdict(lambda:''))
	ajax_get_new_pv.route = '/pv/ajax/new'
	ajax_get_new_pv.method = 'GET'

	def post_new_pv(self):
		fields = dict()
		fields['title'] = request.forms.title
		fields['date'] = request.forms.date
		fields['time'] = request.forms.time
		fields['location'] = request.forms.location
		fields['description'] = request.forms.description

		validation_result = self.pv_hook.create(fields)
		if isinstance(validation_result, dict):
			return template('pv/new', title="New PV", errors=validation_result, data=request.forms)
		else:
			redirect('/')
	post_new_pv.route = '/pv/new'
	post_new_pv.method = 'POST'

	def ajax_post_new_pv(self):
		fields = dict()
		fields['title'] = request.forms.title
		fields['date'] = request.forms.date
		fields['time'] = request.forms.time
		fields['location'] = request.forms.location
		fields['description'] = request.forms.description

		validation_result = self.pv_hook.create(fields)
		if isinstance(validation_result, dict):
			return validation_result
		else:
			return {'id': validation_result}
	ajax_post_new_pv.route = '/pv/ajax/new'
	ajax_post_new_pv.method = 'POST'

	### Edit
	def get_edit_pv(self, pv_id=None):
		data = self.pv_hook.retrieve_one(where={'id':pv_id})

		return template('pv/edit', title="New PV", data=data, errors=dict())
	get_edit_pv.route = '/pv/edit/<pv_id>'
	get_edit_pv.method = 'GET'

	def ajax_get_edit_pv(self):
		data = self.pv_hook.retrieve_one(where={'id':request.query.pv_id})

		return template('pv/edit', ajax=True, title="New PV", data=data, errors=dict())
	ajax_get_edit_pv.route = '/pv/ajax/edit'
	ajax_get_edit_pv.method = 'GET'

	def post_edit_pv(self):
		fields = dict()
		fields['id'] = request.forms.pv_id
		fields['title'] = request.forms.title
		fields['date'] = request.forms.date
		fields['time'] = request.forms.time
		fields['location'] = request.forms.location
		fields['description'] = request.forms.description

		validation_result = self.pv_hook.update(fields, {'id': fields['id']})

		if isinstance(validation_result, dict):
			return template('pv/edit', data=fields, errors=validation_result)
		else:
			redirect('/')
	post_edit_pv.route = '/pv/edit'
	post_edit_pv.method = 'POST'

	def ajax_post_edit_pv(self):
		fields = dict()
		fields['id'] = request.forms.pv_id
		fields['title'] = request.forms.title
		fields['date'] = request.forms.date
		fields['time'] = request.forms.time
		fields['location'] = request.forms.location
		fields['description'] = request.forms.description

		validation_result = self.pv_hook.update(fields, {'id': fields['id']})
		if isinstance(validation_result, dict):
			return validation_result
		else:
			return {'id': validation_result}
	ajax_post_edit_pv.route = '/pv/ajax/edit'
	ajax_post_edit_pv.method = 'POST'

	### Delete
	def get_delete_pv(self, pv_id=None):
		if pv_id is None:
			redirect('/')
		else:
			return template('pv/delete', title="Delete PV", pv_id=pv_id)
	get_delete_pv.route = '/pv/delete/<pv_id>'
	get_delete_pv.method = 'GET'

	def ajax_get_delete_pv(self):
		pv_id = request.query.pv_id
		return template('pv/delete', ajax=True, title="Delete PV", pv_id=pv_id)
	ajax_get_delete_pv.route = '/pv/ajax/delete'
	ajax_get_delete_pv.method = 'GET'

	def post_delete_pv(self):
		pv_id = request.forms.pv_id
		if 'yes' not in request.forms or 'no' in request.forms or pv_id is None:
			redirect('/')
		else:
			if self.pv_hook.delete({'id':pv_id}):
				redirect('/')
			else:
				print('Error. Do something.') # TODO
	post_delete_pv.route = '/pv/delete'
	post_delete_pv.method = 'POST'

	def ajax_post_delete_pv(self):
		pv_id = request.forms.pv_id
		print(pv_id)
		if pv_id is None:
			redirect('/')
		else:
			if self.pv_hook.delete({'id':pv_id}):
				redirect('/')
			else:
				print('Error. Do something.') # TODO
	ajax_post_delete_pv.route = '/pv/ajax/delete'
	ajax_post_delete_pv.method = 'POST'

	### Select
	def get_pv(self, pv_id=None):
		if pv_id is None:
			redirect('/')
		else:
			try:
				isinstance(int(pv_id), int)
			except ValueError:
				redirect('/')

			cookie_data = request.get_cookie('spvm', dict(), secret='secret')

			if not isinstance(cookie_data, dict) and cookie_is_encoded(cookie_data):
				cookie_data = cookie_decode(cookie_data, 'key')

			cookie_data['pv_id'] = pv_id

			response.set_cookie('spvm', cookie_encode(cookie_data, 'key'), secret='secret', path='/')

			pv_data = self.pv_hook.retrieve_one(where={'id':pv_id})

			points = self.point_hook.retrieve(where={'pv_id':pv_id, 'parent_id':''}, order="rank ASC", recursion=3)

			participants = self.participant_hook.retrieve(where={'pv_id':pv_id})

			return template('main', pv_id=pv_id, pv_data=pv_data, points=points, participants=participants)
	get_pv.route = '/pv/<pv_id>'
	get_pv.method = 'GET'

	### Unselect
	def close_pv(self):
		cookie_data = request.get_cookie('spvm', dict(), secret='secret')

		if not isinstance(cookie_data, dict) and cookie_is_encoded(cookie_data):
			cookie_data = cookie_decode(cookie_data, 'key')

		cookie_data['pv_id'] = 0

		response.set_cookie('spvm', cookie_encode(cookie_data, 'key'), secret='secret', path='/')

		redirect('/')
	close_pv.route = '/pv/close'
	close_pv.method = 'GET'

	### Configure TODO
	def config_pv(self):
		redirect('/')
	config_pv.route = '/pv/config'
	config_pv.method = 'GET'
示例#13
0
try:
    db_module = __import__('database.' + options.db_module,
                           fromlist=['database'])
except ImportError:
    print('DB Error.')
    exit(1)

# Connecting to database
db_hook = db_module.DBModule(options.database, options.username,
                             options.password)

# Loading models
pv_hook = PV(db_hook)
point_hook = Point(db_hook)
proposition_hook = Proposition(db_hook)
participant_hook = Participant(db_hook)

# Building tables
pv_hook.create_table()
point_hook.create_table()
proposition_hook.create_table()
participant_hook.create_table()


def setup_routes(obj):
    for kw in dir(obj):
        attr = getattr(obj, kw)
        if hasattr(attr, 'route'):
            if hasattr(attr, 'method'):
                print('routing ' + str(attr) + ' with ' + attr.route + ', ' +
                      attr.method)
示例#14
0
文件: spvm.py 项目: sirzerator/spvm
# Loading database
try:
	db_module = __import__('database.' + options.db_module, fromlist=['database'])
except ImportError:
	print('DB Error.')
	exit(1)

# Connecting to database
db_hook = db_module.DBModule(options.database, options.username, options.password)

# Loading models
pv_hook = PV(db_hook)
point_hook = Point(db_hook)
proposition_hook = Proposition(db_hook)
participant_hook = Participant(db_hook)

# Building tables
pv_hook.create_table()
point_hook.create_table()
proposition_hook.create_table()
participant_hook.create_table()

def setup_routes(obj):
	for kw in dir(obj):
		attr = getattr(obj, kw)
		if hasattr(attr, 'route'):
			if hasattr(attr, 'method'):
				print('routing ' + str(attr) + ' with ' + attr.route + ', ' + attr.method)
				bottle.route(attr.route, attr.method)(attr)
			else: