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 create_default_groups():
        """
        Automatically create groups in STRATUM_GROUPS
        """
        # Fisheries, Programs, Gear Types

        premade = [
            {
                'group': 16,
                'name': 'Non Catchshares',
                'group_type': 'Programs'
            },
            {
                'group': 17,
                'name': 'Catchshares',
                'group_type': 'Programs'
            },
            {
                'group': 18,
                'name': 'All',
                'group_type': 'Programs'
            },
        ]
        for g in premade:
            StratumGroups.create(**g)

        for prog in Programs.select():
            ProgramStratumGroupMtx.create(group=18, program=prog.program)
            if 'Catch Shares' == prog.program_name:
                ProgramStratumGroupMtx.create(group=17, program=prog.program)
            else:
                ProgramStratumGroupMtx.create(group=16, program=prog.program)
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
    def _get_programs_orm(self, rebuild=False):
        """
        Get programs from database via ORM, store DB keys
        """
        if self._programs is not None and not rebuild:  # only build this once
            return

        self._programs = list()

        fish_q = Programs.select()
        for fishery in fish_q:
            self._programs.append(fishery.program_name)
        self._programs = sorted(set(self._programs))  # Remove Duplicates + Sort Alphabetically
Beispiel #6
0
    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()