First week Tasks

It took pretty long time to get into my blog. The code is yet to be merged .But I must say it was challenging and interesting.

Task1: Display users who have completed a given task on the task detail page

How i did?

I wrote  a simple method to the model Task which returns the list of users who have completed the given task.

def users_who_completed_this_task(self):
return User.objects.filter(
taskattempt__in=TaskAttempt.objects.filter(, state=TaskAttempt.FINISHED)).distinct()

The property decorator lets you to access the method as an attribute of the class. So that if task1 is an instance of the model Task, task1.users_who_completed_task returns all users who completed the specific task.

My first unit test case

  • This was most challenging and exciting part.I wrote unit test cases for the code i wrote.Thanks to Bob silverberg for the helping me with  constant feedbacks. If you are new to unit testing this check this link.🙂

Task2: Add date completed in the Task Activity page

This was quite easy . 🙂

modified=attempt.modified.strftime(‘%Y-%m-%d: %I:%M:%S %p’).lower())

What i learned

    • Some simple filters used in jinja2 templates like strfttime. Here is a simple code snippet for a comma separated list of users in the template

 {% for each_user in users %}
{{ }}{% if not loop.last %},{% endif %}
{% endfor %}

  • Writing unit testcase

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s