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

BIN
db.sqlite3.old → db.sqlite3.new


+ 1 - 1
marktplatz/models.py

@@ -275,7 +275,7 @@ class Product(models.Model):
     photo = CharField(max_length=500, null=True, blank=True, help_text="")
     videocts = CharField(max_length=500, null=True, blank=True, help_text="")
     category = ManyToManyField(Category,  help_text="",null = True, blank=True)
-    credits = ForeignKey(Credit, null = True,on_delete=models.SET_NULL, help_text="")
+    credits = ForeignKey(Credit, null = True, blank=True, on_delete=models.SET_NULL, help_text="")
     description = ForeignKey(Description,  on_delete=models.SET_NULL, help_text="",null = True, blank=True)
     contact = ForeignKey(Contact, null = True,on_delete=models.SET_NULL, help_text="")
     #interaction = ForeignKey(Interaction, null = True,on_delete = models.SET_NULL, help_text="")

+ 3 - 0
marktplatz/receivers.py

@@ -3,6 +3,9 @@ from post_office import mail
 from django.core.mail import EmailMessage
 from django.core.mail import EmailMultiAlternatives
 
+
+
+
 #
 #
 # @receiver(user_sign_up_attempt)

+ 22 - 9
marktplatz/templates/marktplatz/admin_panel.html

@@ -21,28 +21,42 @@
         <th scope="col"> submitted</th>
 
     </tr>
-    {% for Product in Product_list %}
+    {% for product in product_list %}
     <tr class=""   >
-        <td  scope="col"><img src="{{Product.media_set.first.image_small.url}}"  width="50" height="50" alt="{{ Product.pk }}"> </td>
-        <td  scope="col"> <a href="{% url 'product-detail' Product.pk %}">   {{Product.name|upper }} </a></td>
+        <td  scope="col"><img src="{{product.media_set.first.image_small.url}}"  width="50" height="50" alt="{{ product.pk }}"> </td>
+        <td  scope="col"> <a href="{% url 'product-detail' product.pk %}">   {{product.name|upper }} </a></td>
          <td scope="col">
-        {% for category in Product.category.all %}
+        {% for category in product.category.all %}
         {{category.short_name}}{% if not forloop.last %} | {% endif %}
              {% endfor %}
         </td>
         <td scope="col">
-    <input type="checkbox" class="form-check-input check" id="{{ Product.pk }}.public" name="{{ Product.pk }}.public" {% if Product.public %}checked="checked"{% endif %}>
-  </td>
+          <input type="checkbox" class="form-check-input check" id="{{ product.pk }}.public_dummy" name="dummy_product_p.{{ product.pk }}.public" {% if product.public %}checked value="true"{% else %} value="false" {% endif %} onclick="if(this.checked){ this.nextElementSibling.setAttribute('value', 'true') }else{ this.nextElementSibling.setAttribute('value', 'false') }">
+          <input type="hidden"  class="hidden" id="{{ product.pk }}.public" name="product_p.{{ product.pk }}.public" {% if product.public %}value="true"{% else %} value="false" {% endif %} >
+</td>
         <td scope="col">
-    <input type="checkbox" class="form-check-input check" id="{{ Product.pk }}.edit" name="{{ Product.pk }}.edit" {% if Product.edit %}checked="checked"{% endif %}>
+    <input type="checkbox" class="form-check-input check" id="{{ product.pk }}.edit_dummy" name="dummy_product_e.{{ product.pk }}.edit" {% if product.edit %}checked="checked"{% endif %} onclick="if(this.checked){ this.nextElementSibling.setAttribute('value', 'true') }else{ this.nextElementSibling.setAttribute('value', 'false') }" >
+    <input type="hidden"  class="hidden" id="{{ product.pk }}.edit" name="product_e.{{ product.pk }}.edit" {% if product.edit %}value="true"{% else %} value="false" {% endif %} >
  </td>
-        <td scope="col"> {{Product.sumbitted}} </td>
+        <td scope="col"> {{product.sumbitted}} </td>
 
     </tr>
     {% endfor %}
 
 
 
+<script type="text/javascript">
+
+  function changeCheck(elem){
+  if(elem.checked){
+    elem.setAttribute('value', 'true')
+  }else{
+    elem.setAttribute('value', 'false')
+}
+}
+
+</script>
+
 
  </table>
     <button  class="btn border-dark rounded-0 mybtn" type="submit">Submit </button>
