예제 #1
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
예제 #2
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