Exemplo n.º 1
0
def generate_from_csdl():
  from components.makahiki_avatar.models import Avatar
  from django.contrib.auth.models import User
  from components.floors.models import Floor
  avatar_base = "avatars/sample/"

  members = {
    "danport": {"name": "Dan Port", "avatar": "danport.jpg"},
    "kagawaa": {"name": "Aaron Kagawa", "avatar": "aaronkagawa.jpeg"},
    "alexey": {"name": "Alexey Olkov", "avatar": "alexey.jpg"},
    "anned": {"name": "Anne Disney", "avatar": "annedisney.jpeg"},
    "austen": {"name": "Austen Ito", "avatar": "austen.jpg"},
    "carleton": {"name": "Carleton Moore", "avatar": "carleton.jpg"},
    "cedric": {"name": "Cedric Zhang", "avatar": "cedric.jpeg"},
    "christoph": {"name": "Christoph Lofi", "avatar": "christoph.jpg"},
    "dadong": {"name": "Dadong Wan", "avatar": "dadong.png"},
    "danu": {"name": "Danu Tjahjono", "avatar": "danu.png"},
    "dnickels": {"name": "David Nickels", "avatar": "davidnickels.jpg"},
    "hongbing": {"name": "Hongbing Kou", "avatar": "hongbing.jpeg"},
    "jameswang": {"name": "James Wang", "avatar": "jameswang.jpg"},
    "corbett": {"name": "Jay Corbett", "avatar": "jaycorbett.jpeg"},
    "jgeis": {"name": "Jennifer Geis", "avatar": "jennifergeis.jpeg"},
    "jitender": {"name": "Jitender Miglani", "avatar": "jitender.jpeg"},
    "jaugustin": {"name": "Joy Augustin", "avatar": "joyaugustin.jpeg"},
    "jsakuda": {"name": "Julie Sakuda", "avatar": "julie.jpg"},
    "julio": {"name": "Julio Polo", "avatar": "juliopolo.jpeg"},
    "kyleung": {"name": "Ka Yee Leung", "avatar": "kayeeleung.jpeg"},
    "mette": {"name": "Mette Moffett", "avatar": "mette.jpeg"},
    "staver": {"name": "Michael Staver", "avatar": "michaelstaver.jpeg"},
    "paulding": {"name": "Mike Paulding", "avatar": "mikepaulding.jpg"},
    "monir": {"name": "Monir Hodges", "avatar": "monir.jpeg"},
    "pavel": {"name": "Pavel Senin", "avatar": "pavel.jpg"},
    "randycox": {"name": "Randy Cox", "avatar": "randycox.jpeg"},
    "rosemary": {"name": "Rosemary Andrada Sumajit", "avatar": "rosemary.png"},
    "russell": {"name": "Russell Tokuyama", "avatar": "russell.jpeg"},
    "joedane": {"name": "Joe Dane", "avatar": "joedane.jpeg"}
  }

  initials = "abcdefghijklmnopqrstuvwxyz"
  floors = Floor.objects.all()
  
  for i in range(0, 600):
    user = None
    while not user:
      try:
        username = string.join(random.sample(members.keys(), 1) + random.sample(initials, 1), "")
        user = User(username=username)
        user.save()
      except IntegrityError:
        user = None

    key = user.username[0: len(user.username) - 1]
    profile = user.get_profile()
    profile.name = members[key]["name"]
    profile.floor = random.sample(floors, 1)[0]
    profile.save()

    avatar_path = avatar_base + members[key]["avatar"]
    avatar = Avatar(user=user, primary=True, avatar=avatar_path)
    avatar.save()
