A web developer's blog. PHP, MySQL, CakePHP, Zend Framework, Wordpress, Code Igniter, Django, Python, CSS, Javascript, jQuery, Knockout.js, and other web development topics.

Author Archives: Wenbert Del Rosario

WordPress: Post Types and Page Templates

Aside from the normal “Add Post” link in the WP-Admin Panel, you can add a custom post type. See http://codex.wordpress.org/Post_Types#Custom_Types. For example, if you want to add “Videos and Podcasts” as another post type, you put this in your functions.php … Continue reading

Posted in General | Tagged , , , , | Leave a comment

Django: Creating multiple select checkboxes with Forms

I got stuck for almost an hour trying to create a multiple select checkbox. Here is how to do it: First, I put this in my forms.py class UserlistForm(forms.Form): users = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,label="Notify and subscribe users to this post:") Then in … Continue reading

Posted in General | Tagged , , , , | 3 Comments

Python: Saving a file from the URL by chunks

For example, when you want to save an image from a URL. https://github.com/images/modules/header/logov3-hover.png f = urllib.urlopen(request.POST[’url’]) p = os.path.join(settings.UPLOAD_DIRECTORY, "saved_file.jpg") filesize = 0 with open(p,’wb’) as output: while True: buf = f.read(65536) filesize += len(buf) if not buf: break output.write(buf)

Posted in General | Tagged | Leave a comment

Django: Reading an image outside the public accessible directory and displaying the image through the browser

In some cases you would want to have “private” images for your logged-in users, you will not be able to store the images in the public accessible directory. For example, if you have “my_private_photo.png” stored in your normal “images” directory, … Continue reading

Posted in General | Tagged , , | 1 Comment

Apache mod_xsendfile for my Django app (UPDATED)

Here is how to setup/install mod_xsendfile in Apache2 + Django (mod_wsgi). First do this to install apxs2 $> sudo apt-get install apache2-prefork-dev Download mod_xsendfile: http://tn123.ath.cx/mod_xsendfile/ Install it by doing this: $> apxs2 -cia mod_xsendfile.c If you get an error compiling … Continue reading

Posted in General | Tagged , , , | 2 Comments

File Streaming in Django (Sending large files through Django)

I am planning to build something involving serving large files over HTTP. Putting the files in a public accessible directory is not an option since I need to monitor the users who download the file. Users will need to login … Continue reading

Posted in General | Tagged , , , | 3 Comments

A Simple Tkinter Example (Python)

What is Tkinter? Tkinter is Python’s de-facto standard GUI (Graphical User Interface) package. It is a thin object-oriented layer on top of Tcl/Tk. Here is a simple Tkinter example. The code below should generate a very simple GUI with a … Continue reading

Posted in General | Tagged , | 2 Comments

A Basic Python Class

This is the basic structure of a Python class. >>> class Simplex: … "An example class""" … def __init__(self, x, y): … self.a = x … self.b = y … def addition(self): … return self.a + self.b … >>> z … Continue reading

Posted in General | Tagged , , , | 1 Comment

My notes for Lists in Python

Lists A list is a sequence of values. [ and ] like numerically indexed arrays in PHP >>> # a list of numbers >>> my_numbers = [10, 15, 20, 25] >>> print my_numbers [10, 15, 20, 25] >>> >>> #a … Continue reading

Posted in General | Tagged , | 2 Comments

Basic Python: Filenames and paths

Another Python post! I am still learning the language. Since I cannot remember everything, I am posting it here for future reference. Get the Current Working Directory To get the “current working directory” do this: import os current_dir = os.getcwd() … Continue reading

Posted in General | Tagged , , , , , , , | Leave a comment