forked from rc/aircox
		
	update for production pre-release
This commit is contained in:
		
							
								
								
									
										50
									
								
								website/autocomplete_light_registry.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										50
									
								
								website/autocomplete_light_registry.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,50 @@
 | 
			
		||||
import autocomplete_light.shortcuts as al
 | 
			
		||||
from aircox_programs.models import *
 | 
			
		||||
 | 
			
		||||
from taggit.models import Tag
 | 
			
		||||
al.register(Tag)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class OneFieldAutocomplete(al.AutocompleteModelBase):
 | 
			
		||||
    choice_html_format = u'''
 | 
			
		||||
        <span class="block" data-value="%s">%s</span>
 | 
			
		||||
    '''
 | 
			
		||||
 | 
			
		||||
    def choice_html (self, choice):
 | 
			
		||||
        value = choice[self.search_fields[0]]
 | 
			
		||||
        return self.choice_html_format % (self.choice_label(choice),
 | 
			
		||||
            self.choice_label(value))
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    def choices_for_request(self):
 | 
			
		||||
        #if not self.request.user.is_staff:
 | 
			
		||||
        #    self.choices = self.choices.filter(private=False)
 | 
			
		||||
        filter_args = { self.search_fields[0] + '__icontains': self.request.GET['q'] }
 | 
			
		||||
 | 
			
		||||
        self.choices = self.choices.filter(**filter_args)
 | 
			
		||||
        self.choices = self.choices.values(self.search_fields[0]).distinct()
 | 
			
		||||
        return self.choices
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TrackArtistAutocomplete(OneFieldAutocomplete):
 | 
			
		||||
    search_fields = ['artist']
 | 
			
		||||
    model = Track
 | 
			
		||||
 | 
			
		||||
al.register(TrackArtistAutocomplete)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TrackNameAutocomplete(OneFieldAutocomplete):
 | 
			
		||||
    search_fields = ['name']
 | 
			
		||||
    model = Track
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
al.register(TrackNameAutocomplete)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#class DiffusionAutocomplete(OneFieldAutocomplete):
 | 
			
		||||
#    search_fields = ['episode', 'program', 'start', 'stop']
 | 
			
		||||
#    model = Diffusion
 | 
			
		||||
#
 | 
			
		||||
#al.register(DiffusionAutocomplete)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										19
									
								
								website/forms.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								website/forms.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,19 @@
 | 
			
		||||
from django import forms
 | 
			
		||||
from django.contrib.admin import widgets
 | 
			
		||||
 | 
			
		||||
import autocomplete_light.shortcuts as al
 | 
			
		||||
from autocomplete_light.contrib.taggit_field import TaggitWidget
 | 
			
		||||
 | 
			
		||||
from aircox_programs.models import *
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TrackForm (forms.ModelForm):
 | 
			
		||||
    class Meta:
 | 
			
		||||
        model = Track
 | 
			
		||||
        fields = ['artist', 'name', 'tags', 'position']
 | 
			
		||||
        widgets = {
 | 
			
		||||
            'artist': al.TextWidget('TrackArtistAutocomplete'),
 | 
			
		||||
            'name': al.TextWidget('TrackNameAutocomplete'),
 | 
			
		||||
            'tags': TaggitWidget('TagAutocomplete'),
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user