Tags: django

Sort by: Date / Title /

  1. 7 years ago by macks
    1. image = Image.open(imageField)
    2. if image.mode != "RGB":
    3.     image = image.convert("RGB")
    4.     #big
    5.     image.save('image.jpg')
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2090"></script>
  2. 7 years ago by macks
    1. #1
    2. from django.db import models
    3. from django.contrib.auth.models import User, UserManager
    4.  
    5. class CustomUser(User):
    6.     birthday = models.DateField()
    7.     activation_key = models.CharField(max_length=255, blank=True, default='')
    8.     photo_url = models.CharField(max_length=50, blank=True) # cant incrementada de votaciones
    9.     User._meta.get_field('username')._unique = False
    10.     User._meta.get_field('email')._unique = True
    11.     User._meta.get_field_by_name('username')[0].max_length=75
    12.  
    13. #2 save child class
    14. from users.models import CustomUser
    15. def saveCustomUsers(request):
    16.     usr = CustomUser()
    17.     usr.username = 'macks'
    18.     usr.password = '123456'
    19.     usr.activation_key = 'sfsdf123456'
    20.     usr.birthday = datetime.now()
    21.     usr.photo_url = 'image.jpg'
    22.     usr.save()
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2083"></script>
  3. 7 years ago by macks
    1. #agregar templatetags a APPS de settings
    2.  
    3. 1.-
    4. apps/templatetags/userInfoTag.py
    5.  
    6. # -*- coding: utf-8 -*-
    7. from django import template
    8. from django.shortcuts import get_object_or_404
    9. from django.contrib.auth.models import User
    10.  
    11. register = template.Library()
    12. @register.inclusion_tag('admin/users/inclusionTags/userRecordsTags.html', takes_context=True)
    13. def userRecords(context):
    14.     request = context['request']
    15.     user = get_object_or_404(User, id=request.user.id)
    16.     userName = user.first_name + ' ' + user.last_name
    17.    
    18.     return {'userName': userName}
    19.  
    20. 2.-
    21. apps/templatetags/__init__.py
    22. from django.template import add_to_builtins
    23. add_to_builtins('templatetags.userInfoTag')
    24.  
    25. 3.-
    26. templates/admin/users/inclusionTags/userRecordsTags.html
    27. {{ userName }} # return value of userInfotag.py
    28.  
    29. 4.-
    30.  
    31. #se puede usar la plantilla userRecords.html en culaquiera otra plantilla
    32.  
    33. templates/admin/users/indexSuccess.html
    34. <td>{% userRecords %}</td>  #def userRecords
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2079"></script>
  4. sponsorised links
  5. 7 years ago by macks
    descragar y cambiar de nombre al archivo
    1. def downloadImage(self):
    2.     img_url = 'http://img1cdn.adoosimg.com/b195d543e38e349deac032b41be043c7-1-5.jpg'
    3.     imgName = 'b195d543e38e349deac032b41be043c7-1-5.jpg'
    4.     imgN = "peque_%s"%imgName.replace('5.','7.') if imgName[-5:]=='5.jpg' else imgName
    5.    
    6.     file_path = "%s/adoos/%s" % (settings.UPLOAD_PATH, imgN)
    7.     downloaded_image = file(file_path, "wb")
    8.  
    9.     image_on_web = urllib.urlopen(img_url)
    10.     while True:
    11.         buf = image_on_web.read(65536)
    12.         if len(buf) == 0:
    13.             break
    14.         downloaded_image.write(buf)
    15.     downloaded_image.close()
    16.     image_on_web.close()
    17.  
    18.     return  file_path
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2073"></script>
  6. 7 years ago by macks
    usando la libreria ffmpeg
    1. import commands
    2. import os
    3.  
    4. def execute():
    5.         cmd = 'c:/ffmpeg/ffmpeg.exe -y -itsoffset -4 -i c:/input.mpg -vframes 1 -s 100x90 -f image2 c:/uploads/img_gen.jpg'
    6.         #c = commands.getoutput(cmd) # linux
    7.         c = os.system(self.cmd) #windows
    8.         return c
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2058"></script>
  7. 7 years ago by macks
    1. def testImages(request):
    2.     from PIL import Image
    3.     path = ('c:/images/soluciones__1.jpg')
    4.     #content = 'c:/images/soluciones1.jpg'
    5.     content = 'c:/images/image.gif'
    6.     image = Image.open(content)
    7.     image.thumbnail((200,150), Image.ANTIALIAS)
    8.     image.save(path, image.format)
    9.     savelog(image.format)
    10.     del image
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2057"></script>
  8. 7 years ago by macks
    1. from django.db import load_backend, transaction, connection
    2.  
    3. #manipular datos de una bd externa
    4.  
    5. def sincronizeDB(self):
    6.         myBackend = load_backend('mysql') # or 'mysql', 'sqlite3', 'oracle'
    7.         myConnection = myBackend.DatabaseWrapper({
    8.             'DATABASE_HOST': '192.168.1.11',
    9.             'DATABASE_NAME': 'agenciaperu_local',
    10.             'DATABASE_OPTIONS': {},
    11.             'DATABASE_PASSWORD': "",
    12.             'DATABASE_PORT': "",
    13.             'DATABASE_USER': "root",})
    14.         # Now we can do all the standard raw sql stuff with myConnection.
    15.         myCursor = myConnection.cursor()       
    16.         id = 22
    17.         name = "tecnologia para jos"
    18.         slug = "tecnologia_para_jos"
    19.         row = myCursor.execute("INSERT INTO category(name, slug )  values(%s,%s);", [name, slug])
    20.         row = myConnection._commit()
    21.         #row = transaction.rollback_unless_managed()  -----> sería cuando trabajamos en local
    22.  
    23. # select simple
    24.         #row = myCursor.execute("select *from category where id = %s and highlight = %s;",[id,0])
    25.         myCursor.fetchall()
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2056"></script>
  9. 7 years ago by macks
    1. values = ['Enero','Enero','Enero','Febrero']
    2. print  [(x,values.count(x)) for x in set(values)]
    3.  
    4. ====>>[('Enero', 3), ('Febrero', 1)]
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2055"></script>
  10. 7 years ago by macks
    1. #template
    2. {% load humanize %}
    3. {{ my_num|intcomma }}
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2046"></script>
  11. 7 years ago by macks
    1. #form.cleaned_data['videoPath'] = C:Apacheuploadsvideosvideo_test.flv
    2.  
    3. path = form.cleaned_data['videoPath'].replace("\","/")
    4.             vName = ''.join(path.split("/")[-1:])
    5.  
    6. #result = 'video_test.flv'
    Paste this in your website: <script type="text/javascript" src="http://www.posteet.com/embed/2045"></script>

First / Previous / Next / Last / Page 1 of 3 (21 posteets)