Esempio n. 1
0
    def _clean_record(rc):
        """
        Cleaning the record
        """

        # - Change 'a - b' to 'a-b'
        for k in rc.keys():
            if isinstance(rc[k], basestring):
                rc[k]= rc[k].replace(' - ', '-')

        # - Gather all possible variations of name.
        rc['name_lookup']= list([rc['address_city']])
        if ' ' in rc['address_city']:
            rc['name_lookup'].append(rc['address_city'].replace(' ', '-'))

        # - Add slug to increase probability of finding the record,
        #   even if name is written with mistakes
        rc['slug']= slugify(downcode(rc['address_city'].decode('utf-8')))

        # - Cleaning tel/fax codes and numbers.
        for code_num in ('tel_code', 'fax_code', 'tel_number', 'fax_number',
                         'address_postalcode'):
            rc[code_num]= re.sub('[^0-9]+', '', rc[code_num])

        # Re-naming elements according to their territory
        rc['name']= '%s, %s' % (rc['address_city'], rc['name'])

        return rc
Esempio n. 2
0
File: forms.py Progetto: CCLab/sezam
    def search(self):
        # Before-search processing goes here (downcode the phrase).
        # Preserve original `q` to put it back to the form after search.
        original_q= self.cleaned_data['q']
        self.cleaned_data['q']= downcode(self.cleaned_data['q'])

        # Figure out models based on the form data keys.
        models= []
        for k in dict(self.data).keys():
            if k != 'q':
                try:
                    models.extend(MODELS[k])
                except:
                    continue
        if len(models) == 0:
            models= MODELS['all']
        self.cleaned_data.update({'models': list(set(models))}) # Remove duplicates.

        # Based on `models` list, figure out filter status
        # to update the template.
        filter_status= [k for k, v in MODELS.iteritems() if models == v][0]
        self.cleaned_data.update({'model_filter': filter_status})

        # Search!
        lQuerySet= super(ModelSearchForm, self).search()

        # Set back the original value of the form's search field - 
        # it must be displayed correctly in the form.
        self.cleaned_data['q']= original_q

        return lQuerySet
Esempio n. 3
0
 def prepare(self, object):
     self.prepared_data = super(AuthorityProfileIndex, self).prepare(object)
     # Clean the text.
     if self.prepared_data['text']:
         self.prepared_data['text']= downcode(clean_text_for_search(
             self.prepared_data['text']))
     if self.prepared_data['report_text'] is None:
         self.prepared_data['report_text']= ''
     return self.prepared_data
Esempio n. 4
0
    def prepare(self, object):
        self.prepared_data = super(PIARequestIndex, self).prepare(object)

        # Extract all the messages from the PIAThread
        # and append them to the end of `text`.
        for msg in object.thread.filter(
                created__lte=self._till_now()).order_by('created'):
            self.prepared_data['text'] += msg.body

        # For reporting purposes storing a duplicate of the thread,
        # cleaned, but not downcoded.
        self.prepared_data['report_text']= clean_text_for_search(
            self.prepared_data['text'])

        # Clean and downcode text for index.
        self.prepared_data['text']= downcode(self.prepared_data['report_text'])

        return self.prepared_data