Archive | March, 2010

Tags: , , ,

Website Stress testing using JMeter

Posted on 31 March 2010 by BeardyGeek

Here’s my latest screencast, showing you how to stress test your website and web applications using JMeter.

Comments

Tags: ,

Adding Views to the Django Admin

Posted on 26 March 2010 by BeardyGeek

I recently had to write a view that exported data to csv.  The view had to be contained within the Django admin area, on a separate page from the rest of the apps and models.  Here is the approach I took.

The Urls

There are 2 ways to add urls to the admin: the quick and easy way, or the not so quick and easy way.  In this case, as I was only adding a single url, I went for the quick and easy way.  The other way involves extending the get_urls() method of AdminSite, adding to the existing admin url pattern.  I did this:


(r'^admin/mypage/$', 'myapp.views.my_admin_view'),
(r'^admin/', include(admin.site.urls)),

Make sure you add your page before the main admin include.

The View

When you write your view make sure you use the staff_member_required decorator.


from django.contrib.admin.views.decorators import staff_member_required
...
@staff_member_required
def my_admin_view(request):
    # view code

When rendering your view, also make sure you pass RequestContext to the template:


return render_to_response('my_template.html',
  context_instance=RequestContext(request))

The Template

So that your view looks like it belongs in the admin area, you need to extend the admin base site template:


{% extends 'admin/base_site.html' %}

You’ll also want to add in i18n support, and the admin media:


{% load i18n adminmedia %}

If you want to add in extra styles you can use {% block extrastyle %}, and you could put javascript in {% block extrahead %}.

Adding form date widgets

If you have a form on your page that includes date fields, you might want to have the nice django javascript form widgets. First you need to add the widgets to your form:


from django.contrib.admin import widgets

class AdminForm(forms.Form):
    start_date = forms.DateField(label="Start date",
         widget=widgets.AdminDateWidget())

Next you need to add in the following to your extrahead block (replace admin-media with whatever you’ve set your admin media url to):


<script type="text/javascript" src="/admin/jsi18n/"></script>
<script type="text/javascript" src="/admin-media/js/core.js"></script>
{{ form.media }}

You also need to add the admin forms css in the extrastyles block:

{{ block.super }}
<link rel="stylesheet" type="text/css" href="/admin-media/css/forms.css" />

Breadcrumbs

If you want to have the breadcrumb trail at the top of the page, you need to create your own breadcrumb:


{% block breadcrumbs %}<div class="breadcrumbs"><a href="/admin/">
{% trans "Home" %}</a> > My View</div>{% endblock %}

Adding a link to the admin index

When I add a link in, I like it to go in one of the right column boxes, so I usually create a new one and put it above the recent actions box. To do this, you need to override the admin index.html file.

Create a directory in your templates directory called admin. Then copy the index.html file from django/contrib/admin/templates to your new directory.

You’ll see a block called ’sidebar’. Under the ‘content-related’ div, place the following:


<div class="module">
  <h2>Admin tools</h2>
    <ul class="actionlist">
      <li class="changelink">
        <a href="/admin/mypage/">My View</a>
      </li>
    </ul>
</div>

Enjoy!

Comments

Tags:

New Django Site – The Great British Sleep Survey

Posted on 24 March 2010 by BeardyGeek

I’ve very recently finished a django based site for a company called Sleepio.  The project was to create a survey site, called the Great British Sleep Survey. Once completed, it calculates your sleep score and creates a report tailored to your issues (or lack of).

Also working on the site, doing all the xhtml and css magic was Rui Zhang from borderleft. If you ever need anyone to turn your designs into an actual web site, he’s your man. Thanks Rui.

One of the co-founders of Sleepio is Professor Colin Espie, who runs the sleep centre at Glasgow University.  The site is also a collaboration with Boots Web MD, which offers health and medical advice.

So check it out, complete the survey (you get a free sleep report!), and any feedback is always welcome.

Comments

Tags:

Google Calls for Link Spam Reports

Posted on 04 March 2010 by BeardyGeek

Spam

[image attribution]

In Matt Cutts latest blog post, he calls for users to report any sites they deem ’spammy’. On the report form, this includes anything that is considered:

  • Hidden text or links
  • Misleading or repeated words

Matt says that Google have been working on new algorithms to detect link spam, and it seems that through this manual reporting process, Google users will be helping to ‘train’ the system to be more effective.

It doesn’t say yet what action will be taken upon finding such a page, and whether Google will allow webmasters to make amends or defend themselves.  So look out for tales of woe from people removed from Google’s index for spurious reasons.

Comments

Bullguard Internet Security
BullGuard Antivirus


Twitter Buttons