Exemplo n.º 2
0
def upload_fb(request):
    """Uploads the user's picture from Facebook."""
    if request.method == "POST":
        form = FacebookPictureForm(request.POST)
        if form.is_valid():
            # Need to download the image from the url and save it.
            photo_temp = NamedTemporaryFile(delete=True)
            fb_url = form.cleaned_data["facebook_photo"]
            photo_temp.write(urllib2.urlopen(fb_url).read())
            photo_temp.flush()

            # Delete old avatars if they exist
            # avatars = Avatar.objects.filter(user=request.user)
            # for avatar in avatars:
            #   avatar.avatar.delete()
            #   avatar.delete()

            path = avatar_file_path(user=request.user, filename="fb_photo.jpg")
            avatar = Avatar(
                user=request.user,
                primary=True,
                avatar=path,
            )
            # print "saving facebook photo to " + path
            new_file = avatar.avatar.storage.save(path, File(photo_temp))
            avatar.save()

            return HttpResponseRedirect(
                reverse("profile_index") + "?changed_avatar=True")

    raise Http404
Exemplo n.º 3
0
def upload_fb(request):
  """Uploads the user's picture from Facebook."""
  if request.method == "POST":
    form = FacebookPictureForm(request.POST)
    if form.is_valid():
      # Need to download the image from the url and save it.
      photo_temp = NamedTemporaryFile(delete=True)
      fb_url = form.cleaned_data["facebook_photo"]
      photo_temp.write(urllib2.urlopen(fb_url).read())
      photo_temp.flush()
      
      # Delete old avatars if they exist
      # avatars = Avatar.objects.filter(user=request.user)
      # for avatar in avatars:
      #   avatar.avatar.delete()
      #   avatar.delete()
        
      path = avatar_file_path(user=request.user, 
          filename="fb_photo.jpg")
      avatar = Avatar(
          user = request.user,
          primary = True,
          avatar = path,
      )
      # print "saving facebook photo to " + path
      new_file = avatar.avatar.storage.save(path, File(photo_temp))
      avatar.save()
    
      return HttpResponseRedirect(reverse("profile_index") + "?changed_avatar=True")
  
  raise Http404
Exemplo n.º 4
0
def generate_csdl_for_floor(floor):
  from components.makahiki_avatar.models import Avatar
  from components.django.contrib.auth.models import User
  from components.floors.models import Floor
  avatar_base = "avatars/sample/"

  members = {
    "danport": {"name": "Dan Port", "avatar": "danport.jpg"},
    "kagawaa": {"name": "Aaron Kagawa", "avatar": "aaronkagawa.jpeg"},
    "alexey": {"name": "Alexey Olkov", "avatar": "alexey.jpg"},
    "anned": {"name": "Anne Disney", "avatar": "annedisney.jpeg"},
    "austen": {"name": "Austen Ito", "avatar": "austen.jpg"},
    "carleton": {"name": "Carleton Moore", "avatar": "carleton.jpeg"},
    "cedric": {"name": "Cedric Zhang", "avatar": "cedric.jpeg"},
    "christoph": {"name": "Christoph Lofi", "avatar": "christoph.jpg"},
    "dadong": {"name": "Dadong Wan", "avatar": "dadong.png"},
    "danu": {"name": "Danu Tjahjono", "avatar": "danu.png"},
    "dnickels": {"name": "David Nickels", "avatar": "davidnickels.jpg"},
    "hongbing": {"name": "Hongbing Kou", "avatar": "hongbing.jpeg"},
    "jameswang": {"name": "James Wang", "avatar": "jameswang.jpg"},
    "corbett": {"name": "Jay Corbett", "avatar": "jaycorbett.jpeg"},
    "jgeis": {"name": "Jennifer Geis", "avatar": "jennifergeis.jpeg"},
    "jitender": {"name": "Jitender Miglani", "avatar": "jitender.jpeg"},
    "jaugustin": {"name": "Joy Augustin", "avatar": "joyaugustin.jpeg"},
    "jsakuda": {"name": "Julie Sakuda", "avatar": "julie.jpg"},
    "julio": {"name": "Julio Polo", "avatar": "juliopolo.jpeg"},
    "kyleung": {"name": "Ka Yee Leung", "avatar": "kayeeleung.jpeg"},
    "mette": {"name": "Mette Moffett", "avatar": "mette.jpeg"},
    "staver": {"name": "Michael Staver", "avatar": "michaelstaver.jpeg"},
    "paulding": {"name": "Mike Paulding", "avatar": "mikepaulding.jpg"},
    "monir": {"name": "Monir Hodges", "avatar": "monir.jpeg"},
    "pavel": {"name": "Pavel Senin", "avatar": "pavel.jpg"},
    "randycox": {"name": "Randy Cox", "avatar": "randycox.jpeg"},
    "rosemary": {"name": "Rosemary Andrada Sumajit", "avatar": "rosemary.png"},
    "russell": {"name": "Russell Tokuyama", "avatar": "russell.jpeg"},
    "joedane": {"name": "Joe Dane", "avatar": "joedane.jpeg"}
  }

  for key in members.keys():
    user = None
    try:
      user = User(username=key)
      user.save()
    except IntegrityError:
      print "Integrity Error: Duplicate user."
      exit()

    profile = user.get_profile()
    profile.name = members[key]["name"]
    profile.floor = floor
    profile.save()

    avatar_path = avatar_base + members[key]["avatar"]
    avatar = Avatar(user=user, primary=True, avatar=avatar_path)
    avatar.save()
