Showing posts from November, 2011

Django: Instalation of Dev environment on a clear Lion Mac OS X

Like lots of Apple fans around the world I've finally decided to upgrade my OS to Lion release. I have bought a new laptop and it was the case. I've waited for a weekend to prepared myself for sex. And it was it. Now I want to share my experience with you guys. For you not to spend to much time on those issues, I've did.

Anyway what I'm usually using is a Fresh 2.7 Python, Django, PIL, virtualenv and many many minor tools which exceed scopes of this article. I also use Eclipse IDE for Python Dev. So all this I had to install and make spinning till monday.

If anybody tells me that Macs do not have good tools for this. He will not be right. Maybe there some itches and scratches of head about:
"Why is not those things working" or "Why do they work not as preferred". But there always is a good "Googled" decision to handle that.
Anyway lets go to installing stuff.

Short brief Plan of out work:
1. Install Apple Development SDK + Xcode (free from…

Python: Debugging/Developing SMTP mail things

You often have 'situations' when you developing Contact forms, or any other forms which have to send emails with python. You have to install or have working SMTP server on your Dev machine like say 'monstrous' Sendmail or something like it. It can cause errors in Django/Python like [Errno 61] Connection refused:

[Errno 61] Connection refused

But python has it handled for you. Python's standard distribution has a test SMTP server that you can test sending mail with. It actually does not sends anything. But you can examine outgoing email message like you've actually send it.
Type something like:

python -m smtpd -n -c DebuggingServer localhost:1025

It will start a command line server on this console and it will print everything your server should send through SMTP.
Also make sure to modify mail sending code to use your non standart port number like so:

server = smtplib.SMTP(SERVER,1025) server.sendmail(FROM, TO, message) server.quit()

Or with 'sudo' (if you …

Django: Adding news archive. Querying models with date and time filtering.

Today I had some practice with filtering Django models by date.
Task was to archive old entries of the news. I've made 2 separate views for those. I was displaying actually news and another was ment to display archived items. Quite common task I guess. Also those 2 views are under wired buggy CMS, but we are not talking about that now.
Will save some examples for future of mine/someones usage.

Time. Subtracting a year from today with Python dateutil:

from datetime import date, timedelta - timedelta(days=days_to_subtract)
This example returns 'd' that has less days than specified in 'days_to_subtract'. timedelta function also can be fed with 'months', 'years' and so on. Becomes handy during time calculations. If you change this minus into plus you can calculate future time.

Filtering Querysets. Filtering by date ranges.

samples = Sample.objects.filter(,1,1), date__lte=datetime.…