Get Online Users in Django

I was upgrading my Django Bookmarks site, and I wanted to list the online users. I searched the internet and I found a simple method, but it doesn’t work properly. So I developed my own method. Why the simple method didn’t work? The problem with it is that it depends on the last login date in the user model. This field is updated on every login for the user. Imagine the following scenario: The user X logs in @ 1:00 pm. The user X posts a new post @ 1:30 pm. The user X comments on a previous post @ 1:35 pm. The user X leaves the website @ 1:40 pm. The user X comes back to the website @ 3:00 pm. The user X is logged in since the session cookie has not expired yet. The user X posts a new post @ 3:15 pm. A guest enters the website, and looks at the online users corner. The guest won’t see X’s name in the list of online users, simply because X’s last login date is @ 1 pm, even though user X is now online and he has just posted a new post. ...

September 21, 2009 · 6 min · Abdullah Diab

I’m Learning Python part 10 (last one)

I'm Learning Python part 10 <p> <h1 style="font-size:18pt;font-family:Verdana;"> (last one) </h1> <p> <img src="http://www.python.org/images/python-logo.gif" alt="Python Logo" title="Python Logo" /> </div> <h1 style="font-family:Georgia;"> Back to blogging </h1> <p> As usual, I will apologize for not blogging for a long time.<br /> I have been very busy, university exams, university projects, job projects, teaching and learning. </p> <h1 style="font-family:Georgia;"> Python Course </h1> <p> At Damascus University, in the faculty of informatics we managed to create free courses to students, and I was one of the teachers there, I taught Python to students.<br /> As far as I know this course was the first Python course in Damascus University.<br /> Even though the students were a few (actually a very little few about 8 ~ 10 students) the course was great. We managed to learn Python 2.6 Syntax, a little bit of its standard library and a little bit of PyQt4 in about 7 days x 2 hours daily.<br /> As far as I know too, students understood it and found it great, and I hope they&#8217;ll be using this great language more in their programs. </p> <h1 style="font-family:Georgia;"> Why last one? </h1> <p> The tour with Python ends here, while it ends here it starts here too, it ends here because so far you&#8217;ve learned what you need to start your own path in Python. And it starts here because you&#8217;re fully equipped with the base tool to discover more tools, I&#8217;ll let you discover the standard library and 3rd-party libraries on your own, because everyone differs in his/her interests.<br /> I&#8217;ll be blogging more on more technical issues but they might not be I&#8217;m Learning Python series :).<br /> Let&#8217;s stop talking here and move directly to the heart of our last lesson.<br /> ...

September 15, 2009 · 7 min · Abdullah Diab

I’m Learning Python part 9

I’m Learning Python part 9 <p> <img title="Python Logo" src="http://www.python.org/images/python-logo.gif" alt="Python Logo" /></div> <h1 style="font-family:Georgia;"> Classes In Python </h1> <div dir="ltr"> As I told you before, Python is a powerful programming language, and powerful it won&#8217;t be without Object Oriented design. </div> <div dir="ltr"> Python supports both Pure Object Oriented Programming (Every thing must be in a class) and Structural Programming (You can type code everywhere). </div> <div dir="ltr"> It supports also other programming paradigms like Functional Programming. I won&#8217;t write about OOP and its uses, why we should use it, I&#8217;ll just give you the keys to use OOP in Python. </div> <h1 style="font-family:Georgia;"> Defining a Class </h1> <p> Classes in Python are defined like this: </p> <p> ...

March 20, 2009 · 8 min · Abdullah Diab

I’m Learning Python part 8

I’m Learning Python part 8 <p> <img title="Python" src="//www.python.org/images/python-logo.gif" alt="Python" /></div> <h1 style="font-family:Georgia;"> Python 3.0 </h1> <p> Since the last time I wrote an article Python many changes happened in my life, one of them is the release of Python 3.0 (Which is known also as Python3K and Python3000). </p> <p> Python 3.0 is the first intentionally backwards incompatible Python release, which means that there are some changes you must notice before start coding in Python 3.0. </p> <p> Don&#8217;t worry that much, the language has become more useful, and also there is <a href="//docs.python.org/library/2to3.html">2to3 source-to-source conversion tool</a> which converts your Python 2.x code to meet the requirements of Python 3.0 🙂 </p> <p> To find more about change in Python please refer to <a title="What's" href="//docs.python.org/3.0/whatsnew/3.0.html">Python website</a>. </p> <p> ...