Exemplo n.º 5
0
def setup_profile(request):
    """
  Displays the profile form.
  """
    if request.is_ajax():
        return _get_profile_form(request)

    # Fields with file uploads are not AJAX requests.
    if request.method == "POST":
        form = ProfileForm(request.POST, user=request.user)
        profile = request.user.get_profile()

        # print request
        if form.is_valid():
            profile.name = form.cleaned_data["display_name"].strip()
            if not profile.setup_profile:
                profile.setup_profile = True
                profile.add_points(5, datetime.datetime.today(),
                                   "Set up profile")

            profile.save()

            if 'avatar' in request.FILES:
                path = avatar_file_path(user=request.user,
                                        filename=request.FILES['avatar'].name)
                avatar = Avatar(
                    user=request.user,
                    primary=True,
                    avatar=path,
                )
                # print "saving avatar to " + path
                new_file = avatar.avatar.storage.save(path,
                                                      request.FILES['avatar'])
                avatar.save()

            elif form.cleaned_data["use_fb_photo"] and form.cleaned_data[
                    "facebook_photo"]:
                # Need to download the image from the url and save it.
                photo_temp = NamedTemporaryFile(delete=True)
                fb_url = form.cleaned_data["facebook_photo"]
                # print fb_url
                photo_temp.write(urllib2.urlopen(fb_url).read())
                photo_temp.flush()

                path = avatar_file_path(user=request.user,
                                        filename="fb_photo.jpg")
                avatar = Avatar(
                    user=request.user,
                    primary=True,
                    avatar=path,
                )
                # print "saving facebook photo to " + path
                new_file = avatar.avatar.storage.save(path, File(photo_temp))
                avatar.save()

            return HttpResponseRedirect(reverse("setup_activity"))

        return _get_profile_form(request, form=form, non_xhr=True)

    raise Http404
Exemplo n.º 6
0
def __handle_uploaded_file(uploaded_file, user):
    if uploaded_file.size > SIZE_LIMIT:
        raise Exception("File is too large")

    # Delete old avatars if they exist
    # avatars = Avatar.objects.filter(user=user)
    # for avatar in avatars:
    #   avatar.avatar.delete()
    #   avatar.delete()

    path = avatar_file_path(user=user, filename=uploaded_file.name)

    avatar = Avatar(
        user=user,
        primary=True,
        avatar=path,
    )
    new_file = avatar.avatar.storage.save(path, uploaded_file)
    avatar.save()
