With Django 1.5, one of the biggest changes introduced was the ability to configure the user model. Anyone who has coded a Django app with a business requirement of adding a birthday field, an arbitrary checkbox to the user registration fields, or even making the signup process email-only with no usernames, knows the awkward feeling of implementing their own custom user and feeling a little less Django-esque when all is said and done. This configurable user model change alone was enough for me to 1) upgrade all my Django sites to 1.5 and to 2) swap out my customer user code for the way it should be done now with the configurable user model.
The Django docs are fantastic. It is one of the most comprehensive and, most important, user-friendly documentations out there for programmers of all skill levels. I highly encourage you to read through the docs first on customizing the user model, but isn't required to understand this walk-through.
If you're anything like me, you sometimes like to skim or even skip the docs altogether, and turn to Google to try and find a solid example online. I found a few, but none of them really seemed to show me a full example of configuring the user model. As a result, I decided to write my own and put it all together in an example Django project to show how I handled the custom user model. Here is the link to the repo on Github.
This is going to be a brief walk-through in running this example codebase. It is opinionated, but (hopefully!) easily understood - so this would enable you to modify this example codebase slightly to fit your business requirements.
Also, this custom user example is inspired from Dr. Russell Keith-Magee's great talk at DjangoCon US 2013 titled "Red User, Blue User, MyUser, auth.User" and should serve as a good example for how you can change the core fields of auth.User.
Please note - this walk-through will assume you have pip and virtualenv installed locally, as we'll be using that to create the environment for the example Django project.
First, clone the example custom user project and change directory into it:
$ git clone https://github.com/jonathanchu/django-custom-user-example.git $ cd django-custom-user-example
Then, create your virtual environment. We'll only be installing Django (v1.5.4):
$ mkvirtualenv customuser (customuser) $ pip install django
After Django is installed, let's run
syncdb to create our test DB and first superuser. This is configured out-of-the-box to use SQLite3 for simplicity, but feel free to change to whatever database backend you feel more comfortable with. Create your superuser now and follow the prompts:
(customuser) $ python manage.py syncdb ... ::Follow prompts to create a superuser::
Then we can run
runserver to checkout how the custom users in the admin looks:
(customuser) $ python manage.py runserver
And open up your browser to http://127.0.0.1:8000/admin and log in with the superuser you just created. Under "Accounts", you will see our custom "Users" there. Try it out, take it for a spin, create additional users from the admin, change passwords, etc. This all works nicely with our custom user model!
Hopefully this is helpful to some out there looking for a solid example on customizing the User model. Any issues with the codebase, please use the repo's issues tracker on Github. Happy hacking!
I've been a big fan of Notational Velocity for quite a few years now - and more recently, nValt which is a popular fork of Notational Velocity, but with a bit more features. Everyone has their own process when it comes to taking notes, and to each his own, but the one thing that really turned me on to Notational Velocity/nValt is the simplicity and unstructured process of taking and searching for notes. Coupled with Dropbox for seamless syncing, you have yourself a great note taking process that was easy to use and even easier to search. As for mobile, I used Simplenote to view my notes via Dropbox, and it made taking notes during programming meetups or business meetings even easier. Life is good!
However, over the past year, as I found myself coding more and more in my text editor of choice, Emacs - the more I found myself wanting something that didn't seem so disconnected from where I do most of my prose and coding. After a quick search, I found Jason Blevins' great little creation called Deft. To sum it up, Deft is an open source mode for Emacs to view, record, and search for notes in plain text, very much like Notational Velocity/nValt. I highly encourage you to check out Jason's project page for Deft. After trying out Deft, it made me want to switch 100% over to org-mode notes as I really only used org-mode for sporadic notes. Now, I have the power of org-mode with Emacs in a Notational Velocity-like buffer with Deft. The rest of the article will be outlining how I set it up in my Emacs config.
Setting up Deft
First, go grab deft.el and make sure it is available in your Emacs config (i.e. - ~/.emacs/vendor/deft.el path). You can grab it here or get it directly from my Emacs config, which is the original unmodified file.
deft.el is on your Emacs load path, you'll need to tell Emacs to use Deft. Put the following anywhere in your config (I like to keep
modes separated in it's own
modes.el file that gets loaded on initialization):
Since I use Org-Mode, I want
*.org files to be recognized by the Deft buffer, so let's set the
deft-extension to "org". I believe the default file type that Deft will look for is "txt", so omit this part or add in "txt" if you want to use plain text files.
(setq deft-extension "org")
And again, since I'm using org-mode with Deft, let's set the
deft-text-mode appropriately to use org-mode:
(setq deft-text-mode 'org-mode)
Next, we need to tell Deft where to find all of my current org-mode files. In my case, I like to keep all my org-mode files in Dropbox, so that path would be
~/Dropbox/org for me. You should change this path to wherever you keep your files.
(setq deft-directory "~/Dropbox/org")
Finally, the last bit of customization is to tell Deft to use the filename as a title. By default, Deft will use the first line of the file as the filename. In my note taking preference, I normally don't lead off a note with the title of the file (it's usually a date like "2013-08-15" if it's a meeting), so I switched on the trigger for this:
(setq deft-use-filename-as-title t)
Putting it all together, and you have this in its entirety:
;; deft (require 'deft) (setq deft-extension "org") (setq deft-directory "~/Dropbox/org") (setq deft-text-mode 'org-mode) (setq deft-use-filename-as-title t)
To enter the Deft buffer, simply do:
m-x deft ENTER
And you should see the Deft buffer like so, with all of your org-files (yes, I know - nothing is blurred out...I got nothing to hide :P ):
Start typing and you'll see the list of notes filter out the results that do not match, just like Notational Velocity. Hit ENTER to open the note in a new buffer.
And there you have it! Much appreciation and thanks goes to Jason Blevins for this awesome mode that has effectively streamlined my coding and note-taking all in Emacs!
Throughout the years, I've flipped back and forth between Org-Mode and applications such as Drafts (iOS), Evernote, Simplenote, and even plain ol' text files (with the Notational Velocity and nValt) for my most basic note-taking needs; however, I've always found myself coming back to Org-Mode in the end for another spin around the block. The one positive thing that kept me coming back to Org-Mode, and perhaps the same thing that Emacs is often criticized for, is the fact that it has a lot of functionality under the hood - almost too much. Org-Mode is a very feature-rich application. For my basic needs, I use Org-Mode primiarly for three things:
- Basic note-taking and outlines
- TODO lists
- Tracking and clocking time
Here Comes MobileOrg
When I first learned about MobileOrg, I was really stoked that I would be able to record notes, update TODO statuses, and even just view my org files on the go. Unfortunatley, I found that the basic setup instructions on their website left a few minor things out for someone new to MobileOrg, and this is my attempt to supplement that to help others with the same issues I faced with setup.
First off, it should be noted that I'm using Emacs 24 with Org-Mode already baked in. If you're using an earlier version of Emacs that doesn't have Org-Mode by default, please install it according to your own preference (which we won't get into here since there are a few different ways to install Org-Mode).
My root directory for all of my org files is kept in Dropbox in a directory called
I've found that this setup fits my workflow best since I also work off a second laptop at times and would like all my org files to be synced across all machines with as little effort as possible.
Next, install MobileOrg from the App Store. I chose the path of least resistance and decided to use Dropbox as the source for server config, so when you first open the application, click on the Dropbox option, click to link account, and allow authentication with Dropbox to proceed. It should have created a new directory for you under:
Emacs Configuration for MobileOrg
You will need a few more lines of code to get this all working with your local org files and MobileOrg. This is my basic config based on the two main directories above that will need to go in your Emacs config:
;; mobileorg settings (setq org-directory "~/Dropbox/org") (setq org-mobile-inbox-for-pull "~/Dropbox/org/inbox.org") (setq org-mobile-directory "~/Dropbox/Apps/MobileOrg") (setq org-mobile-files '("~/Dropbox/org"))
Finally, from within Emacs - edit any org file located in
~/Dropbox/org/ and save those changes. Then send these changes to MobileOrg to sync up:
With any luck, you should be able to go back to MobileOrg on your mobile device and click the refresh button to see your org file(s) all there.
Recently, I updated all of the packages I have installed via Homebrew and ran into some issues with the PostgreSQL package. I was getting this error:
The data directory was initialized by PostgreSQL version 9.0, which is not compatible with this version 9.1.4
A quick search took me to this page, however the docs left a lot to be desired to say the least. Here's a step-by-step to how I eventually fixed it using pg_upgrade.
First, change directories to your Postgres data directory.
$ cd /usr/local/var
Next, create a new directory for the new data directory.
$ mkdir postgres9
initdb to initialize the new Postgres cluster in the new data directory you created above.
$ initdb /usr/local/var/postgres9
pg_upgrade with the following arguments:
$ pg_upgrade -d /usr/local/var/postgres/ -D /usr/local/var/postgres9 -b /usr/local/Cellar/postgresql/9.0.4/bin/ -B /usr/local/Cellar/postgresql/9.1.4/bin/ -v
If all goes without error, you can switch the data directories so Postgres will point to the right source.
$ mv postgres postgres9.0.1 $ mv postgres9 postgres
You can delete the script left behind by
$ rm delete_old_cluster.sh
I actually had my old Postgres instance running, so I had to stop it before restarting the new one:
$ pg_ctl -D /usr/local/var/postgres9.0.1 stop -m fast
Then I restarted the new Postgres instance:
$ launchctl unload -w homebrew.mxcl.postgresql.plist $ launchctl load -w homebrew.mxcl.postgresql.plist
And you're done - this should fix the PostgreSQL incompatible data directory issue.
I have a Buffalo TeraStation that I bought in 2006 to store all my big media files. Through the years it has served me well, although with Mac OS X Lion, connectivity to the TeraStation stopped working altogether - mainly due to Lion's changed AFP connectivity. Usually with hardware of this age, it would be simply replaced; however, I've always found Buffalo's hardware to be of great quality which is a testament to how long it's lasted. Sadly, installing OpenTera has been on my TODO list for roughly a year now, so this fix is overdue. Buffalo officially responded that there will be a firmware fix for this in the future, but that was over a year ago. This is a quick walkthrough of how I got read/write access back on the TeraStation through Mac OS X Lion. Note: I did the download and firmware updates from my Windows PC, telnet from Mac OS X Lion.
1) Find out the firmware version of your TeraStation. At the time of writing, I have v2.14. Download the corresponding firmware version from this site and install it. This is essentially the same firmware but with telnet enabled. You'll need telnet enabled to log into the TeraStation to install OpenTera.
2) Download OpenTera Update v5 and Samba 3 from this site. Unzip and move this on the TeraStation where you can later access it. I moved this into my "Share" directory.
3) Telnet into the TeraStation. I believe the default user for the firmware is "myroot", which you should use to telnet in.
$ telnet 192.168.0.108 Trying 192.168.0.108... Connected to 192.168.0.108. Escape character is '^]'. Password: Login incorrect TERASTATION login: myroot root@TERASTATION:~#
4) Change directories into the OpenTera directory, the one you just placed on the TeraStation, and run the
root@TERASTATION:/# cd mnt/array1/share/OpenTera_v5/ root@TERASTATION:/mnt/array1/share/OpenTera_v5# ./Update_OpenTera.sh
This script is an interactive install, so it will prompt you to say "y" a few times. Go ahead and do so. If all is successful, you should see:
[OpenTera] ============ OpenTera Install Completed ===============
5) Next, change directories into the Samba directory and run the
root@TERASTATION:/mnt/array1/share/OpenTera_v5# cd /mnt/array1/share/samba-3.0.37_ppc/ root@TERASTATION:/mnt/array1/share/samba-3.0.37_ppc# ./Update_Samba.sh
When all is completed, you should see:
********************************************************************* Completed samba-3.0.37_ppc.tgz install *********************************************************************
And that's it! I was able to access the TeraStation from Mac OS X Lion. Hopefully this will be helpful to someone else out there, as I know I'm not the only one with this problem. If I missed any steps, let me know - good luck!