CRUD in Drupal

No. Not crud. CRUD. Create, Read, Update, Delete. The basic operations a web app needs to do on database records.

I’ve been working on the Provisionator module, which helps with institutional-scale deployments of Drupal sites on a shared hosting server. The module began life as a separate PHP application, and evolved into a Drupal module wrapping those functions. It essentially managed a table within a Drupal site’s database, adding rows for each website deployed.

I was just working on adding the rest of the CRUD support (it already handled Create and Read OK, but not Update (edit) nor Delete). I was looking for The Drupal Way when it hit me. I don’t know why I didn’t see it before.

I don’t need to manage a table, nor do I need to manually implement CRUD operations.

All I need to do is define a custom content/node type, and let Drupal take care of the basic CRUD operations. The Provisionator module will then simply implement relevant bits of the node API and have it get called when nodes of the appropriate type are inserted, edited, or deleted. I can add whatever “fields” I want as properties of the custom node type, so it should be easier to extend than the current hard-coded table.

I’m going to attempt converting to the Drupal node + hooks + node API pattern ASAP. I think it’s going to be relatively straightforward, and offers some pretty cool benefits. Instead of having an essentially static list of sites in a custom database table, I’ll be able to add sites (as nodes) to various taxonomies, enable comments on the site node, and easily implement various permissions (user can create sites, user can list sites, user can edit all sites, user can edit own sites, user can delete all sites, user can delete own sites, etc…)

Portable Camera Storage on the cheap?

I’m planning a vacation in the spring. The tickets are all in place, and we’re looking forward to it. Can’t say more, because it’s a surprise Christmas present. I’d love to leave the laptop at home, but would currently need to bring it along to dump photos off the camera every day.

Does anyone have any great (and cheap) solution to offload photos from a camera (Canon Digital Rebel xt) without a laptop? I’ve got a 5G iPod (30 Gig), and have looked at the Apple and Belkin media readers – both of which apparently suck the soul out of the battery before finishing the job.

I’ve seen some pretty sweet portable hard drive systems (Epson P-3000, Smartdisk Photobank, XS Drive Super, etc…), but I’m not going to spend $800 for a handy camera offloader, no matter how cool it is.

Lazyweb, help me! What’s the best bang-for-the-buck solution? DIY is OK, too. Oh, and Epson? If you want to send me a P-3000 to review, I’d be more than happy to test it out…

Custom Fields in Drupal Event Signups

We’re using the Event module to list our workshops at the Teaching & Learning Centre, and the Signup module to let people register to attend workshops (or other events). It’s working really quite well, but we needed to add some extra fields to the registration form so we could track Faculties, Status, etc…

“Sure,” I said, “Drupal’s open source, so we should be able to add any fields we want. Worst case scenario? We’d have to fork Signup.module and maintain our own version with our custom fields in it.”

I then proceeded to drag my feet, not looking forward to having to maintain a module for something as simple as adding some custom fields. Maybe I could use the FormsAPI and insert the fields through some custom code?

So, I poked through the signup.module source code to see what would be involved. I’d braced for some rather convoluted and involved hackery. I blocked my schedule for the day so I’d have time to dedicate to the task.

Then, I saw that the module developers had already done the work for me. They implemented the signup form’s fields as a themable method, letting me override it on a per-theme basis. Without having to touch the code for the module itself. Brilliant. Absofrakking brilliant. So, I added this code to our theme’s template.php file (the theme is called “uofc_thisisnow”):

function uofc_thisisnow_signup_user_form() {
    $form['signup_form_data']['#tree'] = TRUE;
    $form['signup_form_data']['Name'] = array(
        '#type' => 'textfield', 
        '#title' => t('Name'), 
        '#size' => 40, 
        '#maxlength' => 64
    );
    $form['signup_form_data']['Phone'] = array(
        '#type' => 'textfield', 
        '#title' => t('Phone'), 
        '#size' => 40, 
        '#maxlength' => 64
    );
    $form['signup_form_data']['Faculty'] = array(
        '#type' => 'textfield', 
        '#title' => t('Faculty or Department'), 
        '#size' => 40, 
        '#maxlength' => 64
    );
    $form['signup_form_data']['Status'] = array(
        '#type' => 'select', 
        '#title' => t('Status'), 
        '#default_value' => t('Faculty Member'), 
        '#options' => array(
            'faculty' => t('Faculty Member'),
            'staff' => t('Staff'), 
            'student' => t('Student'), 
            'other' => t('Other')
        )
    );
  return $form;
}

That results in a signup form that looks like this:

TLC Workshop Signup with Custom FieldsTLC Workshop Signup with Custom Fields

The beauty of this, since it exposes the full FormsAPI, we can add select menus, radio boxes, default values, etc… Without having to touch the code of the Signup module itself. Very cool stuff.

TED Talks are changing how I think

