kamal's blog

kamal's picture

Drupal: Views block delta converted to md5 hash

Find out this only through reading the views.module code. In case of your views block display has a long name (> 32 chars)(the views name would be used as delta in block table), Views would hash it through md5. You can get the list of hashed names stored in the variable table as views_block_hashes. For example, mine:-

Array
(
    [ba843477361f490ca5c9e42548f0127d] => imagegallery_block_latest_images-block_1
)

The related code is in line 298 of views.module.

kamal's picture

Installing Drupal from command line

Using twill because until Drupal 7, there's no way you can install Drupal without opening the browser.

#debug http 1
go http://192.168.1.6:12000/install.php?profile=pulut&locale=en
code 200
find "To set up your Pulut database, enter the following information."
#show_cookies

fv 1 db_type pgsql
fv 1 db_path gmp
fv 1 db_user kamal
fv 1 db_pass abc123

submit op

find "All necessary changes to <em>./sites/default</em> and <em>./sites/default/settings.php</em> have been made. They have been set to read-only for security."

fv 1 site_mail kamal@bytecraft.com.my
fv 1 account[name] admin
fv 1 account[mail] kamal@bytecraft.com.my
fv 1 account[pass][pass1] abc123
fv 1 account[pass][pass2] abc123
fv 1 update_status_module[1] 0

submit op

find "Congratulations, Pulut has been successfully installed"

clear_cookies
go http://192.168.1.6:12000/

fv 1 name admin
fv 1 pass abc123

submit op
find "Log out"

It's pretty crude at the moment but I guess a good start. Couple with some other tools I'm working on, installing Drupal can be fully automated. The next step is to convert this twill script into Python equivalent to be more flexible.

Update

Here some good and better explanation on this from Lin Clark's blog.

kamal's picture

Drupal: Handling form field weight through CCK

If you have custom field added to the node form (probably using hook_form_alter), you have to manually set the #weight properties to order the element the way you want on the node form. CCK user definitely would miss the 'drag and drop' UI to rearrange CCK fields.

Turn out it possible to somehow 'register' your custom fields so that it can be rearranged using the CCK UI. Cool. I first found this in an old issue queue. Further 'googling' lead me to this blog post which describe it further.

The key is the hook_content_extra_fields that you can implement to return an array of fields to be managed by CCK. Then function content_extra_field_weight($node_type, $fieldname) can be use to set the weight properties on hook_view or hook_nodeapi view op.

kamal's picture

Drupal urlencode: Dealing with ampersand in filename

A bug poping out with some files failed to download, returning 404. Looking closer at the issue, turned out the files that failed contained ampersand "&" in the filename. PHP would translate the "&" in request path as a key in $_GET variable. So something like:-

$ wget http://www.somesite.com/system/files/fm/somefile_with_&_ampersand.pdf

would result in PHP $_GET as:-

array(
  [q] => system/files/fm/somefile_with_
  [_ampersand] =>
)

urlencode'ing' the path is not enough because PHP would still translate that to an ampersand.

kamal's picture

Debugging WSGI Application

One thing everyone like in PHP, print statement just work. You don't need any fancy debugger.

DebuggingTechniques does explain it well on how to debug your WSGI apps. It also explain why print would not work, all for good reason. My favorite debugger is the web debugger from Werkzeug but as explained in the wiki, to make it work with mod_wsgi you must make sure subsequent request from the debugger end up in the same process that trigger the error. That mean:-

StartServers 1
ServerLimit 1

kamal's picture

Build Debian package for Python modules

Just a note for future references. Tools to build Debian package for Python modules:-

Stdeb is not in Ubuntu Hardy repo so we need to build a package for itself first.

kamal's picture

PHP CLI Segmentation Fault With pgsql

"Segmentation fault"

Got this every time running PHP from the command line, especially when working with Drupal. It doesn't caused any harm (script working just fine) and that's why I never look into it. But accidentally found this post and the suggested fix did remove the "Segmentation fault" message from appearing.

  • Commented pgsql in pgsql.ini
  • Load pgsql extension in curl.ini, before the curl extension.
kamal's picture

Drupal: Where's my CCK content get stored in db ?

Wrote about internal CCK storage in my personal blog sometimes ago but looking through issues coming up recently in our issue tracker suggest that some of developers here still not sure where their CCK content are stored in the database. Briefly revising this topic to give some clue on where to look after when something goes wrong with our CCK related content.

kamal's picture

Drupal: Namespace your CCK fields

Not aware of this until it was too late. All CCK field was stored in a flat container in table node_field. It's not unique per content type. That means you cannot have two fields with a same name although that field was used in different content type. From the UI, if you create field with a same name, it'll just append an arbitrary number such as _0, _1 to make it unique.

kamal's picture

PHP development server

One thing that I like in various Python frameworks such as Django etc, they come with built-in development server that allow you to start developing the application without worrying much about properly setting up apache and all sort of things regarding deployment. Though personally, I'd prefer developer to have some knowledge in configuring apache (at least in their local environment) having some sort of development server still being useful even for myself.

Syndicate content