Skip to content

Instantly share code, notes, and snippets.

View toutpt's full-sized avatar
👨‍💻

Jean-Michel toutpt

👨‍💻
View GitHub Profile
@toutpt
toutpt / resources.js
Last active March 21, 2016 11:22
angular require extra libs
(function () {
'use strict';
/*global _:false */
/*global angular:false */
/*global SWIF_RESOURCES_VERSION:false */
/*jshint latedef:false */
/* config.json file available throw settings.app:
"resources": {
"scripts": {
/*global _:false */
/**
* nom
* code
* type
* Site parent
* Service mainteneur
* long
* lat
@toutpt
toutpt / feature.js
Created December 20, 2013 14:32
open all img in a plone site using overlay
var openimginoverlay = function(){
$('img[src$="image_tile"],img[src$="image_thumb"],img[src$="image_mini"],img[src$="image_preview"]')
.each(function(){
var $this = $(this);
if (!$this.parent().is('a')){
$this.prepOverlay({
subtype: 'image',
urlmatch: '/image_.+$',
urlreplace: '',
});
@toutpt
toutpt / storage.py
Last active December 13, 2018 18:52
The best way to store settings/data using zope annotations
from zope.annotation.interfaces import IAnnotations
from persistent.list import PersistentList
from Products.CMFCore.utils import getToolByName
FAVBY = "collective.favoriting.favoritedby"
def setupAnnotations(context):
"""
set up the annotations if they haven't been set up
def getToolByName(obj, name, default=_marker):
""" Get the tool, 'toolname', by acquiring it.
o Application code should use this method, rather than simply
acquiring the tool by name, to ease forward migration (e.g.,
to Zope3).
"""
tool_interface = _tool_interface_registry.get(name)
@toutpt
toutpt / get_browser_views_used.py
Created September 26, 2013 20:01
This script can be used as Python Script in ZMI
catalog = container.portal_catalog
types = container.portal_types.objectIds()
views = {}
for t in types:
brains = catalog(portal_type=t)
for brain in brains:
ob = brain.getObject()
layout = ob.getLayout()
@toutpt
toutpt / removefss.py
Created September 26, 2013 19:55
Script to migrate FSS to blob. You have to write an uprade step and put this code inside. Most of the time you need to adapt it to your project / content types
def upgrade_fss2attr_storage(portal_setup):
"""We use fss on plone3, so we need first to come back to default
plone so the migration of plone will next do the job to go on blob"""
site = portal_setup.aq_parent
#fss2attributestorage
from cStringIO import StringIO
from Products.Archetypes.Storage import AttributeStorage
from iw.fss.FileSystemStorage import FileSystemStorage
# attr_storage = AttributeStorage()
fss_storage = FileSystemStorage()
@toutpt
toutpt / dump_all_resources.py
Created August 27, 2013 09:11
This is a script to get all browser:resources from a Plone install
from zope.publisher.interfaces.browser import IDefaultBrowserLayer,\
IBrowserPublisher
from zope.component.hooks import setSite
import zope.interface
from zope.component._api import getAdapters
import shutil
import os
from Testing import makerequest
portal = app.restrictedTraverse('adria-rcse')
@toutpt
toutpt / googlexxxxx.py
Created August 26, 2013 08:14
google analytics file for Plone with diazo
# Add this as python scrip tin the ZMI
res = "CONTENT OF THE FILE GOOGLE HAS GAVE YOU"
context.REQUEST.response.setHeader('X-Theme-Disabled', 'True')
return res
@toutpt
toutpt / ismobile.py
Created April 11, 2013 10:16
detect mobile browser for Plone
# Ported by Matt Sullivan http://sullerton.com/2011/03/django-mobile-browser-detection-middleware/
import re
from Products.Five.browser import BrowserView
reg_b = re.compile(r"(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino", re.I|re.M)
reg_v = re.compile(r"1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)