예제 #1
0
def get_original(obj, user_id):
    if not obj.is_mosaico:
        return Http404
    template_id = obj.id
    key = tools.get_mosaico_key(template_id)
    original = Template.objects.filter(user_id=user_id,
                                       template_id=template_id).first()
    if not original:
        name = "versafix-1"
        created = int(time.time())
        tpl_default = tools.VersafixSettings()
        meta_data = {
            "key": key,
            "name": "versafix-1",
            "created": created,
            "editorversion": "0.15.0",
            "template":
            "/static/mosaico/templates/versafix-1/template-versafix-1.html",
            "templateversion": "1.0.5"
        }
        original, _created = Template.objects.get_or_create(
            # key=key,
            name=name,
            user_id=user_id,
            template_id=template_id,
        )
        original.html = tpl_default.DEFAULT_HTML
        original.template_data = tpl_default.TEMPLATE_DATA
        original.meta_data = meta_data
        original.save()
    return original
예제 #2
0
def create(request):
    if request.method == "POST":
        mosaico_name = request.POST.get("mosaico_name", "")
        mosaico_name = mosaico_name or "versafix-1"
        mosaico_status = request.POST.get("mosaico_status", "")
        if mosaico_status == "create":
            with atomic():
                tpl_obj = SendTemplate.objects.create(
                    user=request.user, content_type=1, encoding='base64', character='utf-8',
                    image_encode='N', attachtype='html', priority='low', status='0', isvalid=1, issync=0,
                    is_mosaico=True
                )
                template_id = tpl_obj.id
                key = tools.get_mosaico_key(template_id)
                created = int(time.time())
                first = Template.objects.filter(user_id=request.user.id, template_id=template_id).first()
                if not first:
                    if mosaico_name == "versafix-1":
                        name = "versafix-1"
                        tpl_default = tools.VersafixSettings()
                        meta_data = {
                            "key": key,
                            "name": "versafix-1",
                            "created": created,
                            "editorversion": "0.15.0",
                            "template": "/static/mosaico/templates/versafix-1/template-versafix-1.html",
                            "templateversion": "1.0.5"
                        }
                    else:
                        name = "tedc15"
                        tpl_default = tools.Tedc15Settings()
                        meta_data = {
                            "key": key,
                            "name": "tedc15",
                            "created": created,
                            "editorversion": "0.15.0",
                            "template": "/static/mosaico/templates/tedc15/template-tedc15.html",
                        }

                    template, _created = Template.objects.get_or_create(
                        # key=key,
                        name=name,
                        user_id=request.user.id,
                        template_id=template_id,
                    )
                    template.html = tpl_default.DEFAULT_HTML
                    template.template_data = tpl_default.TEMPLATE_DATA
                    template.meta_data = meta_data
                    template.save()
            return HttpResponseRedirect(reverse("mosaico_template_modify", args=(template_id,)))
    return HttpResponseRedirect(reverse("home"))