Просмотр исходного кода

embed, email template, admin create

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

+ 14 - 0
marktplatz/apps.py

@@ -1,5 +1,19 @@
 from django.apps import AppConfig
+from django.contrib.auth.models import User
 
 
+
+
+# import django
+# django.setup()
+
 class marktplatzConfig(AppConfig):
     name = 'marktplatz'
+
+    def ready(self):
+
+        u = User(username='admin')
+        u.set_password('admin_pass')
+        u.is_superuser = True
+        u.is_staff = True
+        u.save()

+ 18 - 0
marktplatz/models.py

@@ -148,6 +148,24 @@ class Product(models.Model):
                         if agentOrt == self.ort:
                             print ('send_mail')
 
+                            # context [] 
+                            # context ['base_uri'] =  self.request.build_absolute_uri( '/' ).rstrip('/')
+                            # context['recipient'] = [ myActivity.contact.email, ]
+                            # context['msg_subject' ] =  _('Activity created')
+                            # context['msg_content' ] = "\n" + "<br/>" + \
+                            #         _("Title: ")               + form.cleaned_data['title']        + "\n" + "<br/><br/>" + \
+                            #         _('Description: ')         + form.cleaned_data['description']  + "\n" + "<br/>"
+                            #
+                            # mail.send(
+                            #     context['recipient'],
+                            #     config.EMAIL_NOREPLY,
+                            #     context = context,
+                            #     template='generic',
+                            #     headers={  'Reply-To': context['email']  },
+                            #     priority='now',
+                            # )
+
+
         super(Product, self).save(force_insert, force_update, *args, **kwargs)
         self.__original_frei = self.frei
 

+ 59 - 0
marktplatz/receivers.py

@@ -0,0 +1,59 @@
+from django.dispatch import receiver
+
+from account.signals import password_changed
+from account.signals import user_sign_up_attempt, user_signed_up
+from account.signals import user_login_attempt, user_logged_in
+
+from pinax.eventlog.models import log
+
+
+@receiver(user_logged_in)
+def handle_user_logged_in(sender, **kwargs):
+    log(
+        user=kwargs.get("user"),
+        action="USER_LOGGED_IN",
+        extra={}
+    )
+
+
+@receiver(password_changed)
+def handle_password_changed(sender, **kwargs):
+    log(
+        user=kwargs.get("user"),
+        action="PASSWORD_CHANGED",
+        extra={}
+    )
+
+
+@receiver(user_login_attempt)
+def handle_user_login_attempt(sender, **kwargs):
+    log(
+        user=None,
+        action="LOGIN_ATTEMPTED",
+        extra={
+            "username": kwargs.get("username"),
+            "result": kwargs.get("result")
+        }
+    )
+
+
+@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={}
+    )

+ 1 - 0
marktplatz/urls.py