Exemplo n.º 7
0
def __handle_uploaded_file(uploaded_file, user):
  if uploaded_file.size > SIZE_LIMIT:
    raise Exception("File is too large")
  
  # Delete old avatars if they exist
  # avatars = Avatar.objects.filter(user=user)
  # for avatar in avatars:
  #   avatar.avatar.delete()
  #   avatar.delete()
    
  path = avatar_file_path(user=user, 
      filename=uploaded_file.name)
      
  avatar = Avatar(
      user = user,
      primary = True,
      avatar = path,
  )
  new_file = avatar.avatar.storage.save(path, uploaded_file)
  avatar.save()
Exemplo n.º 8
0
def setup_profile(request):
  """
  Displays the profile form.
  """
  if request.is_ajax():
    return _get_profile_form(request)
    
  # Fields with file uploads are not AJAX requests.
  if request.method == "POST":
    form = ProfileForm(request.POST)
    profile = request.user.get_profile()
    
    # print request
    if form.is_valid():
      profile.name = form.cleaned_data["display_name"]
      profile.about = form.cleaned_data["about"]
      if not profile.setup_profile:
        profile.setup_profile = True
        profile.add_points(5, datetime.datetime.today())
      profile.save()
      
      if 'avatar' in request.FILES:
        path = avatar_file_path(user=request.user, 
            filename=request.FILES['avatar'].name)
        avatar = Avatar(
            user = request.user,
            primary = True,
            avatar = path,
        )
        # print "saving avatar to " + path
        new_file = avatar.avatar.storage.save(path, request.FILES['avatar'])
        avatar.save()
        
      elif form.cleaned_data["use_fb_photo"] and form.cleaned_data["facebook_photo"]:
        # Need to download the image from the url and save it.
        photo_temp = NamedTemporaryFile(delete=True)
        fb_url = form.cleaned_data["facebook_photo"]
        # print fb_url
        photo_temp.write(urllib2.urlopen(fb_url).read())
        photo_temp.flush()
        
        path = avatar_file_path(user=request.user, 
            filename="fb_photo.jpg")
        avatar = Avatar(
            user = request.user,
            primary = True,
            avatar = path,
        )
        # print "saving facebook photo to " + path
        new_file = avatar.avatar.storage.save(path, File(photo_temp))
        avatar.save()
        
      return setup_activity(request, non_xhr=True)
        
    return _get_profile_form(request, form=form, non_xhr=True)
    
  raise Http404
Exemplo n.º 9
0
def upload_fb(request):
  """Uploads the user's picture from Facebook."""
  if request.method == "POST":
    # Need to download the image from the url and save it.
    photo_temp = NamedTemporaryFile(delete=True)
    fb_url = "http://graph.facebook.com/%s/picture?type=large" % request.user.facebookprofile.profile_id
    # print fb_url
    photo_temp.write(urllib2.urlopen(fb_url).read())
    photo_temp.flush()
    
    path = avatar_file_path(user=request.user, 
        filename="fb_photo.jpg")
    avatar = Avatar(
        user = request.user,
        primary = True,
        avatar = path,
    )
    # print "saving facebook photo to " + path
    new_file = avatar.avatar.storage.save(path, File(photo_temp))
    avatar.save()
    
    return HttpResponseRedirect(reverse("profile_index"))
  
  raise Http404
