Juan Carlos 5 лет назад
Родитель
Сommit
f7f5c28828

+ 3 - 5
marktplatz/models.py

@@ -139,7 +139,7 @@ class Product(models.Model):
         super(Product, self).__init__(*args, **kwargs)
         self.__original_frei = self.frei
 
-    def save(self, force_insert=False, force_update=False, *args, **kwargs):
+    def save(self, force_insert=False, update_fields=[''], force_update=False, *args, **kwargs):
         if self.frei != self.__original_frei:
             if self.frei == "JAJA":
                 for agent in SearchAgent.objects.all():
@@ -166,7 +166,7 @@ class Product(models.Model):
                             # )
 
 
-        super(Product, self).save(force_insert, force_update, *args, **kwargs)
+        super(Product, self).save(force_insert, force_update, update_fields=['frei'], *args, **kwargs)
         self.__original_frei = self.frei
 
     STATUS = [
@@ -215,8 +215,6 @@ class Product(models.Model):
         ('1230', '23., Liesing'),
         ('GERM', 'Deutschland'),
         ('SCHW', 'Schweiz'),
-        ('GERM', 'Germany'),
-        ('GERM', 'Germany'),
         ('VORA', 'Vorarlberg'),
         ('TIRO', 'Tirol'),
         ('SALZ', 'Salzburg'),
@@ -304,7 +302,7 @@ def auto_delete_reverse_keys(sender, instance, **kwargs):
         instance.interaction.delete()
 
 @receiver(post_save, sender=Product)
-def search_agent(sender, instance, created, raw, using, update_fields, **kwargs):
+def search_agent(sender, instance, **kwargs):
     print(instance)
     print(sender)
     print(update_fields)

+ 2 - 0
marktplatz/templates/marktplatz/admin_panel.html

@@ -47,6 +47,8 @@
 
 <script type="text/javascript">
 
+/* for reference, eventually replace the call of onclick */
+
   function changeCheck(elem){
   if(elem.checked){
     elem.setAttribute('value', 'true')

+ 74 - 44
marktplatz/templates/marktplatz/product_overview.html

@@ -21,6 +21,7 @@ $(document).ready(function(){
 
     });
 
+/*
     $("button#vote").click(function(){
         $(".card").show();
         $("button").removeClass("mark");
@@ -34,34 +35,13 @@ $(document).ready(function(){
            $("#how").fadeOut(10)
         }
     });
-
-     {% for category in cat_list %}
-
-    {% if category %}
-
-    $("[id='{{category.short_name|cut:" "}}']").click(function(){
-        $(".card").show();
-        $("button").removeClass("mark");
-
-        $(".card").not(".{{category.short_name|cut:" "}}").hide();
-        $("[id='{{category.short_name|cut:" "}}']").addClass("mark");
-
-        if($(".card").filter(":visible").length < 1){
-            $("#how").fadeIn(200)
-        } else{
-           $("#how").fadeOut(10)
-        }
-    });
-
-    {% endif %}
-
-    {% endfor %}
+*/
 
 
     {% for country in count_list %}
 
     {% if country %}
-
+/*
     $("[id='{{country.code}}']").click(function(){
         $(".card").show();
         $("button").removeClass("mark");
@@ -76,13 +56,13 @@ $(document).ready(function(){
         }
 
     });
-
+*/
     {% endif %}
 
     {% endfor %}
 
     {% for year in year_list %}
-
+/*
     $("[id='{{year}}']").click(function(){
         $(".card").show();
         $("button").removeClass("mark");
@@ -97,9 +77,49 @@ $(document).ready(function(){
         }
 
     });
+*/
+    {% endfor %}
+
+
+
+    {% for key, value in ort_dict.items %}
+    /*
+      $(".{{ key }}").click(function(){
+         $(".card").show();
+         $("button").removeClass("mark");
+
+         $(".card").not(".{{ key }}").hide();
+         $("button .{{ key }}").addClass("mark");
+
+         if($(".card").filter(":visible").length < 1){
+           $("#how").fadeIn(200)
+         } else{
+           $("#how").fadeOut(10)
+         }
+
+      });
+      */
 
     {% endfor %}
 
+    $(".btn-toggle").click (function(elem){
+
+       let toggler = this.getAttribute("toggler");
+       console.log(toggler);
+       $(".card").show();
+       $("button").removeClass("mark");
+
+       $(".card").not("." + toggler).hide();
+       $("button ." + toggler).addClass("mark");
+
+       if($(".card").filter(":visible").length < 1){
+         $("#how").fadeIn(200)
+       } else{
+         $("#how").fadeOut(10)
+       }
+
+    });
+
 
 });
 </script>
@@ -148,8 +168,14 @@ $(document).ready(function(){
 
     color: black;
     margin-top: 0px;
+}
+    .mab-card-highlight {
+
+      background-color: #f0faf0;
+
+    }
+
 
-  }
 
 </style>
 
@@ -172,17 +198,23 @@ $(document).ready(function(){
       {% if user.is_authenticated %}
       <button id='vote' class="border-thin mybtn " style="margin-right: 2px;margin-bottom: 2px">#Not Voted</button>
       {% endif %}
-      {% for category in cat_list %}
-      <button id='{{category.short_name}}' class="border-thin mybtn " style="margin-right: 2px;margin-bottom: 2px">#{{category.name}}</button>
-      {% endfor %}
 
-      {% for year in year_list %}
-      <button id='{{year}}' class="border-thin mybtn " style="margin-right: 2px;margin-bottom: 2px">#{{year}}</button>
-      {% endfor %}
 
-    {% for country in count_list %}
-                <button id='{{country.code}}' class="border-thin mybtn " style="margin-right: 2px;margin-bottom: 2px" >#{{country.name}}</button>
-    {% endfor %}
+        {% for elem in frei_list %}
+                    <button id='{{elem.0}}' toggler='{{elem.0}}' class="border-thin mybtn btn-toggle elem.0" style="margin-right: 2px;margin-bottom: 2px" >#{{elem.1}}</button>
+        {% endfor %}
+
+
+
+        {% for key, value in ort_dict.items %}
+        <button class="border-thin mybtn btn-toggle {{key}}"  toggler='{{key}}' style="margin-right: 2px;margin-bottom: 2px" >#{{value}}</button>
+        {% endfor %}
+
+        {% for elem in altneu_list %}
+        <button class="border-thin mybtn btn-toggle {{elem.0}}"  toggler='{{elem.0}}' style="margin-right: 2px;margin-bottom: 2px" >#{{elem.1}}</button>
+        {% endfor %}
+
+
 
       </div>
 </div>
@@ -201,10 +233,11 @@ $(document).ready(function(){
 
   {{main_card|safe}}
 
+  {% for product in wohnprojekt_list %}
 
-  {% for product in product_list %}
+  {{ product.wohnprojekt }}
 
-  <div class="mab-card {% for name in product.country %} {{name.code}} {% endfor %} {{product.year}} {% for category in product.category.all %} {{category.short_name}} {% endfor %} card rounded-0 border-0 {% if user.is_authenticated %} {% get_vote_class product user %} {% endif %}" style="">
+  <div class="mab-card  {{product.ort}} {{product.status}} {{product.frei}} {{product.altneu}} {% if product.frei == 'JAJA' %} mab-card-highlight {% endif %} card rounded-0 border-0 " style="">
     <a href="{% url 'product-detail' product.pk %}">
       <div style="position: relative;text-align: center;">
         <img class="{% if user.is_authenticated %}{% get_vote_class product user %} {% endif %} {% for category in product.category.all %} {{category.short_name}} {% endfor %} card-img-top rounded-0" src="{{product.media_set.first.image_norm.url}}" alt="image">
@@ -221,15 +254,12 @@ $(document).ready(function(){
       </div>-->
 
       <p class="mab-card-text card-text" style="">
-        {% for name in product.country %}
-        <button id='{{name.code}}' class="border-thin mybtn" style="">#{{name.name}}</button>
-        {% endfor %}
 
-        <button id='{{product.year}}' class="border-thin mybtn" style="">#{{product.year}}</button>
+        <button id='product_{{product.pk}}_{{product.frei}}' toggler='{{product.frei}}' class="border-thin mybtn btn-toggle {{product.frei}}" style="">#{{product.get_frei_display}}</button>
+        <button id='product_{{product.pk}}_{{product.status}}' toggler='{{product.status}}' class="border-thin mybtn btn-toggle {{product.status}}" style="">#{{product.get_status_display}}</button>
+        <button id='product_{{product.pk}}_{{product.ort}}' toggler='{{product.ort}}' class="border-thin mybtn btn-toggle {{product.ort}}" style="">#{{product.get_ort_display}}</button>
+        <button id='product_{{product.pk}}_{{product.altneu}}' toggler='{{product.altneu}}' class="border-thin mybtn btn-toggle {{product.altneu}}" style="">#{{product.get_altneu_display}}</button>
 
-        {% for category in product.category.all %}
-        <button id='{{category.short_name}}' class="border-thin mybtn" style="">#{{category.name}}</button>
-        {% endfor %}
       </p>
     </div>
   </div>

+ 10 - 1
marktplatz/templatetags/tags.py

@@ -1,5 +1,8 @@
-from django import template
 from PIL import Image
+
+from django import template
+from django.template.defaulttags import register
+
 from django.conf import settings
 from django.db.models import Avg
 
@@ -43,6 +46,12 @@ def field_name(obj, field):
 
 
 
+...
+@register.filter
+def get_item(dictionary, key):
+    return dictionary.get(key)
+
+
 
 @register.simple_tag
 def get_vote(Product, user):

+ 38 - 18
marktplatz/views.py

@@ -81,17 +81,21 @@ class SearchAgentCreate(CreateView):
     success_url = reverse_lazy('products')
 
 class ProductsView(generic.ListView):
-    model = Product
+    model = Wohnprojekt
     #context_object_name = 'Products'
     # show the best 4 website finish
 
     def get_queryset(self):
         # original qs
         qs = super().get_queryset()
+
         self.user = self.request.user
         user = self.user
-        if user.groups.filter(name='jury').exists():
-            return qs.filter(sumbitted = config.CURRENT_EVENT)
+
+        # if user.groups.filter(name='jury').exists():
+        #     return qs.filter(sumbitted = config.CURRENT_EVENT)
+
+        qs = qs.order_by('frei')
 
         if user.groups.filter(name='submission').exists():
             contact = Contact.objects.get(user=user)
@@ -100,6 +104,7 @@ class ProductsView(generic.ListView):
         if user.is_superuser:
             return qs
 
+
         return qs.filter(public = True)
 
     def get_context_data(self, **kwargs):
@@ -107,22 +112,33 @@ class ProductsView(generic.ListView):
             user =self.request.user
             context['user'] = user
             used_countries = []
+            orts = {}
+
 
 
             years = {''}
-            for product in context['product_list']:
+            for product in context['wohnprojekt_list']:
                 if not years.__contains__(product.year):
                     years.add(product.year)
                 for country in product.country:
                     if not used_countries.__contains__(country):
                         used_countries.append(country)
+                # if not used_orts.__contains__(  product.get_ort_display()  ):
+                if not product.ort in orts:
+                    orts[product.ort] = product.get_ort_display()
+
+
+
 
             years.remove('')
             context['year_list'] = years
             context['count_list'] = used_countries
+            context['frei_list'] = Product.FREI
+            context['status_list'] = Product.STATUS
+            context['ort_dict'] = orts
 
+            context['altneu_list'] = Wohnprojekt.ALTNEU
 
-            context['cat_list'] = Category.objects.all
 
             context['sponsor_cards'] =  Template( config.SPONSOR_CARDS ).render( Context(context) )
             context['main_card'] =      Template( config.MAIN_CARD ).render( Context(context) )
@@ -235,26 +251,26 @@ class AdminView(LoginRequiredMixin, generic.ListView):
         for elemk in public:
             # print(elemk + " -  " + public[elemk] )
             keys = elemk.split(".")
-            now_Product = Product.objects.get(pk=keys[1])
+            current_product = Product.objects.get(pk=keys[1])
             if public[elemk] == 'true':
-                now_Product.public = True
-                now_Product.save()
+                current_product.public = True
+                current_product.save()
             else:
-                now_Product.public = False
-                now_Product.save()
+                current_product.public = False
+                current_product.save()
 
         edit = {k: v for k, v in context.items() if k.startswith('product_e')}
         # print (edit)
         for elemk in edit:
             # print(elemk + " -  " + edit[elemk] )
             keys = elemk.split(".")
-            now_Product = Product.objects.get(pk=keys[1])
+            current_product = Product.objects.get(pk=keys[1])
             if edit[elemk] == 'true':
-                now_Product.edit = True
-                now_Product.save()
+                current_product.edit = True
+                current_product.save()
             else:
-                now_Product.edit = False
-                now_Product.save()
+                current_product.edit = False
+                current_product.save()
 
         return HttpResponseRedirect('')
 
@@ -608,11 +624,15 @@ class EditView(FormView):
             update_fields = []
             # https://stackoverflow.com/questions/35879101/how-to-determine-if-a-field-has-changed-in-a-django-modelform/43550210
             if product_f.has_changed():
+                product =  product_f.save(  commit=False )
                 if 'frei' in product_f.changed_data:
-                    print('frei changed')
-                product_f.save( )
+                    product.save(  update_fields=['frei']   )
+                else:
+                    product.save(  )
+
+
 
-            product = product_f.save()
+            # product = product_f.save()
             # for lnk in lnks_f:
             #    if lnk.is_valid():
             #        print( "link valid   ......................." )

+ 2 - 2
project_base/apps.py

@@ -38,7 +38,7 @@ def create_admin(sender=None, **kwargs):
 class project_base(AppConfig):
     name = 'project_base'
     def ready(self):
-        print("base ready")
+        # print("base ready")
         super().ready()
         post_migrate.connect(create_admin, sender=self)
 
@@ -46,7 +46,7 @@ class project_base(AppConfig):
 class AuthConfigBase(AuthConfig):
 
     def ready(self):
-        print("base ready")
+        # print("base ready")
         super().ready()
         post_migrate.connect(create_admin, sender=self)