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 setup_project( project_id: str, protein: str, proposal: str, crystals: List[Dict[str, str]], import_autoproc: bool, encrypted: bool, ): try: print(f"setting up project, ID {project_id}: {protein} ({proposal})") user_proj = UserProject.get(project_id) project = create_project( settings.PROJECTS_DB_DIR, project_id, proposal, protein, encrypted ) with db_session: _setup_project_folders(project) _add_crystals(project, Crystals.from_list(crystals)) _add_datasets(project) if import_autoproc: scrape_imported_autoproc_status(project) user_proj.set_ready() except Exception as e: user_proj.set_failed(f"{e}") # re-raise exception, so that # details are recoded in the worker log raise e
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 set_current(request, id): proj = UserProject.get_project(get_proposals(request), id) if proj is None: return HttpResponseNotFound() request.user.set_current_project(proj) # redirect to the 'landing page' page return redirect(reverse("project_summary"))
def projects(request): """ Adds a projects related data to template context. """ if not request.user.is_authenticated: # user not logged in, no projects context return {} proposals = get_proposals(request) return { # list of all projects that are accessible to the user "projects": list(UserProject.user_projects(proposals)), # user's currently selected project "project": request.user.get_current_project(proposals), }
def delete(_, id): try: proj = UserProject.get(id) except UserProject.DoesNotExist: return HttpResponseNotFound(f"project {id} not found") # # Do a 'cosmetic' delete, # only delete the project from the list of existing projects. # leave all data files will be left in-place. # # This way it's should be possible to 'recover' a project, # deleted by mistake. # proj.delete() return HttpResponse(f"ok")
def setUp(self): super().setUp() # # set-up two dummy projects # self.proj_db_dir = Path(self.temp_dir, "db", "projs") self.proj1 = self.projects[0] self.user_proj1 = UserProject.get(self.proj1.id) self.proj2 = self.projects[1] # # mock a request where user have access to the project created above # and current project is set to 'proj1' project # self.req_mock = _get_request_mock( True, current_project=self.user_proj1, session=dict(proposals=[PROP1, PROP2]), )
def new(request): """ GET requests show the 'Create new Project' page POST requests will try to create a new project """ if request.method == "GET": proposals = sorted(get_proposals(request), reverse=True) return render( request, "project_new.html", {"proposals": proposals}, ) # # HZB-site hack, use 'username' as proposal # # As HZB is not using proposal to organize data, use the # user name as 'proposal' for now. Perhaps we should # restructure the code to no use 'proposal' concept in general. # post_args = request.POST if current.proposals_disabled(): # make a mutable copy of POST arguments dict post_args = post_args.copy() # put down current user name as 'proposal' post_args["proposal"] = request.user.username form = ProjectForm(post_args, request.FILES) if not form.is_valid(): return HttpResponseBadRequest(form.get_error_message()) protein, proposal, crystals, import_autoproc, encrypt = form.get_values() proj = UserProject.create_new(protein, proposal) setup_project.delay(str(proj.id), protein, proposal, crystals.as_list(), import_autoproc, encrypt) return HttpResponse("ok")
def set_current_project(self, project_id: str): proj = UserProject.get_project(self.proposals, project_id) # type: ignore self.user.set_current_project(proj)
def get_user_project(self, project) -> UserProject: return UserProject.get(project.id)
def setUp(self): self.project = UserProject.create_new("MID2", "20201122") self.assertTrue(self.project.is_pending())
def setUp(self): super().setUp() self.user_project = UserProject.get(self.projects[0].id) self.user = User(username=self.USERNAME) self.user.save()
def _wrap_projects(request): for project in UserProject.user_projects(get_proposals(request)): yield ProjectEntry(project)