I’ve been slowly working through the TED Talks video podcasts – making time to watch several sessions each week. I can’t even begin to describe what an impact they’re having on me. I’m starting to think differently about many issues – some I hadn’t even considered before, others I thought were outside of my reach.

I watched Majora Carter’s presentation this morning. She is the founder of Sustainable South Bronx – a grassroots movement she started in her community to try to bring it back from the brink of ecological (and social and economic) devastation.

I live in a pretty well-off community, in a pretty well-off city, in a pretty well-off country. I hadn’t given much thought to the connection between ecological, social and economic planning and well-being. Hearing about what happened to the South Bronx as a result of wanton exploitation of a marginalized region’s resources (human and environmental) made me wonder what we’re doing here in Alberta, where our entire province feels like it’s sole purpose is to extract oil from the tar sands. I’m wondering what impacts we’ll be seeing in 60 years…

I also watched Sir Ken Robinson’s session on creativity in the education system. Another absolutely amazing and provocative presentation that’s changed how I think about “non academic” education. If we don’t value and reward creativity in our young people, rather than drilling it out of them through an industrialized worker bee factory, we’re wasting the skills and talents we’ll need to remain flexible as a society.

The session list goes on and on. Al Gore on the environment. Jimmy Wales on Wikipedia. Negroponte on the $100 laptop. Aubrey de Grey on extending or preventing senescence (now THAT’s something that will have a HUGE impact – ethical and moral implications on both sides of his argument). Every single session has sparked something for me. I’m positive I’ll be percolating much of it in my head for years to come.

The CogDogBlog Will Be Back Soon

I got an email from Alan last night mentioning that his blog was actually knocked offline by the overzealous actions of spammers. They were hammering his site so hard that his host had to kill the site. He had been running the CogDogBlog on some graciously donated webspace, so it’s understandable that they weren’t thrilled about the load that spammers can add to a server.

Unfortunately, Alan’s got a Day Job which is currently in conference management mode (i.e., traveling and busy) so he’ll be trying to get things back up and running in the few spare milliseconds he can eke out in the next little while.

Yet another reason why Google needs to step up and show some serious corporate responsibility in helping to actually solve the spam problem created by Adsense. Come ON, Google, what’s it going to take? How many billions of spamments need to be inflicted on blogs, wikis, and other open web spaces before you’ll act?

I’ve outlined some potential ways to solve the problem, but curiously never heard from Larry or Sergey.

Flickr: Public Artwork Hacks

The Conversation - improvedWhile browsing the Flickr photos from Calgary, I came across this one by Sherlock77. It prompted a brief discussion, wondering if there was a group for people to put photos of public artwork that had been hacked (or dressed, or modified, or adorned) – legally and non-destructively. I did some searching, but didn’t find anything. So, I created a public group: Public Artwork Hacks.

If you have (or plan to take) photos of public artwork that has been “improved” – here’s the place to share it. Put a Santa hat on The Thinker. Sunglasses on David. Photos that include modifications – without the use of Photoshop to add things – are welcome!

The group is currently rather empty, but it should be cool to see what (if anything) happens. ‘Tis the season for hacking public artwork

Apkakkallli: PFO!

Dear Apkakkallli spammer,

P. F. O.

You are not going to win. I will not let you vandalize my blog. Get a clue. Your 24,712 (and counting) attempts recently have all failed. Every. Single. One. Move along. Or, better yet, get a job (or a life). All you’re succeeding in doing is wasting my time, and the resources of my server. And in pissing me off, which guarantees that you will not succeed here.

You may as well point your spambot zombie farm somewhere else – or better yet, decommission it, rather than inflicting your inane Google-powered vandalism on other people. I count over 800,000 references to Apkakkalli in Google right now, including a handful of old spamments that temporarily snuck through onto my blog. And that’s with duplicates removed, so the total count of your spamments is likely in the millions. That’s a LOT of spam you’ve foisted on the blogosphere. I really hope that Karma comes back to you. Really soon.

If you’re ever in Calgary, give me a shout. I’d love to, er, buy you a coffee or something. Yeah. That’s it. A coffee…

Dreamtube

Dreamhost rocks. I mean, they just keep piling on awesome new features into their hosting package. Recently, it was essentially infinite bandwidth and storage. Yesterday, they added an automatic Flash video transcoder and presenter, ala YouTube. But, within any Dreamhost site.

All I have to do is upload a video file (.avi, .mov, .mp4) to my site, tell Dreamhost I want it converted to Flash video (using the panel.dreamhost.com site that’s used for managing everything else as well), and their magic elves do their work and email me a javascript snippet to embed a flash player in any web page (or blog post). Like, for instance, this one:

[flv:http://www.darcynorman.net/video/banffdaylight_640x320.flv 640 320]

It seems to choke on some video formats (it didn’t like my screencast at all – perhaps it’s not able to deal with the H.264 video encoding or AAC audio encoding…)

Now, if only Dreamhost would solve the intermittent MySQL performance suckage, things would be perfect!