Juan Carlos 5 år sedan
förälder
incheckning
85b1c90a9f
5 ändrade filer med 111 tillägg och 115 borttagningar
  1. 51 64
      marktplatz/models.py
  2. 49 32
      marktplatz/signals.py
  3. 8 17
      marktplatz/views.py
  4. 1 1
      project_base/apps.py
  5. 2 1
      project_base/settings.py

+ 51 - 64
marktplatz/models.py

@@ -9,6 +9,7 @@ from django.core.validators import MinValueValidator, MaxValueValidator
 from django.contrib.auth.models import User
 from django.core.files.storage import FileSystemStorage
 from django_countries.fields import CountryField
+from django.urls import reverse
 
 from django.db import models
 from django.dispatch import receiver
@@ -128,79 +129,65 @@ class Category(models.Model):
 
 class Product(models.Model):
 
-    # def save(self, update_fields=None, *args, **kwargs):
-    #     print(kwargs)
-    #     print(args)
-    #     print (update_fields)
-    #     # update_fields = ['frei']
-    #     super().save(*args, **kwargs)  # Call the "real" save() method.
 
     #https://stackoverflow.com/questions/1355150/when-saving-how-can-you-check-if-a-field-has-changed
-    __original_frei = None
+
 
     def __init__(self, *args, **kwargs):
         super(Product, self).__init__(*args, **kwargs)
-        self.__original_frei = self.frei
-
 
-    def save(self, update_fields=None, *args, **kwargs):
-        print ("is this workig?")
+    def save(self, update_fields=None,  *args, **kwargs):
+        # print ("is this workig?")
+        # if self.frei != self.__original_frei and self.frei == "JAJA":
+        #     print ( "activates --------")
+        #     self.frei_activated = True
 
-
-        print ('update_fields: ', update_fields)
+        # print ('update_fields: ', update_fields)
         # post_save.connect(search_agent)
-        if self.frei != self.__original_frei and self.frei == "JAJA":
-            for agent in SearchAgent.objects.all():
-                for agentOrt in agent.ort:
-                    print(agentOrt)
-                    if agentOrt == self.ort:
-                        print ('send_mail')
-
-                        context = {}
-
-                        context['product_name']=self.name
-                        context['product_claim']=self.claim
-                        context['product_beschreibung']=self.beschreibung
-                        context['product_learning']=self.learning
-                        context['product_gruendungsjahr']=self.gruendungsjahr
-                        context['product_betriebgenommen']=self.betriebgenommen
-                        context['product_status']=self.status
-                        context['product_adresse']=self.adresse
-                        context['product_plz']=self.plz
-                        context['product_adresse_zusatz']=self.adresse_zusatz
-                        context['product_ort']=self.ort
-                        context['product_website']=self.website
-                        context['product_email']=agent.hash
-                        context['agent_hash']=self.email
-
-
-
-                        context['recipient'] = [ agent.email, ]
-                        context['msg_subject' ] = ('Gemeinschaffen - ' + self.name )
-
-                        mail.send(
-                            context['recipient'],
-                            config.EMAIL_NOREPLY,
-                            context = context,
-                            template='generic',
-                            headers={  'Reply-To': context['product_email']  },
-                            priority='now',
-                        )
 
+        # if self.frei != self.__original_frei and self.frei == "JAJA":
+        #     for agent in SearchAgent.objects.all():
+        #         for agentOrt in agent.ort:
+        #             print(agentOrt)
+        #             if agentOrt == self.ort:
+        #                 print ('send_mail')
+        #
+        #                 context = {}
+        #
+        #                 print (  reverse('search-agent-delete' , kwargs={ 'pk': agent.pk, 'hash': agent.hash }   )  )
+        #
+        #                 context['product_name']=self.name
+        #                 context['product_claim']=self.claim
+        #                 context['product_beschreibung']=self.beschreibung
+        #                 context['product_learning']=self.learning
+        #                 context['product_gruendungsjahr']=self.gruendungsjahr
+        #                 context['product_betriebgenommen']=self.betriebgenommen
+        #                 context['product_status']=self.status
+        #                 context['product_adresse']=self.adresse
+        #                 context['product_plz']=self.plz
+        #                 context['product_adresse_zusatz']=self.adresse_zusatz
+        #                 context['product_ort']=self.ort
+        #                 context['product_website']=self.website
+        #                 context['product_email']=agent.hash
+        #                 context['agent_hash']=self.email
+        #
+        #
+        #
+        #                 context['recipient'] = [ agent.email, ]
+        #                 context['msg_subject' ] = ('Gemeinschaffen - ' + self.name )
+        #
+        #                 mail.send(
+        #                     context['recipient'],
+        #                     config.EMAIL_NOREPLY,
+        #                     context = context,
+        #                     template='generic',
+        #                     headers={  'Reply-To': context['product_email']  },
+        #                     priority='now',
+        #                 )
 
