Ejemplo n.º 1
0
    def import_projects(self):
        proj_names = []
        mapping, proj_df = self.get_mapping_and_df('project_project')
        for values in mapping.iterate_dataframe(proj_df):
            proj_names.append(values['name'])
        self.log_info(f'Importing {len(proj_names)} projects: ' +
                      ', '.join(proj_names))

        project_types = set()  # type: Set[str]
        for values in mapping.iterate_dataframe(proj_df):
            proj_id, proj_name, proj_type = values['id'], values['name'], str(
                values['type_id'])
            project_types.add(proj_type)
            if proj_type in self.missing_doc_types:
                raise Exception(
                    f'Doc. type {self.missing_doc_types[proj_type]} ' +
                    f'was not found, project "{proj_name}"')
            proj_type = self.document_types[proj_type]
            # TRANSACTION starts here
            with transaction.atomic():
                with ModelLock(None, Project,
                               ModelLock.LOCK_MODE_ACCESS_EXCLUSIVE):
                    existing_projects = list(
                        Project.all_objects.filter(name=proj_name).values_list(
                            'pk', 'type_id'))
                    if not existing_projects:
                        # create project
                        self.log_info(f'Creating project "{proj_name}"')
                        new_proj = Project()
                        new_proj.name = proj_name
                        new_proj.type_id = proj_type
                        new_proj.status_id = values['status_id']
                        new_proj.send_email_notification = values[
                            'send_email_notification'] == 't'
                        new_proj.hide_clause_review = values[
                            'hide_clause_review'] == 't'
                        new_proj.save()
                        self.project_ids[proj_id] = new_proj.pk
                        continue

            # there might be more than one project with the same name
            # some of these projects might have the required type
            matching_projects = [
                p for p in existing_projects if p[1] == proj_type
            ]
            if not matching_projects:
                raise Exception(f'''Importing document type ({proj_type})
                                    differs from the document type of the selected 
                                    project ({existing_projects[0][1]}).''')
            self.project_ids[proj_id] = matching_projects[0][0]

        if self.project:
            project_types = {self.project.type_id}
        self.check_project_doc_field_types(project_types)
Ejemplo n.º 2
0
    async def get(self, *args, **kwargs):
        """
        项目数据查询
        """
        ret_data = []
        project_query = Project.extend()

        name = self.get_argument('name', None)
        if name is not None:
            project_query = project_query.filter(Project.name == name)

        env = self.get_argument('env', None)
        if env is not None:
            project_query = project_query.filter(TestEnvironment.name == env)

        host = self.get_argument('host', None)
        if host is not None:
            project_query = project_query.filter(
                TestEnvironment.host_address == host)

        project_query = project_query.order_by(-Project.add_time)
        projects = await self.application.objects.execute(project_query)
        for project in projects:
            project_dict = model_to_dict(project)
            ret_data.append(project_dict)

        return self.json(JsonResponse(code=1, data=ret_data))
Ejemplo n.º 3
0
    def __get_or_create_project(self):
        try:
            project_id = None
            if self.request.POST and 'project_unique_id' in self.request.POST:
                print("########## GOT EXISTING #+++++++++++++++++")
                project_unique_id = Project.base64_to_uuid(
                    self.request.POST.get("project_unique_id"))
                existing_project = Project.objects.filter(
                    unique_id=project_unique_id).first()
                if existing_project:
                    project_id = existing_project.id

            project, created = Project.objects.update_or_create(
                pk=project_id,
                defaults={
                    'heading': self.cleaned_data['heading'],
                    'subheading': self.cleaned_data['subheading'],
                    'description': self.cleaned_data['description'],
                    'semester': self.cleaned_data['semester'],
                    'year_from': self.cleaned_data['year_from'],
                    'year_to': self.cleaned_data['year_to'],
                    'degree_program': self.cleaned_data['degree_program'],
                    'subject': self.cleaned_data['subject']
                })
            if created:
                print("-Created Project")
            else:
                print("-Updated Project")
            self.project = project
        except Exception as e:
            print(str(e))

            self.project = None
