Skip to content

Instantly share code, notes, and snippets.

View souen's full-sized avatar

Souen Boniface souen

View GitHub Profile
@souen
souen / gist:651289
Created October 28, 2010 13:06 — forked from davidbgk/fields.py
class EmptyChoiceField(forms.ChoiceField):
def __init__(self, choices=(), empty_label=None, required=True, widget=None, label=None,
initial=None, help_text=None, *args, **kwargs):
# add an empty label if it exists (and if field is not required!)
if not required and empty_label is not None:
choices = tuple([(u'', empty_label)] + list(choices))
super(EmptyChoiceField, self).__init__(choices=choices, required=required, widget=widget, label=label,
initial=initial, help_text=help_text, *args, **kwargs)
def get_absolute_url(self):
# We need to build the URL to the paperPage inside the digital paper
# of the linked publication.
# It's built with the linked publication's absolute_url + an anchor pointing
# to the right book and the right page, 0-indexed.
# ex: http://journal.liberation.fr/publication/liberation/460/#0_17
# The anchor is #0_17:
# - 0 -> first book of the publication
# - 17 -> paperPage.page_number == 18
if self.book.code == BOOK_CODE.QUOTIDIEN:
@souen
souen / gist:913312
Created April 11, 2011 10:03
django-treemenu documentation

Django Tree Menus

This is a simple and generic tree-like menuing system for Django_ with an easy-to-use admin interface. It covers all the essentials for building tree-structured menus and should be enough for a lot of projects. It is also easily extendable if you need to add some special behaviour to your menu items.

@souen
souen / gist:2703795
Created May 15, 2012 18:05
Slow queries Sesql
# 6s
2012-05-15 19:59:43 CEST LOG: duration: 6309.370 ms statement: SELECT classname, id
FROM sesql_default
WHERE (workflow_state = 20) AND (fulltext_tsv @@ plainto_tsquery('public.lem_french', E'ayrault ')) AND (classname IN (E'Article',E'Slideshow',E'Media',E'Pointer',E'Chat',E'Forum')) AND (workflow_state = 20) AND (editorial_source IN (20,10)) AND (publication_date >= E'2011-11-17')
ORDER BY publication_date_time DESC
LIMIT 1000
# 56s
2012-05-15 19:54:33 CEST LOG: duration: 56736.021 ms statement: SELECT classname, id
@souen
souen / gist:2703937
Created May 15, 2012 18:21
Slow queries sur les section sans contenus
# Requête 1: sélectionne un contentmodel lié à la rubrique *100126* (qui n'en contient aucun)
# Prend 15-30s
SELECT "libe_contentmodel"."id","libe_contentmodel"."child_type"
FROM "libe_contentmodel"
INNER JOIN "libe_contenttosection"
ON ("libe_contentmodel"."id" = "libe_contenttosection"."content_model_id")
WHERE ("libe_contenttosection"."section_id" = 100126 AND "libe_contentmodel"."workflow_state" = 20 )
ORDER BY "libe_contentmodel"."computed_ponderation" DESC, "libe_contentmodel"."updating_date" DESC LIMIT 1
public class MyApexClasssss
{
/**
* Enum representing each of before/after CRUD events on Sobjects
*/
public enum Evt
{
afterdelete, afterinsert, afterundelete,
afterupdate, beforedelete, beforeinsert, beforeupdate
}