Skip to main content

Posts

Django Log Files Viewer documents

Django Log File Viewer. This is a PYPI package django-log-file-viewer  documents. Github repo:  django-log-file-viewer@garmoncheg.github.com Usage: Useful to add log files view functionality to your Django admin web site. Instead of using database log files storage, it gives you ability to store/view log files through GUI. It requires a directory with Django log files to function. E.g. directory structure: $ project_dir / logs / : applog . log applog . log . 2012 - 09 - 22 . . . errors . log applog . log . 2012 - 09 - 22 . . . Screenshots: To parse/display these log files you need: 1. Install an app and add it to your settings.py INSTALLED_APPS section: # settings.py INSTALLED_APPS = ( # ... 'django-log-file-viewer' , # ... ) 2. Set UP 2 django variables in settings.py: # settings.py: LOG_FILES_DIR = '/path/to/your/log/directory' # Relative or static path string o...

SSH Unix/Lunux Recipes for daily usage.

I've decided to create a post with several recipes for commands I need to use daily. I use them from a Mac OS X Lion default console, except for some mac ports installed... Remote is special linux distribution. How do I Compress a Whole Linux or UNIX Directory?  You need to use tar command as follows (syntax of tar command): tar -zcvf archive-name.tar.gz directory-name Where, -z: Compress archive using gzip program -c: Create archive -v: Verbose i.e display progress while creating archive -f: Archive File name For example, you have directory called /home/garmoncheg/data and you would like to compress this directory then you can type tar command as follows: $ tar - zcvf data . tar . gz / home / garmoncheg / data / Above command will create an archive file called data.tar.gz in current directory. If you wish to restore your archive then you need to use following command (it will extract all files in current directory): $ tar - zxvf data . tar . gz Whe...

Python: simple recipe to measure your function's execution time

We always write something unusual while doing basic things. Our own bicycles and crutches to work out some unusual situation. Here is another recipe to do a thing like so. I have tried several libraries and readymade decisions. But it assumes you have them installed. And you often try things in console, don't you? Anyway the recipe is simple and quite straightforward. import datetime # Getting first timestamp t1 = datetime . datetime . now ( ) # Your function e.g.: data = [ g . name for g in request . user . groups . all ( ) ] # Second timestamp t2 = datetime . datetime . now ( ) print "Execution time: %s" % ( t1 - t2 ) It is rude and quite simple but may often suit you well to measure execution time in a simple and straightforward manner. Also nice idea to write down this function into logs. It may be handy on refactoring of your core app for e.g.; import datetime import logging log = logging . getLogger ( 'mylogger' ) # Getting ...

Django: Resetting Passwords (with internal tools)

I have had a task recently. It was about adding a forms/mechanism for resetting a password in our Django based project. We have had our own registration system ongoing... It's a corporate sector project. So you can not go and register yourself. Admins (probably via LDAP sync) will register your email/login in system. So you have to go there and only set yourself a password. For security reasons you can not register. One word. First I've tried to find standart decision. From reviewed by me were: django-registration and django password-reset . These are nice tools to install and give it a go. But I've needed a more complex decision. And the idea was that own bicycle is always better. So I've thought of django admin and that it has all the things you need to do this yourself in no time. (Actually it's django.contrib.auth part of django, but used out of the box in Admin UI) You can find views you need for this in there. they are: password_reset password_reset_...

Django: Unittest for HttpResponseRedirect method recipe

I like to invent bicycles in my code. They often come in handy and you basically do not rely on Django version... So upon updating your project's Django version in future times you will not have to refactor half of all the code. So... How do you test http redirects? I usually restrict my time in thinking and write code like if redirect target is hardcoded. And it really is in most of the times. But imagine if you decide to redirect your view response in several places. Or imagine if you're not the only one who owns you'r project's code and there are many collaborators that can change things without warning... And you need to have a test for that view that will test redirects and complex code behavior. I used to check redirects like so: response = self . cliet . get ( '/myview' ) self . assertEqual ( response . status_code , 302 ) # View redirected... All ok... But  if you have some view that can redirect to things that you need to check. How would y...

Blocking iOS to acces Contacts freely

There are lots of occasions when you want to be private in the net. Now it's common to say "Anonymous". Many people do not even think it's important. I, personaly, dislike facebook, skype, twitter, any else third party... having my contacts list synched to their server without even telling me...  I do not want to be truly anonymous, you know... Have nothing to hide really. But I want that really smal confirm that Skype, for e.g. would take my contacts and for what reason.  Facebook was first, as usual... They've done it. I really deleted their app from my iOS devices first. But instead of taking lessons from their mistakes... All huge companies gone wild about this possibility to copy some new ammount of user data... Skype was second (for me)... Then LinkedIn... However they warned and I've agreed... So nothing really bad to say about them. But MS is such a Microsoft... They want me to "skype" instead of "calling" my friends through ...

Twitter official client for Mac problem "Unauthorized" solving.

I had a problem "Unauthorized" in official twitter client for Mac. Tried several instal/reinstall. Deleted/Downloaded again from Apple App Store. It all didn't help. They seem to change something in authentication. So I've tried deleting all the config files in ~/Library/ Main solution that helped me: 1. Switch off the client. (be sure to Close an app) 2. Delete: ~/Library/Preferences/com.twitter.twitter-mac.plist.lockfile ~/Library/Preferences/com.twitter.twitter-mac.plist 3. Launch Twitter app and login from scratch. I have revoked access this twitter client too in my https://twitter.com/settings/applications  but it seem to make no effect. Making similar actions to TweetDeck for Mac does not help. So it seems like problem is somewhere deeper. Hope it will help you solve similar issue.