image = Image.open(imageField)
if image.mode != "RGB":
image = image.convert("RGB")
#big
image.save('image.jpg')
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2090"></script>
#1
from django.db import models
from django.contrib.auth.models import User, UserManager
class CustomUser(User):
birthday = models.DateField()
activation_key = models.CharField(max_length=255, blank=True, default='')
photo_url = models.CharField(max_length=50, blank=True) # cant incrementada de votaciones
User._meta.get_field('username')._unique = False
User._meta.get_field('email')._unique = True
User._meta.get_field_by_name('username')[0].max_length=75
#2 save child class
from users.models import CustomUser
def saveCustomUsers(request):
usr = CustomUser()
usr.username = 'macks'
usr.password = '123456'
usr.activation_key = 'sfsdf123456'
usr.birthday = datetime.now()
usr.photo_url = 'image.jpg'
usr.save()
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2083"></script>
#agregar templatetags a APPS de settings
1.-
apps/templatetags/userInfoTag.py
# -*- coding: utf-8 -*-
from django import template
from django.shortcuts import get_object_or_404
from django.contrib.auth.models import User
register = template.Library()
@register.inclusion_tag('admin/users/inclusionTags/userRecordsTags.html', takes_context=True)
def userRecords(context):
request = context['request']
user = get_object_or_404(User, id=request.user.id)
userName = user.first_name + ' ' + user.last_name
return {'userName': userName}
2.-
apps/templatetags/__init__.py
from django.template import add_to_builtins
add_to_builtins('templatetags.userInfoTag')
3.-
templates/admin/users/inclusionTags/userRecordsTags.html
{{ userName }} # return value of userInfotag.py
4.-
#se puede usar la plantilla userRecords.html en culaquiera otra plantilla
templates/admin/users/indexSuccess.html
<td>{% userRecords %}</td> #def userRecords
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2079"></script>
descragar y cambiar de nombre al archivo
def downloadImage(self):
img_url = 'http://img1cdn.adoosimg.com/b195d543e38e349deac032b41be043c7-1-5.jpg'
imgName = 'b195d543e38e349deac032b41be043c7-1-5.jpg'
imgN = "peque_%s"%imgName.replace('5.','7.') if imgName[-5:]=='5.jpg' else imgName
file_path = "%s/adoos/%s" % (settings.UPLOAD_PATH, imgN)
downloaded_image = file(file_path, "wb")
image_on_web = urllib.urlopen(img_url)
while True:
buf = image_on_web.read(65536)
if len(buf) == 0:
break
downloaded_image.write(buf)
downloaded_image.close()
image_on_web.close()
return file_path
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2073"></script>
def __validateVideoName(videoname):
import string
rs = False
if videoname:
whiteSpace = False if re.search(' ',videoname) else True
specialChar = True if re.compile('[a-zA-Z0-9._-]+$').match(videoname) else False
if whiteSpace and specialChar:
rs = True
return rs
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2069"></script>
dsc = ['uno','dos','tres']
line = """#%d# rn
%s rnrn""" % (i+1, dsc)
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2067"></script>
def remove_html_tags(data):
p = re.compile(r'<[^<]*?/?>')
return p.sub('', data)
Here is another function to remove more than one consecutive white spaces:
def remove_extra_spaces(data):
p = re.compile(r's+')
return p.sub(' ', data)
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2066"></script>
usando la libreria ffmpeg
import commands
import os
def execute():
cmd = 'c:/ffmpeg/ffmpeg.exe -y -itsoffset -4 -i c:/input.mpg -vframes 1 -s 100x90 -f image2 c:/uploads/img_gen.jpg'
#c = commands.getoutput(cmd) # linux
c = os.system(self.cmd) #windows
return c
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2058"></script>
from django.db import load_backend, transaction, connection
#manipular datos de una bd externa
def sincronizeDB(self):
myBackend = load_backend('mysql') # or 'mysql', 'sqlite3', 'oracle'
myConnection = myBackend.DatabaseWrapper({
'DATABASE_HOST': '192.168.1.11',
'DATABASE_NAME': 'agenciaperu_local',
'DATABASE_OPTIONS': {},
'DATABASE_PASSWORD': "",
'DATABASE_PORT': "",
'DATABASE_USER': "root",})
# Now we can do all the standard raw sql stuff with myConnection.
myCursor = myConnection.cursor()
id = 22
name = "tecnologia para jos"
slug = "tecnologia_para_jos"
row = myCursor.execute("INSERT INTO category(name, slug ) values(%s,%s);", [name, slug])
row = myConnection._commit()
#row = transaction.rollback_unless_managed() -----> serĂa cuando trabajamos en local
# select simple
#row = myCursor.execute("select *from category where id = %s and highlight = %s;",[id,0])
myCursor.fetchall()
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2056"></script>
#template
{% load humanize %}
{{ my_num|intcomma }}
Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2046"></script>