Exemplo n.º 10
0
  def testSetProfilePic(self):
    """
    Tests that this predicate is completed when the user sets a profile pic.
    """
    # Need to disconnect create thumbnail signal temporarily for test so that additional image
    # files don't get created.
    signals.post_save.disconnect(create_default_thumbnails, Avatar)
    
    self.assertFalse(set_profile_pic(self.user), "User should not have their profile pic set.")
    image_path = os.path.join(settings.PROJECT_ROOT, "fixtures", "test_images", "test.jpg")
    image = ImageFile(open(image_path, "r"))
    path = avatar_file_path(user=self.user, filename="test.jpg")
    avatar = Avatar(user=self.user, avatar=path, primary=True)
    new_file = avatar.avatar.storage.save(path, image)
    avatar.save()
    self.assertTrue(set_profile_pic(self.user), "User should have their profile pic set.")
    
    # Test within context of a quest.
    avatar.delete()
    self.quest.unlock_conditions = "set_profile_pic()"
    self.quest.save()
    self.assertTrue(self.quest not in get_quests(self.user), "User should not be able to participate in this quest.")

    self.quest.unlock_conditions = "not set_profile_pic()"
    self.quest.save()
    self.assertTrue(self.quest in get_quests(self.user)["available_quests"], "User should be able to participate in this quest.")

    self.quest.accept(self.user)
    self.quest.completion_conditions = "set_profile_pic()"
    self.quest.save()
    self.assertTrue(self.quest not in possibly_completed_quests(self.user), "User should not be able to complete this quest.")

    avatar = Avatar(user=self.user, avatar=path, primary=True)
    avatar.save()
    self.assertTrue(self.quest in possibly_completed_quests(self.user), "User should have completed this quest.")
    
    # Be sure to clean up test files and reconnect post_save signal.
    signals.post_save.connect(create_default_thumbnails, sender=Avatar)
    for avatar in self.user.avatar_set.all():
      avatar.avatar.delete()
      avatar.delete()
Exemplo n.º 11
0
def generate_from_csdl():
    from components.makahiki_avatar.models import Avatar
    from django.contrib.auth.models import User
    from components.floors.models import Floor
    avatar_base = "avatars/sample/"

    members = {
        "danport": {
            "name": "Dan Port",
            "avatar": "danport.jpg"
        },
        "kagawaa": {
            "name": "Aaron Kagawa",
            "avatar": "aaronkagawa.jpeg"
        },
        "alexey": {
            "name": "Alexey Olkov",
            "avatar": "alexey.jpg"
        },
        "anned": {
            "name": "Anne Disney",
            "avatar": "annedisney.jpeg"
        },
        "austen": {
            "name": "Austen Ito",
            "avatar": "austen.jpg"
        },
        "carleton": {
            "name": "Carleton Moore",
            "avatar": "carleton.jpg"
        },
        "cedric": {
            "name": "Cedric Zhang",
            "avatar": "cedric.jpeg"
        },
        "christoph": {
            "name": "Christoph Lofi",
            "avatar": "christoph.jpg"
        },
        "dadong": {
            "name": "Dadong Wan",
            "avatar": "dadong.png"
        },
        "danu": {
            "name": "Danu Tjahjono",
            "avatar": "danu.png"
        },
        "dnickels": {
            "name": "David Nickels",
            "avatar": "davidnickels.jpg"
        },
        "hongbing": {
            "name": "Hongbing Kou",
            "avatar": "hongbing.jpeg"
        },
        "jameswang": {
            "name": "James Wang",
            "avatar": "jameswang.jpg"
        },
        "corbett": {
            "name": "Jay Corbett",
            "avatar": "jaycorbett.jpeg"
        },
        "jgeis": {
            "name": "Jennifer Geis",
            "avatar": "jennifergeis.jpeg"
        },
        "jitender": {
            "name": "Jitender Miglani",
            "avatar": "jitender.jpeg"
        },
        "jaugustin": {
            "name": "Joy Augustin",
            "avatar": "joyaugustin.jpeg"
        },
        "jsakuda": {
            "name": "Julie Sakuda",
            "avatar": "julie.jpg"
        },
        "julio": {
            "name": "Julio Polo",
            "avatar": "juliopolo.jpeg"
        },
        "kyleung": {
            "name": "Ka Yee Leung",
            "avatar": "kayeeleung.jpeg"
        },
        "mette": {
            "name": "Mette Moffett",
            "avatar": "mette.jpeg"
        },
        "staver": {
            "name": "Michael Staver",
            "avatar": "michaelstaver.jpeg"
        },
        "paulding": {
            "name": "Mike Paulding",
            "avatar": "mikepaulding.jpg"
        },
        "monir": {
            "name": "Monir Hodges",
            "avatar": "monir.jpeg"
        },
        "pavel": {
            "name": "Pavel Senin",
            "avatar": "pavel.jpg"
        },
        "randycox": {
            "name": "Randy Cox",
            "avatar": "randycox.jpeg"
        },
        "rosemary": {
            "name": "Rosemary Andrada Sumajit",
            "avatar": "rosemary.png"
        },
        "russell": {
            "name": "Russell Tokuyama",
            "avatar": "russell.jpeg"
        },
        "joedane": {
            "name": "Joe Dane",
            "avatar": "joedane.jpeg"
        }
    }

    initials = "abcdefghijklmnopqrstuvwxyz"
    floors = Floor.objects.all()

    for i in range(0, 600):
        user = None
        while not user:
            try:
                username = string.join(
                    random.sample(members.keys(), 1) +
                    random.sample(initials, 1), "")
                user = User(username=username)
                user.save()
            except IntegrityError:
                user = None

        key = user.username[0:len(user.username) - 1]
        profile = user.get_profile()
        profile.name = members[key]["name"]
        profile.floor = random.sample(floors, 1)[0]
        profile.save()

        avatar_path = avatar_base + members[key]["avatar"]
        avatar = Avatar(user=user, primary=True, avatar=avatar_path)
        avatar.save()
