def run(self, input=None): 
     start = self.options['start']
     length = self.options['length']
     if self.bound_form.use_solr == False: # make database query
         return database.get_queryset(**self.options)[start:start+length].values_list('id', flat=True)
     else:
         return solrlib.article_ids(self.options)
Ejemplo n.º 2
0
    def run(self):
        sel = SelectionForm(project=self.project, data=self.data)

        if not sel.is_valid():
            # This should not happen when using normal pages (i.e., someone is trying
            # to hack)
            forms.ValidationError("Non-valid values entered.")

        sel.full_clean()
        if sel.use_solr:
            sel.cleaned_data['length'] = 99999999  # Return 'unlimited' results
            sel.cleaned_data['sortColumn'] = None
            sel.cleaned_data['start'] = 0
            sel.cleaned_data['columns'] = []

            articles = solrlib.getArticles(sel.cleaned_data)
        else:
            articles = database.get_queryset(**sel.cleaned_data)

        project = Project.objects.get(id=self.data.get('projects'))

        # Create articleset
        a = ArticleSet.objects.create(project=project,
                                      name=self.data['setname'])
        a.add(*articles)

        # Split all articles
        CreateSentences(dict(articlesets=[a.id])).run()

        # Create codingjob
        coder = User.objects.get(id=self.data['coder'])
        articleschema = CodingSchema.objects.get(id=self.data['articleschema'])
        unitschema = CodingSchema.objects.get(id=self.data['unitschema'])

        if not 'insertuser' in self.data:
            insertuser = auth.get_request().user
        else:
            insertuser = User.objects.get(id=self.data['insertuser'])

        c = CodingJob.objects.create(project=project,
                                     name=self.data['setname'],
                                     articleset=a,
                                     coder=coder,
                                     articleschema=articleschema,
                                     unitschema=unitschema,
                                     insertuser=insertuser)
        html = "<div>Saved as <a href='%s'>coding job %s</a>.</div>"

        return HttpResponse(json.dumps({
            "html":
            html % (reverse("codingjob", args=[project.id, c.id]), c.id),
            "webscriptClassname":
            self.__class__.__name__,
            "webscriptName":
            self.name,
            "doNotAddActionToMainForm":
            True
        }),
                            mimetype='application/json')
Ejemplo n.º 3
0
 def run(self, input=None):
     start = self.options['start']
     length = self.options['length']
     if self.bound_form.use_solr == False:  # make database query
         return database.get_queryset(
             **self.options)[start:start + length].values_list('id',
                                                               flat=True)
     else:
         return solrlib.article_ids(self.options)
Ejemplo n.º 4
0
    def run(self):
        sel = SelectionForm(project=self.project, data=self.data)

        if not sel.is_valid():
            # This should not happen when using normal pages (i.e., someone is trying
            # to hack)
            forms.ValidationError("Non-valid values entered.")

        sel.full_clean()
        if sel.use_solr:
            sel.cleaned_data['length'] = 99999999 # Return 'unlimited' results
            sel.cleaned_data['sortColumn'] = None
            sel.cleaned_data['start'] = 0
            sel.cleaned_data['columns'] = []

            articles = solrlib.getArticles(sel.cleaned_data)
        else:
            articles = database.get_queryset(**sel.cleaned_data)

        project = Project.objects.get(id=self.data.get('projects'))

        # Create articleset
        a = ArticleSet.objects.create(project=project, name=self.data['setname'])
        a.add(*articles)

        # Split all articles 
        CreateSentences(dict(articlesets=[a.id])).run()

        # Create codingjob
        coder = User.objects.get(id=self.data['coder'])
        articleschema = CodingSchema.objects.get(id=self.data['articleschema'])
        unitschema = CodingSchema.objects.get(id=self.data['unitschema'])

        if not 'insertuser' in self.data:
            insertuser = auth.get_request().user
        else:
            insertuser = User.objects.get(id=self.data['insertuser'])

        c = CodingJob.objects.create(project=project, name=self.data['setname'], articleset=a,
                                     coder=coder, articleschema=articleschema, unitschema=unitschema,
                                     insertuser=insertuser)
        html = "<div>Saved as <a href='%s'>coding job %s</a>.</div>"


        return HttpResponse(json.dumps({
            "html" : html % (reverse("codingjob", args=[project.id, c.id]), c.id),
            "webscriptClassname" : self.__class__.__name__,
            "webscriptName" : self.name,
            "doNotAddActionToMainForm" : True            
            
        }), mimetype='application/json')