Exemple #1
0
 def auth_data(self):
     return {
         "username": setting("LAPOSTE_USERNAME"),
         "password": setting("LAPOSTE_PASSWORD"),
         "grant_type": "password",
         "client_id": setting("LAPOSTE_CLIENTID"),
         "client_secret": setting("LAPOSTE_SECRET"),
     }
Exemple #2
0
 def send_sms(self):
     over_target = setting('MISSIVE_PHONE', False)
     self.missive.target = over_target if over_target else self.missive.target
     if setting('MISSIVE_SERVICE', False):
         pass
     self.missive.status = choices.STATUS_SENT
     self.missive.save()
     logger.info("send sms: %s" % self.message, extra=self.extra)
     return self.missive.status
Exemple #3
0
 def email_attachments(self):
     if self.missive.attachments:
         logs = []
         for document in self.missive.attachments:
             if setting('MISSIVE_SERVICE', False):
                 self.email.attach(os.path.basename(document.name),
                                   document.read(), 'application/pdf')
             logs.append(os.path.basename(document.name))
         self.missive.logs['attachments'] = logs
     if setting('MISSIVE_SERVICE', False):
         self.email.send()
Exemple #4
0
 def send_email(self):
     over_target = setting('MISSIVE_EMAIL', False)
     self.missive.target = over_target if over_target else self.missive.target
     if setting('MISSIVE_SERVICE', False):
         self.missive.msg_id = make_msgid()
         text_content = str(self.missive.txt)
         html_content = self.missive.html
         self.email = EmailMultiAlternatives(
             self.missive.subject,
             html_content,
             conf.sender_email, [self.missive.target],
             headers={'Message-Id': self.missive.msg_id})
         self.email.attach_alternative(html_content, "text/html")
     self.email_attachments()
     self.missive.to_sent()
     self.missive.save()
     return self.missive.status
Exemple #5
0
 def delete_backup(self, name):
     name = "%s/%s" % (setting("MEDIA_ROOT"), name)
     assert name, "The name argument is not allowed to be empty."
     name = os.path.realpath(name)
     try:
         if os.path.isdir(name):
             os.rmdir(name)
         else:
             os.remove(name)
     except FileNotFoundError:
         pass
     self.remove_dir(name)
Exemple #6
0
 def our_data(self):
     return {
         "name": self.missive.subject,
         "custom_id": self.missive.msg_id,
         "custom_data": self.missive.msg_id,
         "color_printing": True,
         "duplex_printing": True,
         "optional_address_sheet": False,
         "notification_email": setting("LAPOST_NOTIFICATION"),
         "archiving_duration": 0,
         "envelope_windows_type": "SIMPLE",
         "postage_type": "ECONOMIC",
     }
Exemple #7
0
 def _save_backup(self, name, content):
     content.seek(0)
     filename = "%s/%s" % (setting("MEDIA_ROOT"), name)
     os.makedirs(os.path.dirname(filename), exist_ok=True)
     with open(filename, "wb") as bacfile:
         while True:
             buf = content.read(1024)
             if buf:
                 for byte in buf:
                     pass
                 n = bacfile.write(buf)
             else:
                 break
Exemple #8
0
 class ForeignKey:
     group = setting('TENANT_GROUP', 'auth.Group')
     role = setting('TENANT_ROLE', 'mighty.Role')
     #alternate = setting('TENANT_ALTERNATE', 'mighty.TenantAlternate')
     tenant = setting('TENANT_MODEL', 'mighty.Tenant')
     missive = setting('TENANT_MISSIVE', 'mighty.Missive')
     invitation = setting('TENANT_INVITATION', 'mighty.TenantInvitation')
     nationalities = setting('TENANT_NATIONALITY', 'mighty.Nationality')
     user = settings.AUTH_USER_MODEL
     optional = False
Exemple #9
0
 def api_url(self):
     if setting('MISSIVE_SERVICE', False):
         return self.api_sandbox
     return self.api_sandbox
Exemple #10
0
from django.utils._os import safe_join
from django.utils.module_loading import import_string
from mighty.functions import setting, get_logger
import os

logger = get_logger()
storage_default = "django.core.files.storage.FileSystemStorage"
storage_choice = setting("STORAGE", storage_default)
Storage = import_string(storage_choice)
"""
Override the storage to use a new storage capability without connection.
Usefull for local development and do not be impacted by requirements.

Also, the class duplicate the function save and remove that able you to backup or synchronate your data.
Usefull for cost service.
"""


class CloudStorage(Storage):
    def __init__(self, **settings):
        todel = [
            name for name, value in settings.items()
            if not hasattr(self, name)
        ]
        logger.info("CloudStorage: delete settings: %s" % todel)
        for field in todel:
            del settings[field]
        super().__init__(**settings)


if storage_choice != storage_default:
Exemple #11
0
 def get_css_print(self):
     return os.path.join(setting('STATIC_ROOT', '/static'), 'css',
                         'print.css')
Exemple #12
0
from mighty.applications.nationality.apps import NationalityConfig
from mighty.applications.user import get_form_fields

import pdfkit, os, tempfile, csv, logging

base_config = {
    'base': {
        'logo': conf.logo,
        'email': TwofactorConfig.method.email,
        'sms': TwofactorConfig.method.sms,
        'basic': TwofactorConfig.method.basic,
        'languages': NationalityConfig.availables,
        'fields': get_form_fields(),
    }
}
base_config.update(setting('BASE_CONFIG', {}))
logger = logging.getLogger(__name__)
"""
Standard view without model
app_label + model_name can be faked for supporting reverse_url
[app_label] view application label
[model_name] application model name
[no_permission] if true no permission needed to get the view
[permission_required] list all permissions needed to get the view
[add_to_context] dict to add datas in the context view
"""


class BaseView(PermissionRequiredMixin):
    app_label = None
    model_name = None
Exemple #13
0
class ShopConfig(AppConfig, Config):
    name = 'mighty.applications.shop'
    group = setting('PAYMENT_GROUP', 'auth.Group')
    method = setting('PAYMENT_METHOD', 'mighty.PaymentMethod')
Exemple #14
0
    'first_name',
    'fullname',
    'representation',
    'style',
    'gender',
    'is_staff',
)

if conf.cgu:
    serializer + ('cgu', )

if conf.cgv:
    serializer + ('cgv', )

invitation = ('last_name', 'first_name', 'email', 'phone', 'user', 'by',
              'token', 'status')
profile = fields.image_url + (
    'username',
    'last_name',
    'first_name',
    'fullname',
    'representation',
    'style',
    'gender',
    'is_staff',
    'language_pref',
)

if 'mighty.applications.nationality' in setting('INSTALLED_APPS'):
    serializer += ('nationalities', )
    profile += ('all_nationalities', )
Exemple #15
0
 class Key:
     google = setting('GOOGLE_API_ADDRESS')
     mapbox = setting('MAPBOX_ACCESS_TOKEN')