def get_current_project(self, proposals) -> Optional[Project]: """ get user's currently selected project proposals - list of proposal number for this user """ def _get_current_project() -> Optional[UserProject]: """ Get currently selected project, if any. Takes care of filtering out 'current project' that is in pending state. """ if self.current_project is None: return None if self.current_project.is_pending(): return None return UserProject.get_project(proposals, self.current_project.id) # # if user object have selected current_project, use that # otherwise use one of the user's project. # # User Project class methods for fetching all projects, so that # we only give access to project's included into current proposals # list. # cur_proj = _get_current_project() if cur_proj is None: return next(UserProject.user_projects(proposals), None) return get_project(settings.PROJECTS_DB_DIR, cur_proj.id)
def _handle(self, *args, **options): protein = options["protein"] proposal = options["proposal"] shift = options["shift"] old_paths = _get_old_paths(protein, proposal, shift) project = get_project(settings.PROJECTS_DB_DIR, "8") _migrate_pandda(project, old_paths)
def _create_project(protein: str, proposal: str, crystals: Crystals) -> Project: user_proj = UserProject.create_new(protein, proposal) project_id = user_proj.id setup_project(project_id, protein, proposal, crystals.as_list(), False, False) return get_project(settings.PROJECTS_DB_DIR, project_id)
def get_project(project_id: str) -> Project: """ returns project's model object, or raises CommandError exception if no project with specified ID exists """ try: return projects.get_project(settings.PROJECTS_DB_DIR, project_id) except ProjectNotFound: raise CommandError(f"no project with ID '{project_id}' exist")
def test_success(self): with db_session: resp = self.client.get("/encryption/key/forget/") with db_session: # check that key was removed from the database, # we need to reload project model in a new session project = get_project(self.projects_db_dir, self.project.id) self.assertFalse(project.has_encryption_key()) # check that we were redirected to correct view self.assertRedirects(resp, reverse("encryption"))
def test_key_uploaded(self): """ test happy path for uploading encryption key """ with db_session: resp = self.client.post( self.URL, dict(method="upload_file", key=self.upload_file)) with db_session: # check that key was saved to database, # we need to reload project model in a new session project = get_project(self.projects_db_dir, self.project.id) self.assertEquals(project.encryption_key, DUMMY_KEY) # check that we were redirected to correct view self.assertRedirects(resp, reverse("encryption"))
def import_crystals(project_id: str, crystals: List[Dict[str, str]]): try: print(f"importing crystals to project ID: {project_id}") with db_session: project = get_project(settings.PROJECTS_DB_DIR, project_id) _add_crystals(project, Crystals.from_list(crystals)) _add_datasets(project) except Exception as e: UserProject.get(project_id).set_failed(f"{e}") # re-raise exception, so that # details are recoded in the worker log raise e UserProject.get(project_id).set_ready()
def forget_key(self): with db_session: project = get_project(self.projects_db_dir, self.project.id) project.forget_key()
def user_projects(user_proposals): pending_ids = PendingProject.get_project_ids() for user_proj in UserProject.objects.filter( proposal__in=user_proposals).exclude(id__in=pending_ids): yield get_project(settings.PROJECTS_DB_DIR, user_proj.id)