-        super().save( update_fields=update_fields, *args, **kwargs)  # Call the "real" save() method.
-        self.__original_frei = self.frei
-        # super().save(update_fields=update_fields, *args, **kwargs)  # Call the "real" save() method.
 
-    # def save(self, *args, update_fields=[''], **kwargs):
+        super().save( update_fields=update_fields, *args, **kwargs)  # Call the "real" save() method.
 
-    #
-    #
-    #     # super(Product, self).save(force_insert, force_update, update_fields=['frei'], *args, **kwargs)
-    #     print ("savingg.....")
-    #     super().save(*args,  update_fields=['frei'], **kwargs)
-    #     print ("saved ++++++++")
-    #
 
     STATUS = [
         ('ENT', 'Entwicklung'),
@@ -457,8 +444,8 @@ class Wohnprojekt(Product):
     wohnbaufoerderung = CharField    ( 'Wohnbauförderung',    max_length = 1024,   choices=WOHNBAUFOERDERUNG, help_text="Wohnbauförderung", null = True, blank=True )
     artmodell         = TextField    ( 'Art der Modells',    max_length = 2048,   help_text="Art der Modells", null = True, blank=True )
     bautraeger        = TextField    ( 'Bauträger',    max_length = 2048, help_text="Bauträger", null = True, blank=True )
-    aerwachsene       = IntegerField( 'Anzahl an Erwachsenen', help_text="Anzahl an Erwachsenen", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
-    akinder           = IntegerField( 'Anzahl an Kinder', help_text="Anzahl an Kinder", validators=[MinValueValidator(0), MaxValueValidator(9999)], null = True, blank=True )
+    aerwachsene       = IntegerField( 'Anzahl an Erwachsenen', help_text="Anzahl an Erwachsenen", validators=[MinValueValidator(0), MaxValueValidator(9999)], default = 0, null = True, blank=False )
+    akinder           = IntegerField( 'Anzahl an Kinder', help_text="Anzahl an Kinder", validators=[MinValueValidator(0), MaxValueValidator(9999)], default = 0,  null = True, blank=False )
     @property
     def amitglieder(self):
             return self.aerwachsene + self.akinder
@@ -482,7 +469,7 @@ class Wohnprojekt(Product):
     zielgruppen        = CharField         ( 'Besondere Zielgruppen',  max_length = 64, help_text="Besondere Zielgruppen", null = True, blank=True )
     gprojekte          = CharField         ( 'Gemeinschaftliche Projekte',  max_length = 64, help_text="Gemeinschaftliche Projekte", null = True, blank=True )
     oekologie          = CharField         ( 'Ökologie',  max_length = 1024, help_text="Ökologie", null = True, blank=True )
-    freiraumangebote   = CharField         ( 'Freiraumangebote',  max_length = 64, choices=FREIANGEBOT, help_text="Freiraumangebote", null = True, blank=False )
+    freiraumangebote   = CharField         ( 'Freiraumangebote',  max_length = 64, choices=FREIANGEBOT, help_text="Freiraumangebote", null = True, blank=True )
     gaestwohnungen     = IntegerField      ( 'Anzahl an Gästewohnungen', help_text="Anzahl an Gästewohnungen", validators=[MinValueValidator(0)], default = 0 )
 
 

+ 49 - 32
marktplatz/signals.py

@@ -1,7 +1,8 @@
 from django.dispatch import receiver
+from django.urls import reverse
 from django.db.models.signals import post_delete, post_save
 
-
+from constance import config
 from post_office import mail
 from django.core.mail import EmailMessage
 from django.core.mail import EmailMultiAlternatives
@@ -11,35 +12,51 @@ from .models import *
 
 
 @receiver(post_save, sender=Product)
+@receiver(post_save, sender=Wohnprojekt)
 def search_agent(sender, instance, update_fields=None, **kwargs):
-    print(instance)
-    print(sender)
-    print(update_fields)
-    if update_fields != None:
-        print(update_fields)
-        if 'frei' in update_fields:
-            print('frei updated')
-
-
-#
-#
-# @receiver(user_sign_up_attempt)
-# def handle_user_sign_up_attempt(sender, **kwargs):
-#     log(
-#         user=None,
-#         action="SIGNUP_ATTEMPTED",
-#         extra={
-#             "username": kwargs.get("username"),
-#             "email": kwargs.get("email"),
-#             "result": kwargs.get("result")
-#         }
-#     )
-#
-#
-# @receiver(user_signed_up)
-# def handle_user_signed_up(sender, **kwargs):
-#     log(
-#         user=kwargs.get("user"),
-#         action="USER_SIGNED_UP",
-#         extra={}
-#     )
+    # print(instance)
+    # print(sender)
+    # print(update_fields)
+    # print ( instance.current_uri )
+    # if update_fields != None:
+    #     print(update_fields)
+
+    if 'frei' in update_fields:
+        if instance.frei == 'JAJA' :
+            for agent in SearchAgent.objects.all():
+                for agentOrt in agent.ort:
+                    if agentOrt == instance.ort:
+
+                        context = {}
+
+                        context['product_name']=instance.name
+                        context['product_claim']=instance.claim
+                        context['product_beschreibung']=instance.beschreibung
+                        context['product_learning']=instance.learning
+                        context['product_gruendungsjahr']=instance.gruendungsjahr
+                        context['product_betriebgenommen']=instance.betriebgenommen
+                        context['product_status']=instance.status
+                        context['product_adresse']=instance.adresse
+                        context['product_plz']=instance.plz
+                        context['product_adresse_zusatz']=instance.adresse_zusatz
+                        context['product_ort']=instance.ort
+                        context['product_website']=instance.website
+                        context['current_uri']=instance.current_uri
+
+                        context['agent_delete_url']= instance.current_uri + reverse(  'search-agent-delete' , kwargs={ 'pk': agent.pk, 'hash': agent.hash }   )
+
+                        context['agent_email'] = agent.email
+                        context['agent_hash']  = agent.hash
+
+                        context['recipient'] = [ agent.email, ]
+                        context['msg_subject' ] = ('Gemeinschaffen - ' + instance.name )
+
+
+                        mail.send(
+                            context['recipient'],
+                            config.EMAIL_NOREPLY,
+                            context = context,
+                            template='generic',
+                            headers={  'Reply-To': context['agent_email']  },
+                            priority='now',
+                        )

+ 8 - 17
marktplatz/views.py

@@ -586,11 +586,11 @@ class EditView(LoginRequiredMixin, FormView):
 
         context['product'] = WohnprojektForm(instance=Wohnprojekt.objects.get(pk=pk))
 
-        linkFormSet = inlineformset_factory(Product,Link, form=LinkForm, extra=0)
-        myLinkFormSet = linkFormSet(instance=  Product.objects.get(pk=pk)  )
-        context['lnks'] =   myLinkFormSet
+        # linkFormSet = inlineformset_factory(Product,Link, form=LinkForm, extra=0)
+        # myLinkFormSet = linkFormSet(instance=  Product.objects.get(pk=pk)  )
+        # context['lnks'] =   myLinkFormSet
+        # context['lnks_helper'] =    FormsetHelper()
 
-        context['lnks_helper'] =    FormsetHelper()
         context['use_ajax']    =    True
         context['info_txt'] = Template(config.INFO_TXT).render(Context(context))
 
@@ -599,26 +599,17 @@ class EditView(LoginRequiredMixin, FormView):
     def post(self, request, pk):
 
         # print (  request.POST.dict()  )
+        # https://stackoverflow.com/questions/35879101/how-to-determine-if-a-field-has-changed-in-a-django-modelform/43550210
+        # print ('product_f.changed_data: ',  product_f.changed_data)
         product_f = WohnprojektForm(request.POST, request.FILES, instance=Wohnprojekt.objects.get(pk=pk))
 
         if product_f.is_valid():
-            # https://stackoverflow.com/questions/35879101/how-to-determine-if-a-field-has-changed-in-a-django-modelform/43550210
             if product_f.has_changed():
-                update_fields = product_f.changed_data
                 product =  product_f.save( commit=False )
-                print ('product_f.changed_data: ',  product_f.changed_data)
-
+                update_fields = product_f.changed_data
+                product.current_uri = request.build_absolute_uri( '/' ).rstrip('/')
                 product.save( update_fields=update_fields )
 
-            # product = product_f.save()
-            # for lnk in lnks_f:
-            #    if lnk.is_valid():
-            #        print( "link valid   ......................." )
-            #        lnk_ = lnk.save(commit=False)
-            #        lnk_.product = product
-            #        lnk_.save()
-
-
             if 'addImage' in request.POST:
                 return HttpResponseRedirect(reverse('add-Image', kwargs={'pk': pk}))
 

+ 1 - 1
project_base/apps.py

@@ -51,7 +51,7 @@ class AuthConfigBase(AuthConfig):
         post_migrate.connect(create_admin, sender=self)
 
 content_html = """
-<table><tbody><tr><td><h2>&nbsp;gemeinschaffen.com </h2></td></tr><tr><td><h3>name</h3><p>{{product_name}}</p><h3>claim</h3><p>{{product_claim}}</p><h3>beschreibung</h3><p>{{product_beschreibung}}</p><h3>learning</h3><p>{{product_learning}}</p><h3>status</h3><p>{{product_status}}</p><h3>adresse</h3><p>{{product_adresse}}</p><h3>plz</h3><p>{{product_plz}}</p><h3>adresse_zusatz</h3><p>{{product_adresse_zusatz}}</p><h3>ort</h3><p>{{product_ort}}</p><h3>website</h3><p>{{product_website}}</p><h3>email</h3><p>{{product_email}}</p></td></tr><tr><td>&nbsp;<a href="https://gemeinschaffen.com/mab/products/">gemeinschaffen.com</a></td></tr></tbody></table><p>&nbsp;</p>
+<table><tbody><tr><td><h2>&nbsp;gemeinschaffen.com </h2></td></tr><tr><td><h3>name</h3><p>{{product_name}}</p><h3>claim</h3><p>{{product_claim}}</p><h3>beschreibung</h3><p>{{product_beschreibung}}</p><h3>learning</h3><p>{{product_learning}}</p><h3>status</h3><p>{{product_status}}</p><h3>adresse</h3><p>{{product_adresse}}</p><h3>plz</h3><p>{{product_plz}}</p><h3>adresse_zusatz</h3><p>{{product_adresse_zusatz}}</p><h3>ort</h3><p>{{product_ort}}</p><h3>website</h3><p>{{product_website}}</p><h3>email</h3><p>{{product_email}}</p></td></tr><tr><td>&nbsp;<a href="https://gemeinschaffen.com/mab/products/">gemeinschaffen.com</a><p><a href="{{agent_delete_url}}">Agent L&ouml;schen</a></p></td></tr></tbody></table><p>&nbsp;</p>
 """
 
 content_txt = strip_tags(content_html)

+ 2 - 1
project_base/settings.py

@@ -196,7 +196,8 @@ CONSTANCE_CONFIG = {
     'INFO_TXT': (INFO_TXT, 'Text to help with the fill in the submitform'),
     'SUBMIT_TEXT': (SUBMIT_TEXT, 'Text to welcome to the submitpage'),
     'ADMIN_EMAIL': ('juan@mediaarchitecture.org', 'Admin email'),
-    'WEBSITE_TITEL': ('Markplatz', 'Name of the website'),
+    'WEBSITE_TITEL': ('Markplatz', 'Name von der Webseite'),
+    'WEBSEITE_URI': ('gemeinschaffen.com', 'Url von der Webseite, zB. gemeinschaffen.com'),
     'LOGO_IMAGE': ('logo.png', 'Company logo', 'image_field'),
     'EMAIL_NOREPLY' : ('no-reply@gemeinschaffen.com', 'No-reply email')
 }