mirror of
				https://gitlab.crans.org/bde/nk20
				synced 2025-11-04 01:12:08 +01:00 
			
		
		
		
	Autocomplete food on ManageIngredients now show owners
This commit is contained in:
		@@ -21,9 +21,13 @@ class FoodSerializer(serializers.ModelSerializer):
 | 
				
			|||||||
    REST API Serializer for Food.
 | 
					    REST API Serializer for Food.
 | 
				
			||||||
    The djangorestframework plugin will analyse the model `Food` and parse all fields in the API.
 | 
					    The djangorestframework plugin will analyse the model `Food` and parse all fields in the API.
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
 | 
					    # This fields is used for autocompleting food in ManageIngredientsView
 | 
				
			||||||
 | 
					    # TODO Find a better way to do it
 | 
				
			||||||
 | 
					    owner_name = serializers.CharField(source='owner.name', read_only=True)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    class Meta:
 | 
					    class Meta:
 | 
				
			||||||
        model = Food
 | 
					        model = Food
 | 
				
			||||||
        fields = '__all__'
 | 
					        fields = ['name', 'owner', 'allergens', 'expiry_date', 'end_of_life', 'is_ready', 'order', 'owner_name']
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class BasicFoodSerializer(serializers.ModelSerializer):
 | 
					class BasicFoodSerializer(serializers.ModelSerializer):
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -167,7 +167,7 @@ class ManageIngredientsForm(forms.Form):
 | 
				
			|||||||
        model=Food,
 | 
					        model=Food,
 | 
				
			||||||
        resetable=True,
 | 
					        resetable=True,
 | 
				
			||||||
        attrs={"api_url": "/api/food/food",
 | 
					        attrs={"api_url": "/api/food/food",
 | 
				
			||||||
               "class": "autocomplete"},
 | 
					               "class": "autocomplete manageingredients-autocomplete"},
 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
    name.label = _('Name')
 | 
					    name.label = _('Name')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -413,13 +413,12 @@ class TestFoodAPI(TestAPI):
 | 
				
			|||||||
        """
 | 
					        """
 | 
				
			||||||
        self.check_viewset(BasicFoodViewSet, '/api/food/basicfood/')
 | 
					        self.check_viewset(BasicFoodViewSet, '/api/food/basicfood/')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        # TODO Repair and detabulate this test
 | 
				
			||||||
        def test_transformedfood_api(self):
 | 
					        def test_transformedfood_api(self):
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
            Load TransformedFood API page and test all filters and permissions
 | 
					            Load TransformedFood API page and test all filters and permissions
 | 
				
			||||||
            """
 | 
					            """
 | 
				
			||||||
        # TODO Repair this test
 | 
					            self.check_viewset(TransformedFoodViewSet, '/api/food/transformedfood/')
 | 
				
			||||||
        pass
 | 
					 | 
				
			||||||
        # self.check_viewset(TransformedFoodViewSet, '/api/food/transformedfood/')
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def test_qrcode_api(self):
 | 
					    def test_qrcode_api(self):
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -769,7 +769,7 @@ class OrderListView(ProtectQuerysetMixin, LoginRequiredMixin, MultiTableMixin, L
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    def get_queryset(self, **kwargs):
 | 
					    def get_queryset(self, **kwargs):
 | 
				
			||||||
        activity = Activity.objects.get(pk=self.kwargs["activity_pk"])
 | 
					        activity = Activity.objects.get(pk=self.kwargs["activity_pk"])
 | 
				
			||||||
        return Order.objects.filter(activity=activity)
 | 
					        return Order.objects.filter(activity=activity).order_by('number')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def get_tables(self):
 | 
					    def get_tables(self):
 | 
				
			||||||
        activity = Activity.objects.get(pk=self.kwargs["activity_pk"])
 | 
					        activity = Activity.objects.get(pk=self.kwargs["activity_pk"])
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -13,11 +13,14 @@ $(document).ready(function () {
 | 
				
			|||||||
    target.addClass('is-invalid')
 | 
					    target.addClass('is-invalid')
 | 
				
			||||||
    target.removeClass('is-valid')
 | 
					    target.removeClass('is-valid')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const isManageIngredients = target.hasClass('manageingredients-autocomplete')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    $.getJSON(api_url + (api_url.includes('?') ? '&' : '?') + 'format=json&search=^' + input + api_url_suffix, function (objects) {
 | 
					    $.getJSON(api_url + (api_url.includes('?') ? '&' : '?') + 'format=json&search=^' + input + api_url_suffix, function (objects) {
 | 
				
			||||||
      let html = '<ul class="list-group list-group-flush" id="' + prefix + '_list">'
 | 
					      let html = '<ul class="list-group list-group-flush" id="' + prefix + '_list">'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      objects.results.forEach(function (obj) {
 | 
					      objects.results.forEach(function (obj) {
 | 
				
			||||||
        html += li(prefix + '_' + obj.id, obj[name_field])
 | 
					        const extra = isManageIngredients ? ` (${obj.owner_name})` : ''
 | 
				
			||||||
 | 
					        html += li(`${prefix}_${obj.id}`, `${obj[name_field]}${extra}`)
 | 
				
			||||||
      })
 | 
					      })
 | 
				
			||||||
      html += '</ul>'
 | 
					      html += '</ul>'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user