Login

Tag "userprofile"

Snippet List

Improved User Admin

Helper function which adds some niceties to the auth/user admin views. Needs django 1.2 to work. ### Usage Define a UserProfile class and set `AUTH_PROFILE_MODULE` as per the [django docs](http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users) In your admin.py file (or anywhere else) add the following: from models import UserProfile from [path to snippet] import upgrade_user_admin upgrade_user_admin(UserProfile)

  • admin
  • user
  • userprofile
Read More

convenience parent class for UserProfile model

This is just a reusable convenience parent class to allow you to create and administer an automatic user profile class using the following code: class UserProfile(UserProfileModel): likes_kittens = models.BooleanField(default=True) Whenever a `User` object is created, a corresponding `UserProfile` will also be created. That's it. NB: You will still need to set `AUTH_PROFILE_MODULE` in your settings :-) (PS: It would also be nice to have the resulting class proxy the `User` object's attributes like django's model inheritance does, while still automatically creating a `UserProfile` object when a `User` object is created :-)

  • userprofile
Read More

Alternative to User.get_profile()

**This is an alternative to User.get_profile.** Rather than having you call `User.get_profile` directly, this retrieves the profile instance for a `User` and attaches the fields from the profile to the `User` object when instantiated. The special methods for `DateField`, `FileField`, `ImageField` and fields with `choices` are also created. Since the profile object still has to be retrieved from the database before its fields can be added to the `User`, the costs for using this might outweigh the rewards unless you are heavily using profiles. To install, place it in a module on your `PYTHONPATH` and add it to `INSTALLED_APPS`.

  • user
  • profile
  • auth
  • userprofile
  • profiles
Read More

User post_save signal to auto create 'admin' profile

**How to use:** 1. puts this code at the end of the `models.py` file who haves the User Profile class declared; 2. verify if your User Profile class has the name 'UserProfile'. If not, change the code to the right name. **About:** this snippet makes the ORM create a profile each time an user is created (or updated, if the user profile lost), including 'admin' user.

  • admin
  • user
  • userprofile
Read More

filter dates to user profile's timezone

I have users in many timezones and I let them set their preferred display timezone in their user profile as a string (validated aginst the pytz valid timezones). This is a filter that takes a datetime as input and as an argument the user to figure out the timezone from. It requires that there is a user profile model with a 'timezone' field. If a specific user does not have a user profile we fall back on the settings.TIME_ZONE. If the datetime is naieve then we again fallback on the settings.TIME_ZONE. It requires the 'pytz' module: [http://pytz.sourceforge.net/](http://pytz.sourceforge.net/) Use: `{{ post.created|user_tz:user|date:"D, M j, Y H:i" }}` The example is assuming a context in which the 'user' variable refers to a User object.

  • filter
  • timezone
  • userprofile
Read More

5 snippets posted so far.