Ejemplo n.º 4
0
    def post(self, request):
        project_form = ProjectForm(request.POST)

        if project_form.is_valid():
            name = request.POST['name']
            type = request.POST['type']
            detail = request.POST['detail']
            creator = UserProfile.objects.get(username=request.user)
            project = Project(name=name,
                              type=type,
                              detail=detail,
                              creator=creator)
            project.save()
        else:
            return render(request, 'project_add.html',
                          {'error': project_form.errors})
        return HttpResponseRedirect(reverse('project_list'))
Ejemplo n.º 5
0
    def get_projects(self):

        qset = Project.objects.filter(approval_state=Project.APPROVED_STATE)
        #print(qset)
        if not qset:
            return []

        if self.user_id:
            qset = qset.filter(members__id=self.user_id)
            if not qset:
                return []

        if self.except_projects:
            qset = qset.exclude(unique_id__in=[
                Project.base64_to_uuid(uid) for uid in self.except_projects
            ])
            if not qset:
                return []

        if self.tags:
            # TODO: FILTER BY FIRSTNAME + LASTNAME IF SHOW_CLEAR_NAME = TRUE
            #qset = qset.extra(select={'full_name':'select CONCAT(CONCAT(first_name, " "), last_name) from registration.AuthEmailUser where registration.AuthEmailUser.id = lib.user.auth_user'})
            qset = qset.filter(self.filter_for_tags(self.tags))
            if not qset:
                return []

        if self.order == 'newest':
            qset = qset.order_by('-upload_date', '-views')
        elif self.order == 'most_views':
            qset = qset.order_by('-views', '-upload_date')
        else:
            most = Project.objects.order_by('-views')[:1].get().views
            newest = Project.objects.order_by('-id')[:1].get().id
            qset = qset.extra(select={
                'default_order':
                "(project_project.id/%s)*(views/%s)"
            },
                              select_params=(newest,
                                             most)).order_by('-default_order')
            # TODO: Rework default sorting algorithm
            # Problems: Uses IDs, not date. Also should be based of publish_date, not upload_date. Should be normalized values,
            # so the 50% oldest and most viewed post = 70% oldest and 30% most viewed
            # Question: What is the basis? Old relative to: -oldest(date), -unix_stimestamp, -oldest(counter, just how many projects come between)
            # , -newest(to NOW()), how normalize?
            # Views are normalized so that when all projects have the same views, all get 1.0 score. The higher the difference between most
            # and least viewed, the more diverse are the resulting scores. Should this be this way?
            # Maybe even implement a relevancy search like google (number of occurence of tags etc.) in the far future

        qset = qset.distinct()
        qset = qset[:self.maximum]
        #print(qset.query)
        return qset
Ejemplo n.º 6
0
def getProjectDetail():
    if request.method == 'GET':
        projects = Project.query.filter(
            Project.is_delete == True).order_by(-Project.create_time).all()
        return render_template('add/projectDetail.html', projects=projects)
    else:
        projectname = request.form.get('projectname')
        if projectname:
            project = Project.query.filter_by(project_name=projectname).all()
            if not project:
                project = Project(project_name=projectname)
                db.session.add(project)
                db.session.commit()
                return render_template('add/projectDetail.html')
            else:
                return render_template('add/projectDetail.html')
        else:
            pass
Ejemplo n.º 7
0
    async def get(self, *args, **kwargs):
        ret_data = []
        project_query = Project.extend()

        # 根据项目名过滤
        name = self.get_argument('name', None)
        if name is not None:
            project_query = project_query.filter(Project.name == name)

        # 默认排序规则
        project_query = project_query.order_by(Project.add_time.desc())

        projects = await self.application.objects.execute(project_query)
        for project in projects:
            project_dict = model_to_dict(project)
            ret_data.append(project_dict)

        return self.json(Result(code=1, msg="项目数据查询成功!", data=ret_data))
Ejemplo n.º 8
0
 def create(self, validated_data):
     user = self.context.get('request').user
     project = Project(**validated_data, user=user)
     project.save()
     return project