Skip to content

Instantly share code, notes, and snippets.

View silenius's full-sized avatar
🤘

Julien Cigar silenius

🤘
View GitHub Profile
export function get_base_url(localized=false) {
const host_url = document.body.getAttribute('data-host_url');
let base_url;
if (localized) {
const prefix = document.body.getAttribute('data-script_name_');
const edit_lang = document.body.getAttribute('data-edit_locale');
if (prefix !== null && edit_lang) {
base_url = host_url + prefix + '/' + edit_lang;
export function site_url() {
const prefix = document.body.getAttribute('data-script_name');
let url = Array.prototype.slice.call(arguments);
url.splice(0, 0, prefix);
return url.join('/').replace(/\/{2,}/, '/');
}
create or replace function t_container_id() returns trigger as $weight$
declare
container_id_changed CONSTANT boolean := TG_OP = 'UPDATE' AND NEW.container_id IS DISTINCT FROM OLD.container_id;
compute_new_weight CONSTANT boolean := TG_OP = 'INSERT' OR container_id_changed;
begin
if container_id_changed then
-- Prevent concurrent modifications.
PERFORM 1
FROM folder
WHERE content_id = NEW.container_id
def with_current_translations(stmt, entity, request=None):
if request is None:
registry = get_current_registry()
else:
registry = request.registry
insp = inspect(entity)
base = insp.class_
current_locale, default_locale = get_locales(request)
translations = registry['amnesia.translations']['mappings']
WITH RECURSIVE parents(id, added, updated, effective, expiration, exclude_nav, inherits_parent_acl, weight, is_fts, props, content_type_id, owner_id, state_id, container_id, content_id, max_children, index_content_id, polymorphic_loading, rss, default_order, level) AS
(
SELECT
content.id AS id,
content.added AS added,
content.updated AS updated,
content.effective AS effective,
content.expiration AS expiration,
content.exclude_nav AS exclude_nav,
content.inherits_parent_acl AS inherits_parent_acl,
WITH RECURSIVE parents(" %% (34442533520 anon)s", count_children, id, added, updated, effective, expiration, exclude_nav, inherits_parent_acl, weight, is_fts, props, content_type_id, owner_id, state_id, container_id, content_id, max_children, index_content_id, polymorphic_loading, rss, default_order, level) AS
(
SELECT
row_number() OVER (PARTITION BY content.container_id
ORDER BY
content.weight DESC) AS anon_1,
(
SELECT
count(*) AS count_1
FROM
WITH RECURSIVE parents(" %% (34442529424 anon)s", count_children, id, added, updated, effective, expiration, exclude_nav, inherits_parent_acl, weight, is_fts, props, content_type_id, owner_id, state_id, container_id, content_id, max_children, index_content_id, polymorphic_loading, rss, default_order, level) AS
(
SELECT
content.id AS id,
content.added AS added,
content.updated AS updated,
content.effective AS effective,
content.expiration AS expiration,
content.exclude_nav AS exclude_nav,
content.inherits_parent_acl AS inherits_parent_acl,
def get_children_containers(dbsession, folder_id, max_depth=None):
root = dbsession.query(
Folder, sql.literal(1, type_=Integer).label('level')
).filter(
sql.and_(
Folder.exclude_nav == False,
Folder.container_id == folder_id
)
).cte(
name='parents', recursive=True
>>> foo = sql.and_(Content.title=='123', Content.owner_id==3)
>>> foo
<sqlalchemy.sql.elements.BooleanClauseList object at 0x80635f850>
>>> print(foo)
anon_1.amnesia_multilingual_content_translation_title = :amnesia_multilingual_content_translation_title_1 AND content.owner_id = :owner_id_1
>>> foo.append(Content.container_id == 2)
Traceback (most recent call last):
File "/usr/home/julien/code/venvs/riparias/lib/python3.7/site-packages/sqlalchemy/sql/elements.py", line 826, in __getattr__
return getattr(self.comparator, key)
AttributeError: 'Comparator' object has no attribute '_text_converter_role'
def get_children_containers(dbsession, folder_id, max_depth=None):
root = dbsession.query(
Folder, sql.literal(1, type_=Integer).label('level')
).filter(
sql.and_(
Folder.exclude_nav == False,
Folder.container_id == folder_id
)
).cte(
name='parents', recursive=True