Exemplo n.º 12
0
def generate_csdl_for_floor(floor):
    from components.makahiki_avatar.models import Avatar
    from components.django.contrib.auth.models import User
    from components.floors.models import Floor
    avatar_base = "avatars/sample/"

    members = {
        "danport": {
            "name": "Dan Port",
            "avatar": "danport.jpg"
        },
        "kagawaa": {
            "name": "Aaron Kagawa",
            "avatar": "aaronkagawa.jpeg"
        },
        "alexey": {
            "name": "Alexey Olkov",
            "avatar": "alexey.jpg"
        },
        "anned": {
            "name": "Anne Disney",
            "avatar": "annedisney.jpeg"
        },
        "austen": {
            "name": "Austen Ito",
            "avatar": "austen.jpg"
        },
        "carleton": {
            "name": "Carleton Moore",
            "avatar": "carleton.jpeg"
        },
        "cedric": {
            "name": "Cedric Zhang",
            "avatar": "cedric.jpeg"
        },
        "christoph": {
            "name": "Christoph Lofi",
            "avatar": "christoph.jpg"
        },
        "dadong": {
            "name": "Dadong Wan",
            "avatar": "dadong.png"
        },
        "danu": {
            "name": "Danu Tjahjono",
            "avatar": "danu.png"
        },
        "dnickels": {
            "name": "David Nickels",
            "avatar": "davidnickels.jpg"
        },
        "hongbing": {
            "name": "Hongbing Kou",
            "avatar": "hongbing.jpeg"
        },
        "jameswang": {
            "name": "James Wang",
            "avatar": "jameswang.jpg"
        },
        "corbett": {
            "name": "Jay Corbett",
            "avatar": "jaycorbett.jpeg"
        },
        "jgeis": {
            "name": "Jennifer Geis",
            "avatar": "jennifergeis.jpeg"
        },
        "jitender": {
            "name": "Jitender Miglani",
            "avatar": "jitender.jpeg"
        },
        "jaugustin": {
            "name": "Joy Augustin",
            "avatar": "joyaugustin.jpeg"
        },
        "jsakuda": {
            "name": "Julie Sakuda",
            "avatar": "julie.jpg"
        },
        "julio": {
            "name": "Julio Polo",
            "avatar": "juliopolo.jpeg"
        },
        "kyleung": {
            "name": "Ka Yee Leung",
            "avatar": "kayeeleung.jpeg"
        },
        "mette": {
            "name": "Mette Moffett",
            "avatar": "mette.jpeg"
        },
        "staver": {
            "name": "Michael Staver",
            "avatar": "michaelstaver.jpeg"
        },
        "paulding": {
            "name": "Mike Paulding",
            "avatar": "mikepaulding.jpg"
        },
        "monir": {
            "name": "Monir Hodges",
            "avatar": "monir.jpeg"
        },
        "pavel": {
            "name": "Pavel Senin",
            "avatar": "pavel.jpg"
        },
        "randycox": {
            "name": "Randy Cox",
            "avatar": "randycox.jpeg"
        },
        "rosemary": {
            "name": "Rosemary Andrada Sumajit",
            "avatar": "rosemary.png"
        },
        "russell": {
            "name": "Russell Tokuyama",
            "avatar": "russell.jpeg"
        },
        "joedane": {
            "name": "Joe Dane",
            "avatar": "joedane.jpeg"
        }
    }

    for key in members.keys():
        user = None
        try:
            user = User(username=key)
            user.save()
        except IntegrityError:
            print "Integrity Error: Duplicate user."
            exit()

        profile = user.get_profile()
        profile.name = members[key]["name"]
        profile.floor = floor
        profile.save()

        avatar_path = avatar_base + members[key]["avatar"]
        avatar = Avatar(user=user, primary=True, avatar=avatar_path)
        avatar.save()
