def __init__(self): super(MainWindows, self).__init__() uic.loadUi( r'C:\Users\Acer\Documents\MEGA\Desenvolvimentos\villagebot\views\mainwindows.ui', self) self.thread_login = ConnectAccount(self) self.model = Village() self.current_village = None # Customização da ComboBox com nomes das Aldeias self.model_list_village = ListOfVillages() self.cb_list_village.setModel(self.model_list_village) # Customização da tabela contendo so campos de recursos self.model_resource_fields = TableOfResourceFields() self.model_resource_fields.setHorizontalHeaderLabels( ['ID', 'Campo', 'Nivel']) self.table_fields.setModel(self.model_resource_fields) # Customização da tabela contendo os campos de construção self.model_construction_fields = TableOfConstructionFields() self.model_construction_fields.setHorizontalHeaderLabels( ['ID', 'Campo', 'Nivel']) self.table_village.setModel(self.model_construction_fields) # Customização da tabela contendo os campos em construção self.model_fields_in_construction = TableFieldsInCOnstruction() self.model_fields_in_construction.setHorizontalHeaderLabels( ['ID', 'Campo', 'Nivel']) self.table_queue.setModel(self.model_fields_in_construction) # Inicializar console self.console_text.append("[14:57:00] -> Seja bem vindo ao BotVillage") self.console_text.setReadOnly(True) customize_tables(self.table_fields) customize_tables(self.table_village) customize_tables(self.table_queue) customize_tables(self.table_building_ordens, 270) # Customizações gerais self.lb_msg.setStyleSheet('color: red') self.tabs.setTabEnabled(1, False) # Setando texto para testes self.le_server.setText("ts2.lusobrasileiro.travian.com") self.le_user.setText("dionialves") self.le_pass.setText("alves625") # Conexões dos botoes self.bt_logar.clicked.connect(self.btn_clicked_login) self.cb_list_village.currentIndexChanged.connect( self.update_tables_on_click) self.update_button.clicked.connect(self.update_button_clicked) self.table_fields.clicked.connect( self.update_name_of_next_building_from_table_fields) self.table_village.clicked.connect( self.update_name_of_next_building_from_table_village)
def create_village(self, user): village = Village() village.name = self.fake.text(max_nb_chars=20) if random.random() > 0.5: village.location = fake_location() db.session.add(village) reqs = VillageRequirements() reqs.village = village reqs.num_attendees = random.randint(2, 100) db.session.add(reqs) membership = VillageMember() membership.user = user membership.village = village membership.admin = True db.session.add(membership)
def register(): if current_user.village and current_user.village.admin: return redirect( url_for(".edit", year=event_year(), village_id=current_user.village.village.id)) form = VillageForm() if form.validate_on_submit(): if Village.get_by_name(form.name.data): flash( "A village already exists with that name, please choose another" ) return redirect(url_for(".register")) village = Village(name=form.name.data, description=form.description.data) member = VillageMember(village=village, user=current_user, admin=True) requirements = VillageRequirements( village=village, num_attendees=form.num_attendees.data, size_sqm=form.size_sqm.data, power_requirements=form.power_requirements.data, noise=form.noise.data, structures=form.structures.data, ) db.session.add(village) db.session.add(member) db.session.add(requirements) db.session.commit() flash( "Your village registration has been received, thanks! You can edit it here." ) return redirect( url_for(".edit", year=event_year(), village_id=village.id)) return render_template("villages/register.html", form=form)
def load_village(year, village_id, require_admin=False): """ Helper to return village or 404 """ if year != event_year(): abort(404) village = Village.get_by_id(village_id) if not village: abort(404) if require_admin and not (current_user.village.village == village and current_user.village.admin): abort(404) return village
def admin_village(village_id): village = Village.get_by_id(village_id) if not village: abort(404) form = AdminVillageForm() if form.validate_on_submit(): form.populate_obj(village) db.session.add(village) db.session.commit() flash("The village has been updated") return redirect(url_for(".admin_village", village_id=village.id)) form.populate(village) return render_template("villages/admin/info.html", village=village, form=form)
class MainWindows(QtWidgets.QMainWindow): def __init__(self): super(MainWindows, self).__init__() uic.loadUi( r'C:\Users\Acer\Documents\MEGA\Desenvolvimentos\villagebot\views\mainwindows.ui', self) self.thread_login = ConnectAccount(self) self.model = Village() self.current_village = None # Customização da ComboBox com nomes das Aldeias self.model_list_village = ListOfVillages() self.cb_list_village.setModel(self.model_list_village) # Customização da tabela contendo so campos de recursos self.model_resource_fields = TableOfResourceFields() self.model_resource_fields.setHorizontalHeaderLabels( ['ID', 'Campo', 'Nivel']) self.table_fields.setModel(self.model_resource_fields) # Customização da tabela contendo os campos de construção self.model_construction_fields = TableOfConstructionFields() self.model_construction_fields.setHorizontalHeaderLabels( ['ID', 'Campo', 'Nivel']) self.table_village.setModel(self.model_construction_fields) # Customização da tabela contendo os campos em construção self.model_fields_in_construction = TableFieldsInCOnstruction() self.model_fields_in_construction.setHorizontalHeaderLabels( ['ID', 'Campo', 'Nivel']) self.table_queue.setModel(self.model_fields_in_construction) # Inicializar console self.console_text.append("[14:57:00] -> Seja bem vindo ao BotVillage") self.console_text.setReadOnly(True) customize_tables(self.table_fields) customize_tables(self.table_village) customize_tables(self.table_queue) customize_tables(self.table_building_ordens, 270) # Customizações gerais self.lb_msg.setStyleSheet('color: red') self.tabs.setTabEnabled(1, False) # Setando texto para testes self.le_server.setText("ts2.lusobrasileiro.travian.com") self.le_user.setText("dionialves") self.le_pass.setText("alves625") # Conexões dos botoes self.bt_logar.clicked.connect(self.btn_clicked_login) self.cb_list_village.currentIndexChanged.connect( self.update_tables_on_click) self.update_button.clicked.connect(self.update_button_clicked) self.table_fields.clicked.connect( self.update_name_of_next_building_from_table_fields) self.table_village.clicked.connect( self.update_name_of_next_building_from_table_village) def update_name_of_next_building_from_table_village(self, index): """ Esta função atualiza os widgets name_of_next_building e construction_level. Campos estes que serão usados para adicionar novas ordens na fila. """ # Atualiza texto do name_of_next_building self.name_of_next_building.setText( self.model.fields[self.current_village]['name'][index.row() + 18]) # Atualiza Var do construction_level level = self.model.fields[self.current_village]['level'][index.row() + 18] self.construction_level.setValue(int(level) + 1) def update_name_of_next_building_from_table_fields(self, index): """ Esta função atualiza os widgets name_of_next_building e construction_level. Campos estes que serão usados para adicionar novas ordens na fila. """ # Atualiza texto do name_of_next_building self.name_of_next_building.setText( self.model.fields[self.current_village]['name'][index.row()]) # Atualiza Var do construction_level level = self.model.fields[self.current_village]['level'][index.row()] self.construction_level.setValue(int(level) + 1) def update_tables_on_click(self): """ Necessário ajustar o codigo dessa função """ # Atualizando variavel current_village self.current_village = self.cb_list_village.currentText() # Limpando as tabelas self.model_resource_fields.clear() self.model_construction_fields.clear() self.model_fields_in_construction.clear() # Definindo o header das tabelas self.model_construction_fields.setHorizontalHeaderLabels( ['ID', 'Campo', 'Nivel']) self.model_resource_fields.setHorizontalHeaderLabels( ['ID', 'Campo', 'Nivel']) self.model_fields_in_construction.setHorizontalHeaderLabels( ['ID', 'Campo', 'Nivel']) customize_tables(self.table_fields) customize_tables(self.table_village) customize_tables(self.table_queue) customize_tables(self.table_building_ordens, 270) self.model_resource_fields.constructor( self.model.fields[self.current_village]) self.model_construction_fields.constructor( self.model.fields[self.current_village]) self.model_fields_in_construction.constructor( self.model.building_ordens[self.current_village]) def btn_clicked_login(self): self.lb_msg.setText("") if self.model.is_logged: self.logout() else: if self.validate_input_for_login(): self.disabled_input_fields() self.add_message_console('Logando na conta') self.login() else: self.lb_msg.setText( "Favor preencher corretamente os campos: Usuário, Senha e Servidor" ) def validate_input_for_login(self): if self.le_server.text() and self.le_user.text() and self.le_pass.text( ): return True return False def login(self): self.thread_login = ConnectAccount(self) self.thread_login.finished.connect(self.is_login) self.thread_login.start() def is_login(self): if self.model.is_logged: self.input_fields_if_logged_in() self.update_list_of_villages_names() else: self.input_fields_if_disconnected() def input_fields_if_logged_in(self): self.bt_logar.setText("Logout") self.bt_logar.setEnabled(True) self.tabs.setTabEnabled(1, True) self.tabs.setCurrentIndex(1) def input_fields_if_disconnected(self): self.bt_logar.setText("Login") self.tabs.setTabEnabled(1, False) self.tabs.setCurrentIndex(0) def disabled_input_fields(self): self.le_server.setEnabled(False) self.le_user.setEnabled(False) self.le_pass.setEnabled(False) self.bt_logar.setEnabled(False) def enable_input_fields(self): self.le_server.setEnabled(True) self.le_user.setEnabled(True) self.le_pass.setEnabled(True) self.bt_logar.setEnabled(True) def update_list_of_villages_names(self): # Update QComboBox: List of villages names self.model_list_village.villages = self.model.get_name_village() self.model_list_village.layoutChanged.emit() def update_button_clicked(self): self.thread_login = UpdateVilageThread(self) self.thread_login.finished.connect(self.update_tables_on_click) self.thread_login.start() def add_message_console(self, message): hour = '[%s]' % datetime.now().strftime('%H:%M:%S') message = hour + ' -> ' + message self.console_text.append(message) def logout(self): self.input_fields_if_disconnected() self.enable_input_fields() self.model.close_browser()
def admin_village(village_id): village = Village.get_by_id(village_id) if not village: abort(404) return render_template("villages/admin/info.html", village=village)