def import_one(key):
    basefname = IMPORT_MAP[key]

    fname = os.path.join(DIR, basefname + ".html")
    fname2 = os.path.join(DIR, basefname + "_subject.txt")

    subject = _(u"Besked fra foKUs")
    body = ''

    if os.path.exists(fname2):
        subject = open(fname2).read().strip()

    if os.path.exists(fname):
        body = open(fname).read()

    try:
        template = EmailTemplate.objects.get(
            key=key, organizationalunit__isnull=True
        )
    except EmailTemplate.DoesNotExist:
        template = EmailTemplate(key=key, organizationalunit=None)

    template.subject = subject
    template.body = body
    template.save()
Esempio n. 2
0
 def create_emailtemplate(self,
                          key=1,
                          type=None,
                          subject="",
                          body="",
                          unit=None):
     if key is not None and type is None:
         type = EmailTemplateType.get(key)
     template = EmailTemplate(key=key,
                              type=type,
                              subject=subject,
                              body=body,
                              organizationalunit=unit)
     template.save()
     return template
    def get_context_data(self, **kwargs):
        context = {}

        context['inherited'] = {
            item.template_key:
            {
                'template_key': item.template_key,
                'enabled': item.enabled,
                'days': item.days
            }
            for item in chain.from_iterable(
                product.productautosend_set.all()
                for product in self.object.real.products
            )
        }
        context['template_keys'] = list(set(
            template.key
            for template in chain.from_iterable(
                EmailTemplate.get_templates(product.organizationalunit)
                for product in self.object.real.products
            )
        ))
        if hasattr(self.object, 'product') and self.object.product is not None:
            context['organizationalunit'] = \
                self.object.product.organizationalunit
        context['autosend_enable_days'] = EmailTemplateType.get_keys(
            enable_days=True
        )
        context.update(kwargs)
        return super(ChangeVisitAutosendView, self).\
            get_context_data(**context)
Esempio n. 4
0
def import_one(key):
    basefname = IMPORT_MAP[key]

    fname = os.path.join(DIR, basefname + ".html")
    fname2 = os.path.join(DIR, basefname + "_subject.txt")

    subject = _(u"Besked fra foKUs")
    body = ''

    if os.path.exists(fname2):
        subject = open(fname2).read().strip()

    if os.path.exists(fname):
        body = open(fname).read()

    et_type = EmailTemplateType.objects.get(key=key)

    templates = EmailTemplate.objects.filter(type=et_type,
                                             organizationalunit__isnull=True)
    if templates.count() == 0:
        templates = [EmailTemplate(type=et_type, organizationalunit=None)]
    for template in templates:
        template.subject = subject
        template.body = body
        template.save()