This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function folks_db_report() { | |
$header = array( | |
'id' => array('data' => t('Id'), 'field' => 'u.id'), | |
'first_name' => array('data' => t('First Name'), 'field' => 'u.first_name'), | |
'last_name' => array('data' => t('Last Name'), 'field' => 'u.last_name'), | |
'color' => array('data' => t('Favorite Color'), 'field' => 'u.color'), | |
); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function YourThemeName_links($links, $attributes = array('class' => 'links')) { | |
global $language; | |
$output = ''; | |
if (count($links) > 0) { | |
$output = '<ul' . drupal_attributes($attributes) . '>'; | |
$num_links = count($links); | |
$i = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Plural form for Russian Language | |
* $form1 - singular value | |
* $form2 - double value | |
* $form3 - multiple value | |
*/ | |
function format_russian_plural($n, $form1, $form2, $form3) { | |
$n = abs($n) % 100; | |
$n1 = $n % 10; | |
if ($n > 10 && $n < 20) return $form3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$result = db_query("SELECT nid FROM {node} WHERE type='publicprofile'"); | |
while ($data = db_fetch_object($result)) { | |
db_query("DELETE FROM {url_alias} WHERE src LIKE '%s'", 'node/' . $data->nid); | |
drupal_set_message('Deleted alias for a node %nid', array('%nid' => $data->nid)); | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def content_file_name(instance, filename): | |
return '/'.join(['content', instance.user.username, filename]) | |
class Content(models.Model): | |
name = models.CharField(max_length=200) | |
user = models.ForeignKey(User) | |
file = models.FileField(upload_to=content_file_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product(models.Model): | |
# other fields | |
image = models.FileField(storage = MogileFSStorage(), upload_to = 'product_images') | |
from django.core.files import File | |
from django.core.files.temp import NamedTemporaryFile | |
product = Product() | |
# set all your variables here | |
product.save() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from django.db.models.fields.files import FileField | |
from django.core.files.storage import default_storage | |
def file_cleanup(sender, **kwargs): | |
""" | |
File cleanup callback used to emulate the old delete | |
behavior using signals. Initially django deleted linked | |
files when an object containing a File/ImageField was deleted. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# set -x | |
# Shell script to monitor or watch the disk space | |
# It will send an email to $ADMIN, if the (free available) percentage of space is >= 90%. | |
# ------------------------------------------------------------------------- | |
# Set admin email so that you can get email. | |
ADMIN="root" | |
# set alert level 90% is default | |
ALERT=90 | |
# Exclude list of unwanted monitoring, if several partions then use "|" to separate the partitions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" ?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one or more | |
contributor license agreements. See the NOTICE file distributed with | |
this work for additional information regarding copyright ownership. | |
The ASF licenses this file to You under the Apache License, Version 2.0 | |
(the "License"); you may not use this file except in compliance with | |
the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.exceptions import MiddlewareNotUsed | |
from django.conf import settings | |
import cProfile | |
import pstats | |
import marshal | |
from cStringIO import StringIO | |
class ProfileMiddleware(object): | |
def __init__(self): | |
if not settings.DEBUG: |
OlderNewer