@@ -13,6 +13,7 @@ urlpatterns = [
     path('products/', views.ProductsView.as_view(), name='products'),
     path('suchagent/', views.SearchAgentCreate.as_view(), name='search-agent-create'),
     path('product/<int:pk>', views.DetailView.as_view(), name='product-detail'),
+    path('product/<int:pk>/embed', views.DetailView.as_view( embed=True, ), name='product-detail-embed'),
     path('votes/', views.VoteView.as_view(), name='vote-detail'),
     path('votescid/', views.CidView.as_view(), name='votecid-detail'),
     path('admin_panel/', views.AdminView.as_view(), name='admin-panel'),

+ 6 - 3
marktplatz/views.py

@@ -136,10 +136,13 @@ class ProductsView(generic.ListView):
 class DetailView(generic.DetailView):
     model = Product
     template_name = 'marktplatz/product_detail.html'
-
+    embed = False
 
     def get_context_data(self, **kwargs):
-            context = super().get_context_data(**kwargs)
+            # context = super().get_context_data(**kwargs)
+
+            if self.embed :
+                kwargs['embed']       = True
             # context['credits'] = Credit.objects.select_related().get(product = self.kwargs['pk'])
             # context['descriptions'] = Description.objects.select_related().get(product = self.kwargs['pk'])
             # context['interactions'] = Interaction.objects.select_related().get(product=self.kwargs['pk'])
@@ -148,7 +151,7 @@ class DetailView(generic.DetailView):
             # print (context)
             # print (context['object'])
             # print (context['product'])
-            return context
+            return super().get_context_data(**kwargs)
 
 
     def post(self, request, *args, **kwargs):

+ 64 - 0
project_base/apps.py

@@ -1,4 +1,68 @@
+from django.apps import AppConfig
 from constance.apps import ConstanceConfig
+from post_office.apps import PostOfficeConfig
+
+from django.template.loader import render_to_string, get_template
+from django.utils.html import strip_tags
+
 
 class ConstanceBase(ConstanceConfig):
     verbose_name = "Configuration"
+
+class project_base(AppConfig):
+    name = 'project_base'
+    def ready(self):
+        from django.contrib.auth.models import User
+
+        print("ready")
+        user = User.objects.update_or_create(username='admin',
+                                defaults={
+                                 'email':'admin@server.com',
+                                 'password':'admin_pass',
+                                 'is_superuser': 'True',
+                                 'is_staff': 'True' }
+                                 )
+        u = User.objects.get(username='admin')
+        u.set_password('admin_pass')
+        u.save()
+
+class PostOfficeBase(PostOfficeConfig):
+
+    def ready(self):
+
+        from post_office.models import EmailTemplate
+        EmailTemplate.objects.update_or_create(
+            name='generic',
+            defaults={
+            'subject'      :  'Neue Nachricht von gemeinschaffen.at',
+            'description'  :  'Generic template',
+            'html_content' :  "content html",
+            'content'      :  "content"}
+            )
+
+        super().ready()
+
+
+
+
+#
+#
+# def db_table_exists(table_name):
+#     return table_name in connection.introspection.table_names()
+#
+# if db_table_exists(  'post_office_emailtemplate' ):
+#
+#
+#     tFile =  get_template('streets/email/generic.html')
+#     with open( str(tFile.template.origin), 'r') as file:
+#         tContentHTML = file.read()
+#         tContent =  strip_tags(tContentHTML)
+#
+#     EmailTemplate.objects.update_or_create(
+#         name='generic',
+#         defaults={
+#         'subject'      :  _('Message from pop-up.wien'),
+#         'description'  :  'Generic template',
+#         'html_content' :  tContentHTML,
+#         'content'      :  tContent}
+#         )

+ 2 - 1
project_base/settings.py

@@ -222,7 +222,8 @@ INSTALLED_APPS = [
     'django_countries',
     'captcha',
     'debug_toolbar',
-    'post_office',
+    'project_base.apps.PostOfficeBase',
+    'project_base.apps.project_base',
 ]
 
 CRISPY_TEMPLATE_PACK = 'bootstrap4'

+ 27 - 26
project_base/templates/base_generic.html

@@ -24,41 +24,42 @@
     {% endblock %}
 </head>
 <body>
-    {% block navbar %}
 
- <nav class="navbar navbar-expand-sm navbar-fixed-top" style="padding-left: 15px; padding-bottom: 0px; margin-bottom: 2px" >
-     <div class="container-fluid rounded-0" style="padding-left: 2px">
-  <a class="navbar-brand navbar-right" href="{% url 'products' %}">
-     <img src="{% static 'newMAB.png' %}" alt="MAB20" height="40px" width="auto" style="margin: auto; padding-bottom: 2px" >
-  </a>
+    {% if not embed %}
+    {% block navbar %}
+    <nav class="navbar navbar-expand-sm navbar-fixed-top" style="padding-left: 15px; padding-bottom: 0px; margin-bottom: 2px">
+      <div class="container-fluid rounded-0" style="padding-left: 2px">
+        <a class="navbar-brand navbar-right" href="{% url 'products' %}">
+          <img src="{% static 'newMAB.png' %}" alt="MAB20" height="40px" width="auto" style="margin: auto; padding-bottom: 2px">
+        </a>
 
         <button class="navbar-toggler" type="button " data-toggle="collapse" data-target="#navbarNavAltMarkup" aria-controls="navbarNavAltMarkup" aria-expanded="false" aria-label="Toggle navigation">
-            <span class="navbar-toggler-icon"></span> ⋁
+          <span class="navbar-toggler-icon"></span> ⋁
         </button>
-  <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
+        <div class="collapse navbar-collapse" id="navbarNavAltMarkup">
 
-    <div class="navbar-nav navbar-right">
-      <a class="nav-link active nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'products' %}">MARKTPLATZ</a>
-              <a class="nav-link active nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'submit' %}">EINREICHEN</a>
+          <div class="navbar-nav navbar-right">
+            <a class="nav-link active nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'products' %}">MARKTPLATZ</a>
+            <a class="nav-link active nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'submit' %}">EINREICHEN</a>
 
-        <a class=" nav-link active nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'about' %}">ÜBER UNS</a>
-        {% if not user.is_authenticated %}
-           <a class=" nav-link active nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'login' %}">EINLOGGEN</a>
-        {% endif %}
+            <a class=" nav-link active nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'about' %}">ÜBER UNS</a>
+            {% if not user.is_authenticated %}
+            <a class=" nav-link active nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'login' %}">EINLOGGEN</a>
+            {% endif %}
 
-        {% if user.is_authenticated %}
-        <a  class="nav-link nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'new-submit-view'%}?">PROJEKT EINREICHEN</a>
-        <a  class="nav-link nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'my-products'%}">MEINE PROJEKTE</a>
-        <a  class="nav-link nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'logout'%}?next={{request.path}}">AUSLOGGEN</a>
-        {% endif %}
-
-</div>
-    </div>
-  </div>
-</nav>
-    </div>
+            {% if user.is_authenticated %}
+            <a class="nav-link nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'new-submit-view'%}?">PROJEKT EINREICHEN</a>
+            <a class="nav-link nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'my-products'%}">MEINE PROJEKTE</a>
+            <a class="nav-link nav-right boldkur" style="color: black;    font-weight: bold;" href="{% url 'logout'%}?next={{request.path}}">AUSLOGGEN</a>
+            {% endif %}
 
+          </div>
+        </div>
+      </div>
+    </nav>
     {% endblock %}
+    {% endif %}
+
 
     <div class="container-fluid">
         {% block content %}