示例#1
0
class ArticleListForm(amcat.scripts.forms.ArticleColumnsForm, amcat.scripts.forms.SelectionForm):
    start = forms.IntegerField(initial=0, min_value=0, widget=forms.HiddenInput, required=False)
    length = forms.IntegerField(initial=100, min_value=1, max_value=9999999,
                                widget=forms.HiddenInput, required=False)
    highlight = forms.BooleanField(initial=False, required=False)
    sortColumn = forms.CharField(required=False)
    sortOrder = forms.ChoiceField(
                    choices=(
                        ('asc', 'Ascending'),
                        ('desc', 'Descending'),
                     ),
                    initial = 'asc', required=False)

    def clean_start(self):
        data = self.cleaned_data['start']
        if data == None:
            data = 0
        return data

    def clean_length(self):
        data = self.cleaned_data['length']
        if data == None:
            data = 100
        if data == -1:
            data = 99999999 # unlimited (well, sort of ;)
        return data

    def clean_columns(self):
        data = self.cleaned_data['columns']
        if self.cleaned_data['query'] == '' and ('keywordInContext' in data or 'hits' in data):
            self._errors["columns"] = self.error_class(
                ['Keyword in Context and Hits columns require a query'])
        return data
示例#2
0
class ViewModelForm(amcat.scripts.forms.GeneralColumnsForm):
    start = forms.IntegerField(initial=0, min_value=0, widget=forms.HiddenInput, required=False)
    length = forms.IntegerField(initial=100, min_value=1, max_value=9999999, widget=forms.HiddenInput, required=False)
    model = forms.CharField()
    select_related = forms.BooleanField(required=False, initial=False)
    search = forms.CharField(required=False)
    projects = forms.ModelMultipleChoiceField(queryset=Project.objects.all(), required=False) # TODO: change to projects of user
    
    sortColumnNr = forms.IntegerField(required=False)
    sortOrder = forms.ChoiceField(
                    choices=(
                        ('asc', 'Ascending'), 
                        ('desc', 'Descending'),
                     ),
                    initial = 'asc', required=False)
    
    
    
    def clean_start(self):
        data = self.cleaned_data['start']
        if data == None:
            data = 0
        return data
        
    def clean_length(self):
        data = self.cleaned_data['length']
        if data == None:
            data = 100
        if data == -1:
            data = 99999999 # unlimited (well, sort of ;)
        return data
        
    def clean_model(self):
        """return the corresponding model with the provided string.
        Also handles . for instance 'coding.CodingJob' will find class 'coding.codingjob.CodingJob'
        but also 'authorisation.ProjectRole' will find the corresponding class"""
        data = self.cleaned_data['model']
        try:
            if '.' in data: # this code is ugly..
                split = data.split('.')
                clss = getattr(amcat.models, split[0].lower())
                try:
                    moduleobj = getattr(clss, split[1].lower())
                    data = split[1]
                except AttributeError: 
                    moduleobj = clss
                    data = split[1]
            else:
                moduleobj = getattr(amcat.models, data.lower())
            log.info('moduleobj: %s, data: %s' % (moduleobj, data))
            if data.islower(): data = data.capitalize() # to make sure "medium" can also be used, not only "Medium" (for example)
            data = getattr(moduleobj, data)
        except Exception,e:
            log.exception('finding model problem')
            self._errors["model"] = self.error_class(['Invalid model name'])
        # if not hasattr(amcat.models, data.lower()):
            # self._errors["modelname"] = self.error_class(['Invalid model name'])
            # return None
        return data
示例#3
0
class AggregationForm(amcat.scripts.forms.SelectionForm):
    """the form used by the Aggregation script"""
    xAxis = forms.ChoiceField(choices=(('date', 'Date'), ('medium', 'Medium'),
                                       ('total', 'Total')),
                              initial='date')
    yAxis = forms.ChoiceField(choices=(('total', 'Total'), ('searchTerm',
                                                            'Search Term'),
                                       ('medium', 'Medium')),
                              initial='medium')
    dateInterval = forms.ChoiceField(choices=(('day', 'Day'), ('week', 'Week'),
                                              ('month', 'Month'), ('quarter',
                                                                   'Quarter'),
                                              ('year', 'Year')),
                                     initial='month',
                                     required=False)
    relative = forms.BooleanField(
        label="Make values relative to (and exclude) first column",
        required=False)
示例#4
0
class AggregationForm(amcat.scripts.forms.SelectionForm):
    """the form used by the Aggregation script"""
    xAxis = forms.ChoiceField(choices=(('date', 'Date'), ('medium', 'Medium')),
                              initial='date')
    yAxis = forms.ChoiceField(choices=(('total', 'Total'), ('searchTerm',
                                                            'Search Term'),
                                       ('medium', 'Medium')),
                              initial='medium')
    dateInterval = forms.ChoiceField(choices=(('day', 'Day'), ('week', 'Week'),
                                              ('month', 'Month'), ('quarter',
                                                                   'Quarter'),
                                              ('year', 'Year')),
                                     initial='month',
                                     required=False)
    counterType = forms.ChoiceField(choices=(('numberOfArticles',
                                              'Number of Articles'),
                                             ('numberOfHits',
                                              'Number of Hits')),
                                    initial='numberOfArticles')