def _create_test_data(self): """ Intended to run with test_db, before trips created """ for t in range(3): Vessels.create(vessel=self.vessel_id_test + t, port=0, vessel_name='Test Vessel {}'.format(t)) Users.create(user=self.user_id_test + t, first_name='User {}'.format(t), last_name='Last', password='******', status=1) Programs.create(program=self.prog_id_test, program_name='Test Program') vess = Vessels.select() for p in vess: print('Created {}'.format(p.vessel_name)) users = Users.select() for u in users: print('Created {}'.format(u.first_name)) p = Programs.get(Programs.program == 1) print('Created {}'.format(p.program_name))
def get_current_program_name(): try: program_id = int(ObserverDBUtil.get_setting('current_program_id')) return Programs.get(Programs.program == program_id).program_name except Programs.DoesNotExist: return None except (TypeError, ValueError): return None
def get_program_ids_for_user(username): user_id = ObserverUsers.get_user_id(username) if user_id: programs = ObserverUsers._get_user_program_names(user_id) program_ids = [ Programs.get(Programs.program_name == program_name).program for program_name in programs ] return program_ids
def currentProgramName(self, program_name): if program_name: try: self._current_program = Programs.get( Programs.program_name == program_name) prog_id = self._current_program.program ObserverDBUtil.set_current_program_id(prog_id) self._logger.debug(f'Current Program ID set to {prog_id}') fisheries = self.get_fisheries_by_program_id( self._current_program.program, self._is_fixed_gear) self._current_fisheries.setStringList(fisheries) self.fisheries_model_changed.emit() except Programs.DoesNotExist as e: self._logger.error(e) self._current_program = None else: self._current_program = None self.current_program_changed.emit()