Exemplo n.º 13
0
def change(request, extra_context={}, next_override=None):
    avatars = Avatar.objects.filter(user=request.user).order_by('-primary')
    if avatars.count() > 0:
        avatar = avatars[0]
        kwargs = {'initial': {'choice': avatar.id}}
    else:
        avatar = None
        kwargs = {}
    primary_avatar_form = PrimaryAvatarForm(request.POST or None, user=request.user, **kwargs)
    if request.method == "POST":
        updated = False
        if 'avatar' in request.FILES:
            path = avatar_file_path(user=request.user, 
                filename=request.FILES['avatar'].name)
            avatar = Avatar(
                user = request.user,
                primary = True,
                avatar = path,
            )
            new_file = avatar.avatar.storage.save(path, request.FILES['avatar'])
            avatar.save()
            updated = True
            # request.user.message_set.create(
            #                 message=_("Successfully uploaded a new avatar."))
        if 'choice' in request.POST and primary_avatar_form.is_valid():
            avatar = Avatar.objects.get(id=
                primary_avatar_form.cleaned_data['choice'])
            avatar.primary = True
            avatar.save()
            updated = True
            # request.user.message_set.create(
            #                 message=_("Successfully updated your avatar."))
        # if updated and notification:
        #     notification.send([request.user], "avatar_updated", {"user": request.user, "avatar": avatar})
        #     notification.send((x['friend'] for x in Friendship.objects.friends_for_user(request.user)), "avatar_friend_updated", {"user": request.user, "avatar": avatar})
        # return HttpResponseRedirect(next_override or _get_next(request))
        return HttpResponseRedirect(reverse("profile_index") + "?changed_avatar=True")
        
    fb_user = facebook.get_user_from_cookie(request.COOKIES, settings.FACEBOOK_APP_ID, settings.FACEBOOK_SECRET_KEY)
    fb_id = None
    
    if fb_user:
      try:
        graph = facebook.GraphAPI(fb_user["access_token"])
        graph_profile = graph.get_object("me")
        fb_id = graph_profile["id"]
      except facebook.GraphAPIError:
        pass
      
    return render_to_response(
        'makahiki_avatar/change.html',
        extra_context,
        context_instance = RequestContext(
            request,
            { 'avatar': avatar, 
              'avatars': avatars,
              'primary_avatar_form': primary_avatar_form,
              'next': next_override or _get_next(request), 
              'fb_id': fb_id,}
        )
    )