February 20, 2009 · 6 min · Abdullah Diab

I’m Learning Python part 7

I’m Learning Python (part 7) <p> <img title="Python Logo" src="http://www.python.org/images/python-logo.gif" alt="Python Logo" /> </p> Apology: First of all I wanna apologize for being late with this part, I’ve had busy days first during Shaam 2008 expo and second during some studies at the college and last busy time past launching Bawabaty project. ...

November 28, 2008 · 4 min · Abdullah Diab

I’m Learning Python part 6

I’m Learning Python (part 6) <p> <img title="Python Logo" src="http://www.python.org/images/python-logo.gif" alt="Python Logo" /> </p> Dictionaries Dictionaries in Python are like dictionaries in life, they consist of key-value pairs, each key maps a value, values can be any object type, and keys also. Keys must be unique, I mean that we can’t have two identical keys with different values. ...

November 7, 2008 · 6 min · Abdullah Diab

I’m Learning Python (part 5)

I’m Learning Python (part 5) <p> <img title="Python Logo" src="http://www.python.org/images/python-logo.gif" alt="Python Logo" /> </p> String Is Immutable? Last time I told you to try to change a specified character, you must have failed if you tried: >>> s[0] = ‘c’ The error you’d get is: TypeError: ‘str’ object does not support item assignment This means that strings are immutable, so are core-types, numbers and tuples, they can’t be changed, while lists and dictionaries can be changed freely. ...

October 29, 2008 · 5 min · Abdullah Diab

I’m Learning Python part 4

I’m Learning Python (part 4) <p> <img title="Python Logo" src="http://www.python.org/images/python-logo.gif" alt="Python Logo" /> </p> Why Use Built-In Types? Most of the time in programming you’ll use lists, stacks, arrays, queues and dictionaries, so instead of constructing them, Python gives you a bunch of built-in types to use. The built-in types implement the semantic of the type ADT (Abstract Data Type), and they are fast, ‘cuz some of them are written in C and C++. ...

October 15, 2008 · 4 min · Abdullah Diab

I’m Learning Python part 3

I’m Learning Python (part 3) <p> <img title="Python Logo" src="http://www.python.org/images/python-logo.gif" alt="Python Logo" /></div> <h1 style="font-family: Georgia;"> What Is Interactive Mode? </h1> <p> When you install Python on your platform you&#8217;ll find an executable called &#8216;python&#8217;, when you run it you&#8217;ll find a terminal and you&#8217;ll see something like the following:<br /> <em>Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win32<br /> Type &#8220;help&#8221;, &#8220;copyright&#8221;, &#8220;credits&#8221; or &#8220;license&#8221; for more information.<br /> >>></em><br /> This is called interactive coding (or interactive mode), here you can write Python statements and the interpreter will execute them directly, let&#8217;s try:<br /> <em>>>> print &#8220;I Love Python&#8221;<br /> I Love Python<br /> >>> print 2 ** 10<br /> 1024<br /> >>></em><br /> ...

October 10, 2008 · 6 min · Abdullah Diab

I’m Learning Python part 2

I’m Learning Python (part 2) <p> <img title="Python Logo" src="http://www.python.org/images/python-logo.gif" alt="Python Logo" /> </p> Who Uses Python? In the world there are more than 1 million Python user, that’s because it’s open source, and because it is implemented for every platform, and it comes included within Linux distributions and Macintosh computers and more. Google uses Python in its web search system, and it employs the Python’s creator. YouTube is largely written in Python. BitTorrent file sharing system is a Python program. Intel, Cisco, HP, Seagate, Qualcomm and IB< use Python for hardware testing. Industrial Light & Magic, Pixar, and others use Python in the production of movie animation. NASA, Los Alamos, Fermilab, JPL, and others use Python for scientific programming. iRobot uses Python to develop commercial robotic vacuum cleaners 🙂 NSA uses Python for cryptography and intelligence analysis. See Python website for more. ...

October 7, 2008 · 5 min · Abdullah Diab