Prechádzať zdrojové kódy

generic search funktion

Juan Carlos 4 rokov pred
rodič
commit
202d0be403

+ 1 - 1
marktplatz/templates/marktplatz/product_overview.html

@@ -291,7 +291,7 @@ $(document).ready(function(){
     <div class="container-fluid">
       <div class="row">
         <div class="col-sm-6">
-          <form method="post" action="{% url 'search-products' %}" >
+          <form method="post" action="{% url 'generic-search-products' type=type %}" >
             {% csrf_token %}
             <!-- Left here in case we need to debug -->
             {% if signup_errors %}

+ 9 - 3
marktplatz/urls.py

@@ -14,9 +14,6 @@ urlpatterns = [
     path('register/', views.registerView.as_view(), name='register-view'),
     path('meine-projekte/', views.UsersProducts.as_view(), name='meine-projekte'),
 
-    path('projekte/', views.ProductsView.as_view(), name='products'),
-    path('projekte/filter/<slug:filter>/', views.FilterProductsView.as_view(), name='products-filter-view'),
-    path('projekte/search', views.SearchProductsView.as_view(), name='search-products'),
     path('products-list/', views.ProductsListView.as_view(), name='products-list'),
     path('products-list/embed', views.ProductsListView.as_view(  embed=True,  ), name='products-list-embed'),
 
@@ -56,6 +53,15 @@ urlpatterns = [
     path('projekt-card/<int:pk>', views.ProduktCardDetailView.as_view(), name='projekt-card'),
     path('projekt-card/<int:pk>/embed', views.ProduktCardDetailView.as_view( embed=True, ), name='projekt-card-embed'),
 
+    # SEARCH & FILTERS
+    path('projekte/<slug:type>/search', views.GenericSearchView.as_view(), name='generic-search-products'),
+    path('projekte/search', views.SearchProductsView.as_view(), name='search-products'),
+        # - FILTERS
+    path('projekte/', views.ProductsView.as_view(), name='products'),
+    path('projekte/filter/<slug:filter>/', views.FilterProductsView.as_view(), name='products-filter-view'),
+
+
+
 
     path('projekt/<int:pk>/freigeben', views.ProductPublish.as_view(  ), name='product-publish'),
 

+ 65 - 11
marktplatz/views.py

@@ -328,6 +328,8 @@ class ProductsView(generic.ListView):
         context['status_list'] = Product.STATUS
         context['sponsor_cards'] =  Template( config.SPONSOR_CARDS ).render( Context(context) )
         context['main_card'] =      Template( config.MAIN_CARD ).render( Context(context) )
+        context['type'] = 'BASE'
+
         context['textSearchForm'] = textSearchForm()
 
         return context
@@ -338,37 +340,53 @@ class WohnprojekteView(ProductsView):
     context_object_name = 'object_list'
 
     def get_context_data(self, **kwargs):
-            context = super().get_context_data(**kwargs)
+        context = super().get_context_data(**kwargs)
 
-            raum_agebote = {}
+        raum_agebote = {}
 
-            for product in context['object_list']:
-                for raum in product.raumangebot:
-                    if not (raum in raum_agebote):
-                        raum_agebote[raum] = product.raumangebot.choices[raum]
+        for product in context['object_list']:
+            for raum in product.raumangebot:
+                if not (raum in raum_agebote):
+                    raum_agebote[raum] = product.raumangebot.choices[raum]
 
-            context['raum_agebote_dict'] = raum_agebote
-            context['frei_list'][0] =  ('JAJA', 'Platz frei')
-            context['altneu_list'] = Wohnprojekt.ALTNEU
+        context['raum_agebote_dict'] = raum_agebote
+        context['frei_list'][0] =  ('JAJA', 'Platz frei')
+        context['altneu_list'] = Wohnprojekt.ALTNEU
+        context['type'] = 'WOHN'
 
-            return context
+        return context
 
 class MobilitaetsProjekteView(ProductsView):
     model = MobilitaetsProjekt
     template_name = 'marktplatz/product_overview.html'
     context_object_name = 'object_list'
 
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context['type'] = 'MOBI'
+        return context
+
 
 class ErnaerungsProjekteView(ProductsView):
     model = ErnaehrungsProjekt
     template_name = 'marktplatz/product_overview.html'
     context_object_name = 'object_list'
 
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context['type'] = 'ERNA'
+        return context
+
+
 class EnergyProjekteView(ProductsView):
     model = EnergyProjekt
     template_name = 'marktplatz/product_overview.html'
     context_object_name = 'object_list'
 
+    def get_context_data(self, **kwargs):
+        context = super().get_context_data(**kwargs)
+        context['type'] = 'ENER'
+        return context
 
 
 class FilterProductsView(ProductsView):
@@ -422,6 +440,7 @@ class SearchProductsView(ProductsView):
         if qform.is_valid():
             self.object_list = self.get_queryset(qfilter= qform.cleaned_data["searchText"]  )
 
+
         allow_empty = self.get_allow_empty()
 
         if not allow_empty:
@@ -437,12 +456,47 @@ class SearchProductsView(ProductsView):
                     'class_name': self.__class__.__name__,
                 })
         context = self.get_context_data()
-        print(context)
+        context['type']=   kwargs['type']
         return self.render_to_response(context)
 
 
 
 
+class GenericSearchView(SearchProductsView):
+
+
+    def  dispatch(self, request, *args, **kwargs):
+
+        print( kwargs['type'] )
+        if self.kwargs['type'] == 'BASE':
+            return super().dispatch(request, *args, **kwargs)
+        elif self.kwargs['type'] == 'WOHN':
+            self.model = Wohnprojekt
+            self.form_class = WohnprojektForm
+            return super().dispatch(request, *args, **kwargs)
+        elif self.kwargs['type'] == 'MOBI':
+            self.model = MobilitaetsProjekt
+            self.form_class = MobilitaetsForm
+            return super().dispatch(request, *args, **kwargs)
+        elif self.kwargs['type'] == 'ERNA':
+            self.model = ErnaehrungsProjekt
+            self.form_class = ErnaehrungsForm
+            return super().dispatch(request, *args, **kwargs)
+        elif self.kwargs['type'] == 'ENER':
+            self.model = EnergyProjekt
+            self.form_class = EnergyForm
+            return super().dispatch(request, *args, **kwargs)
+
+
+
+
+
+
+
+
+
+
+
 class ProductsListView(generic.ListView):
     model = Product
     template_name='marktplatz/object_list.html'