@@ -52,4 +66,3 @@
     <p>You are not authorized to view this page. </p>
 {% endif %}
 {% endblock %}
-

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

@@ -6,8 +6,6 @@
 $('form').submit(function () {
 
 
-
-
     if () {
         alert('CID doubled');
         return false;

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

@@ -202,32 +202,32 @@ $(document).ready(function(){
   {{main_card|safe}}
 
 
-  {% for Product in Product_list %}
+  {% for product in product_list %}
 
-  <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="">
-    <a href="{% url 'product-detail' Product.pk %}">
+  <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="">
+    <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">
-        <div class="mab-Product-title" style="">{{Product.name|upper }}</div>
+        <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">
+        <div class="mab-product-title" style="">{{product.name|upper }}</div>
         {% if user.is_authenticated %}
-        <div class="mab-Product-vote" style="">{% get_vote Product user %}</div>
+        <div class="mab-product-vote" style="">{% get_vote product user %}</div>
         {% endif %}
       </div>
     </a>
     <div class="card-body mab-card-body" style="">
       <!--<div class="border-0 d-flex justify-content">
-        <p class="card-title" style="margin-bottom: 3px"><a href="{% url 'product-detail' Product.pk %}"> {{Product.header }} </a></p>
+        <p class="card-title" style="margin-bottom: 3px"><a href="{% url 'product-detail' product.pk %}"> {{product.header }} </a></p>
 
       </div>-->
 
       <p class="mab-card-text card-text" style="">
-        {% for name in Product.country %}
+        {% 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.year}}' class="border-thin mybtn" style="">#{{product.year}}</button>
 
-        {% for category in Product.category.all %}
+        {% for category in product.category.all %}
         <button id='{{category.short_name}}' class="border-thin mybtn" style="">#{{category.name}}</button>
         {% endfor %}
       </p>

+ 27 - 14
marktplatz/views.py

@@ -228,20 +228,33 @@ class AdminView(LoginRequiredMixin, generic.ListView):
             return context
 
     def post(self, request, *args, **kwargs):
-        for pk in request.POST.dict():
-            print(pk)
-            if not 'csrfmiddlewaretoken' in pk:
-                if request.POST[pk] != '' and ('public' in pk):
-                    pass
-                    #now_Product = Product.objects.get(pk=pk.split('.')[0])
-                    #now_Product.public = request.POST[pk].checktest
-                    #now_Product.save()
-
-                if request.POST[pk] != '' and ('edit' in pk):
-                    pass
-                    #now_Product = Product.objects.get(pk=pk.split('.')[0])
-                    #now_Product.edit = request.POST[pk].checktest
-                    #now_Product.save()
+        # print (request.POST.dict())
+        context = request.POST.dict()
+        public = {k: v for k, v in context.items() if k.startswith('product_p')}
+
+        for elemk in public:
+            # print(elemk + " -  " + public[elemk] )
+            keys = elemk.split(".")
+            now_Product = Product.objects.get(pk=keys[1])
+            if public[elemk] == 'true':
+                now_Product.public = True
+                now_Product.save()
+            else:
+                now_Product.public = False
+                now_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])
+            if edit[elemk] == 'true':
+                now_Product.edit = True
+                now_Product.save()
+            else:
+                now_Product.edit = False
+                now_Product.save()
 
         return HttpResponseRedirect('')
 

+ 5 - 3
project_base/apps.py

@@ -18,8 +18,8 @@ class ConstanceBase(ConstanceConfig):
 def create_admin(sender=None, **kwargs):
 
     from django.contrib.auth.models import User
+    from django.contrib.auth.models import Group
 
-    print("user post migrations")
     user = User.objects.update_or_create(username='admin',
                             defaults={
                              'email':'admin@server.com',
@@ -29,6 +29,10 @@ def create_admin(sender=None, **kwargs):
                              )
     u = User.objects.get(username='admin')
     u.set_password('admin_pass')
+
+    Group.objects.update_or_create(name='submission')
+    Group.objects.update_or_create(name='jury')
+
     u.save()
 
 class project_base(AppConfig):
@@ -48,8 +52,6 @@ class AuthConfigBase(AuthConfig):
 
 
 def create_emails(sender=None, **kwargs):
-    # Your specific logic here
-    print("post post migrations")
     from post_office.models import EmailTemplate
     EmailTemplate.objects.update_or_create(
         name='generic',