Archive for the 'Websites' Category

Eclipse or Aptana en Pydev: “Project interpreter not specified”

After installing pydev in aptana (trying out for Django-development), I got this error message: “project interpreter not specified”. Apparently this is an error that mainly hits non-English speaking people, as I found no solution in English. Google translate helped me out, but I thought I’d save you the trouble:
Go to: Window>Preferences>pydev>interpreter-python where you can set the python interpreter. For me, the “auto-config” button worked just fine…

Drupal 6: adding and modifying html using javascript

A while ago, I had a simple website, with a simple js script for calculating a price based on some user input. The script uses an updater function that, after all required choices have been made (radio buttons), calculates the final price and shows the price. It does this by adding html to a predefined ‘price div’ (price.innerHTML = “…”) and setting it’s height from 0 to ‘auto’. Nothing fancy, but worked quite nice.
Upon changing the website for a Drupal site, I was confronted with implementing the js within Drupal. And even though it wasn’t really hard, it took me a while to figure it out, so I thought I’d share my findings, hoping they would be useful to somebody.

First of all, I created a normal page within Drupal. The downside of the method (to some people) is that I had to enable PHP for the page input. But as I am the only person ever seeing an input form on this particular site, I didn’t care too much. For adding the required js (and some extra css for that page), I used:

drupal_add_js(’sites/all/js/prices.js’); drupal_add_js(’sites/all/js/updater.js’);
drupal_set_html_head(‘<script type=”text/javascript”>
window.onload = function() {
includePrices();
};
');
drupal_add_css(path_to_theme().'/prices.css', 'theme', 'all', TRUE);
$styles = drupal_get_css();

And then I added an html form which calls the updater function on each click. This makes it possible to have the second choice customers have to make depend on the first choice they make.

<div onclick="update();" id="priceform">
<div onclick="update();" id="house_type">
<form id="typeform">
Type house:
<input type="radio" value="1" ...
</form>
...

Works like a charm for me...

Drupal: Random sort in Views 2

Without a doubt, the Views module is one of those Drupal modules without which Drupal wouldn’t be the same. With Drupal 6, Views got a major revision, and I must say I quite like the new interface. There was one thing that I couldn’t figure out immediately however: how to random sort the selection. I should have looked harder in the sort criteria – which is the most logical place to put it – but I was sort of expecting the possiblity to add randomness to any sort criterion I selected (e.g. node:type). Not so: in the list with all possible criteria, you have to select “global:random”.

Still not sure whether that is the most logical way of doing it. Personally, I would think adding “random” as a choice for each criterion (besides “ascending” and “descending”) would yield a much finer granularity and makes more sense. The fact that the random sort criterion is listed as “global:random asc” (asc for ascending) doesn’t really help changing this view either.

But probably there is a good reason for doing it this way. To paraphrase a French proverb: The programmer has his reasons that reason doesn’t know.