Beispiel #1
0
def edit_make_editable_id(context, uuid_name, root):
    try:
        editable_id = root['id']
    except KeyError:
        editable_id = str(uuid5(get_uuid(context), uuid_name))
        root['id'] = editable_id
    return editable_id
Beispiel #2
0
        def render_tag(self, context, nodelist):
            output = nodelist_to_html(context, nodelist)
            if not edit_check_user(context):
                return output

            soup = BS(output)
            ctx = {}
            results = soup.findAll(attrs={'data-hint': self.non_greedy_all})
            for idx, result in enumerate(results):
                hint = result.attrs['data-hint']

                ct_id, id_, fields, edit_class = decode(hint).split(':')
                fields = fields.split(',')

                model_class = ContentType.objects.get(id=ct_id).model_class()
                instance = model_class.objects.get(id=id_)

                name = '__front_edit_{}'.format(idx)
                ctx[name] = instance

                models_fields = []
                for field in fields:
                    models_fields.append('{}.{}'.format(name, field))

                context.update(ctx)
                edit_soup(context, models_fields, '', result)
                context.pop()
            return mark_safe(str(soup))
Beispiel #3
0
def startup():
    for field_path in appsettings.CUSTOM_FIELDS:
        try:
            module_path, field_name = field_path.rsplit('.', 1)
            module = import_module(module_path)
            field = getattr(module, field_name)
        except (ValueError, ImportError, AttributeError) as e:
            raise ImportError(CF_IMPORT_ERROR.format(field_path, e))
        try:
            MEDIA.append(str(field().formfield().widget.media))
        except AttributeError as e:
            raise ImproperlyConfigured(CF_FIELD_ERROR.format(field_path, e))
Beispiel #4
0
def edit_link(context, admin_url, edit_class, html):
    if not edit_check_user(context):
        return html

    edit_check_configuration(context)

    root = bs_root(html)

    editable_id = edit_make_editable_id(context, admin_url, root)

    edit_modify_context(context,
                        editable_id=editable_id,
                        edit_class=edit_class,
                        admin_url=admin_url)

    return mark_safe(str(root))
Beispiel #5
0
    def _make_editables(self, context, deferred):
        editables = []
        for defer in deferred:
            admin_url = defer['admin_url']
            model = defer['model']
            subcontext = {
                'editable_id': defer['editable_id'],
                'edit_class': defer['edit_class'],
                'admin_url': admin_url,
            }

            if model is not None:
                model_class = model.__class__
                form_for_fields = make_form(
                    model_class, defer['fields'], defer['widgets'])(
                        instance=model,
                        auto_id='{}_%s'.format(defer['editable_id']))
                try:
                    self.media.add(str(form_for_fields.media))
                except AttributeError:
                    pass
                if model._deferred:
                    model_name = model_class.__base__.__name__.lower()
                else:
                    model_name = model_class.__name__.lower()

                subcontext.update({
                    'form_for_fields': form_for_fields,
                    'app_label': model._meta.app_label,
                    'model_name': model_name,
                    'pk': model.pk,
                })

            editables.append(
                render_to_string(appsettings.EDITABLE_TEMPLATE, subcontext,
                                 context))

        return editables
Beispiel #6
0
def edit_html(context, models_fields, edit_class, html):
    if not edit_check_user(context):
        return html

    edit_check_configuration(context)

    # get the model and fields
    model, fields, widgets = edit_get_model_and_fields(context, models_fields)

    if not edit_check_model(context, model):
        return html

    root = bs_root(html)

    editable_id = edit_make_editable_id(context, ','.join(models_fields), root)

    edit_modify_context(context,
                        model=model,
                        fields=fields,
                        widgets=widgets,
                        editable_id=editable_id,
                        edit_class=edit_class)

    return mark_safe(str(root))
Beispiel #7
0
def nodelist_to_html(context, nodelist):
    context.push()
    output = str(nodelist.render(context))
    context.pop()
    return output
Beispiel #8
0
    return mark_safe(str(root))


if appsettings.USE_HINTS:
    VKEY = appsettings.VIGENERE_KEY

    if VKEY is None:

        def encode(clear):
            return clear

        def decode(enc):
            return enc
    else:
        VKEY = str(VKEY)
        LVKEY = len(VKEY)

        UNILIMIT = sys.maxunicode

        def encode(clear):
            return base64.b64encode(''.join([
                chr((ord(c) + ord(VKEY[i % LVKEY])) % UNILIMIT)
                for i, c in enumerate(clear)
            ]).encode('utf-8'))

        def decode(enc):
            ''.join([
                chr((UNILIMIT + ord(e) - ord(VKEY[i % LVKEY])) % UNILIMIT)
                for i, e in enumerate(base64.b64decode(enc).decode('utf-8'))
            ])