timi 1 Follower

I work by Tesobe for a practical year

Location: Berlin

Quick Links

View Show Available Profiles


Posted
timiKnight News Challenge: Feowl: Networked data-collection & power cuts monitoring (feed)
Knight News Challenge: Feowl: Networked data-collection & power cuts monitoring:...
(This is an imported feed item. You can read the original item at http://azd325.tumblr.com/post/20116852655)

timi
1 month, 3 weeks ago, 0 Comments

timiHello World (feed)

Hello, to my new blog.

It was build with Jekyll Bootstrap and Twitter Bootstrap. I will try to start to blog about some topics. Some Linux, Source Snippets, ...


(This is an imported feed item. You can read the original item at http://azd325.github.com/2012/03/18/hello-world)

timi
1 month, 3 weeks ago, 0 Comments

timiDjango: Setting Headers in your Response (feed)

Today I found a interesting part in the Django Docs about set and remove of headers in responses.

response=HttpResponse()# Created a HttpResponseresponse['Cache-Control']='no-cache'# Set Cache-Control Headerdelresponse['Cache-Control']# Remove Cache-Control Header

I know that should be do the web server like Apache but sometimes is it nicer (even recommended) to set in some cases the headers in web app directly, to test the behaviour or to make really sure to get the right headers in the response if you don't have anytime access to the server config's or a lazy sys-admin.

FYI:

Set and Remove in the Django Docs

Content-Disposition example


(This is an imported feed item. You can read the original item at http://azd325.github.com/Web/2012/03/21/django-setting-headers-in-your-response)

timi
1 month, 3 weeks ago, 0 Comments

timiDjango: Pre-Validation with the URL dispatcher (feed)

I work currently on a rating feature, to rate some items and I want to do this in one view to handle the methods POST and GET.

POST should handle the submit request(rate count) of the item

GET should handle the template with the right item to see the current user/ global rate

Situation:

  • max. stars = five
  • min. stars = one
  • zero stars are not possible to vote

What we need to rate?

  • item id
  • vote result

I start to add the first version of the view and I was adding two URL's one for GET and one for POST. And I what to handle the parameter over the named groups in Django.

urlpatterns+=patterns('',url(r'^ajax/votes/(?P\w+)/$','vote_for_item'),# GETurl(r'^ajax/votes/(?P\w+)/(?P\d+)/$','vote_for_item')# POST)

What we can to be more explicit?

We can use re of Python and so we can set a range of allowed numbers with [1-5]. So we have only a range of URL's for every state of the rating situation and so we get a 404 if we want to access for example the vote-URL with the vote count of six.

urlpatterns+=patterns('',url(r'^ajax/votes/(?P\w+)/$','vote_for_item'),# GETurl(r'^ajax/votes/(?P\w+)/(?P[1-5])/$','vote_for_item')# POST)

The next thing we have to two exact same URL's the only difference is that the POST needs an extra parameter.

Can we make this parameter optional?

Yeah, we can do it again with re. We have to wrap the vote part in (?:...) and after it a single ?. More in the Python Docs.

The end solution:

I have one URL for the cases of GET and POST and we create only the URL's what I need for the rating feature

urlpatterns+=patterns('',url(r'^ajax/votes/(?P\w+)/(:?(?P[1-5])/)?$','vote_for_item'),)

FYI:

Optional named groups Python re

URL dispatcher at Django Docs

re at Python Docs


(This is an imported feed item. You can read the original item at http://azd325.github.com/Web/2012/03/22/django-pre-validation-with-the-url-dispatcher)

timi
1 month, 3 weeks ago, 0 Comments

timiPycon 2012: Stop Writing Classes (feed)

By: Jack Diederich@jackdied

Classes are great but they are also overused. This talk will describe examples of class overuse taken from real world code and refactor the unnecessary classes, exceptions, and modules out of them.


(This is an imported feed item. You can read the original item at http://azd325.github.com/Python/2012/03/23/pycon-2012-stop-writing-classes)

timi
1 month, 3 weeks ago, 0 Comments

Followers (1)

Alex