{"action":"created","comment":{"url":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/comments/46474714","id":46474714,"diff_hunk":"@@ -0,0 +1,195 @@\n+from django.shortcuts import render\n+from hummingbird.models import UserProfile, UserDevice, User\n+from hummingbird.forms import UserProfileForm, UserDeviceForm, UserSongForm\n+from django.http import HttpResponse\n+import datetime\n+import urllib\n+\n+\n+## TO-DO: Add div and context for files in library to allow for file deletion. As of right now, files will just accumulate in the library.\n+def index(request):\n+    userprofile_list = UserProfile.objects.order_by('-last_played')\n+    context_dict = {'userprofiles': userprofile_list}\n+    response = render(request, 'index.html', context_dict)\n+    return response\n+\n+\n+## Returns info for userprofile page, and will update userprofile/userdevice fields if POST is used.\n+def profile(request, user_id):\n+\tadded_song=False\n+\tadded_device=False\n+\tcontext_dict = {}\n+\n+\t## If we're getting data via post method, update whatever fields we've been given.\n+\tif request.method == 'POST':\n+\t\tuserprofile = UserProfile.objects.get(pk=user_id)\n+\t\tusersong_form = UserSongForm(data=request.POST)\n+\t\tdevice_form = UserDeviceForm(data=request.POST)\n+\t\n+\t\tif usersong_form.is_valid():\n+\t\t\tuserprofile.song = request.FILES['song']\n+\t\t\tuserprofile.length = usersong_form.cleaned_data['length']\n+\t\t\tuserprofile.save()\n+\t\t\tadded_song = True\n+\t\n+\t\tif device_form.is_valid():\n+\t\t\tdevice = device_form.save(commit=False)\n+\t\t\tdevice.user_profile = userprofile\n+\t\t\tadded_device = True\n+\t\t\tdevice.save()\n+\t\n+\t## Regardless of method (GET/POST), let's return info for the user's profile.\n+\ttry:\n+\t\tuserprofile = UserProfile.objects.get(pk=user_id)\n+\t\tcontext_dict['profile'] = userprofile\n+\t\tcontext_dict['name'] = userprofile.name\n+\t\t# If user has no song, the template will put in appropriate copy.\n+\t\tif userprofile.song:\n+\t\t\tcontext_dict['song'] = userprofile.song.name\n+\t\t# If the user hasn't been played yet, the template will put in appropriate copy.\n+\t\tif userprofile.last_played:\n+\t\t\tcontext_dict['last_played'] = userprofile.last_played.strftime('%Y-%m-%d %H:%M:%S')\t\t\n+\t\tcontext_dict['length'] = userprofile.length\n+\t\t# Add in devices to list for user's profile\n+\t\tdevices = UserDevice.objects.filter(user_profile=userprofile)\n+\t\tcontext_dict['devices'] = devices\n+\t\t# Populate forms\n+\t\tusersong_form = UserSongForm()\n+\t\tdevice_form = UserDeviceForm()\n+\t\tcontext_dict['usersong_form'] = usersong_form\n+\t\tcontext_dict['device_form'] = device_form\n+\texcept UserProfile.DoesNotExist:\n+\t\tpass\n+\t# If we updated one of the fields, pass that to the template so it can tell the user that update was successful.\n+\tcontext_dict['added_device'] = added_device\n+\tcontext_dict['added_song'] = added_song\n+\treturn render(request,'profile.html',context_dict)\n+\n+\n+## Checks if user exists. If so, return user name. Otherwise, return \"0\". \n+def get_user_from_device(request):\n+\tif request.method == 'GET':\n+\t\ttry:\n+\t\t\tdevice = request.GET['mac_id']\n+\t\t\tuserdevice = UserDevice.objects.get(mac_id=device.lower())\n+\t\t\tuser = userdevice.user_profile.id\n+\t\t\treturn HttpResponse(user, content_type='text/plain')\n+\t\texcept UserDevice.DoesNotExist:\n+\t\t\treturn HttpResponse(\"0\", content_type='text/plain')\n+\tpass\n+\n+\n+## Returns information necessary to build the User object if mac_id is recognized. If not, return \"0\".\n+## If there is a user, a string representation of a dictioanry is returned.\n+def build_user_from_device(request):\n+\tif request.method == 'GET':\n+\t\ttry:\n+\t\t\tdevice=urllib.unquote(request.GET['mac_id']).decode('utf8')\n+\t\t\tuserdevice = UserDevice.objects.get(mac_id=device.lower()) \n+\t\t\tuser_dict={}\n+\t\t\tuser_dict['name'] = userdevice.user_profile.name\n+\t\t\t# If user exists, but there is no song currently associated with them, we don't have anything to play,\n+\t\t\t# so we return \"0\"\n+\t\t\tif userdevice.user_profile.song.name=='':\n+\t\t\t\treturn HttpResponse(\"0\", content_type='text/plain') \n+\t\t\telse:\n+\t\t\t\tuser_dict['song'] = userdevice.user_profile.song.name\n+\t\t\tuser_dict['length'] = userdevice.user_profile.length\n+\t\t\t# Handle first-seen case. This will likely happen right after the device is added.\n+\t\t\t# So, to prevent immediate playback after adding a user and device, if this is the \n+\t\t\t# first time a user is seen, just set the \"last_played\" field to now, and they will play tomorrow.\n+\t\t\tif userdevice.user_profile.last_played is not None:\n+\t\t\t\tuser_dict['last_played'] = userdevice.user_profile.last_played.strftime('%Y-%m-%d %H:%M:%S')\n+\t\t\telse: user_dict['last_played'] = datetime.datetime(1991,1,1).strftime('%Y-%m-%d %H:%M:%S')\n+\t\t\treturn HttpResponse(str(user_dict), content_type='text/plain')\n+\t\texcept UserDevice.DoesNotExist:\n+\t\t\treturn HttpResponse(\"0\", content_type='text/plain')\n+\tpass\n+\n+\n+## Once a user's song is played, Hummingbird uses this to update their \"last_played\" field to the current datetime.\n+def update_last_played(request):\n+\tif request.method == 'GET':\n+\t\tdevice=urllib.unquote(request.GET['mac_id']).decode('utf8')\n+\t\tuserdevice = UserDevice.objects.get(mac_id=device)\n+\t\tuserprofile = userdevice.user_profile\n+\t\tuserprofile.last_played = datetime.datetime.now()\n+\t\tuserprofile.save()\n+\t\treturn HttpResponse(\"Updated User\", content_type='text/plain')\n+\telse:\n+\t\treturn HttpResponse(\"0\", content_type='text/plain')\n+\n+## I think this is deprecated.\n+def get_song_from_user(request):","path":"hummingbird/views.py","position":123,"original_position":123,"commit_id":"65e048d196ea2ebec60599513d06fb402bebeaea","original_commit_id":"65e048d196ea2ebec60599513d06fb402bebeaea","user":{"login":"RevolutionTech","id":6820092,"avatar_url":"https://avatars.githubusercontent.com/u/6820092?v=3","gravatar_id":"","url":"https://api.github.com/users/RevolutionTech","html_url":"https://github.com/RevolutionTech","followers_url":"https://api.github.com/users/RevolutionTech/followers","following_url":"https://api.github.com/users/RevolutionTech/following{/other_user}","gists_url":"https://api.github.com/users/RevolutionTech/gists{/gist_id}","starred_url":"https://api.github.com/users/RevolutionTech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RevolutionTech/subscriptions","organizations_url":"https://api.github.com/users/RevolutionTech/orgs","repos_url":"https://api.github.com/users/RevolutionTech/repos","events_url":"https://api.github.com/users/RevolutionTech/events{/privacy}","received_events_url":"https://api.github.com/users/RevolutionTech/received_events","type":"User","site_admin":false},"body":"Let's remove this if it's unused.","created_at":"2015-12-02T21:02:44Z","updated_at":"2015-12-02T21:02:44Z","html_url":"https://github.com/RevolutionTech/hummingbird/pull/1#discussion_r46474714","pull_request_url":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/comments/46474714"},"html":{"href":"https://github.com/RevolutionTech/hummingbird/pull/1#discussion_r46474714"},"pull_request":{"href":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/1","id":52434983,"html_url":"https://github.com/RevolutionTech/hummingbird/pull/1","diff_url":"https://github.com/RevolutionTech/hummingbird/pull/1.diff","patch_url":"https://github.com/RevolutionTech/hummingbird/pull/1.patch","issue_url":"https://api.github.com/repos/RevolutionTech/hummingbird/issues/1","number":1,"state":"open","locked":false,"title":"Hummingbird django","user":{"login":"ittaisays","id":7220020,"avatar_url":"https://avatars.githubusercontent.com/u/7220020?v=3","gravatar_id":"","url":"https://api.github.com/users/ittaisays","html_url":"https://github.com/ittaisays","followers_url":"https://api.github.com/users/ittaisays/followers","following_url":"https://api.github.com/users/ittaisays/following{/other_user}","gists_url":"https://api.github.com/users/ittaisays/gists{/gist_id}","starred_url":"https://api.github.com/users/ittaisays/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ittaisays/subscriptions","organizations_url":"https://api.github.com/users/ittaisays/orgs","repos_url":"https://api.github.com/users/ittaisays/repos","events_url":"https://api.github.com/users/ittaisays/events{/privacy}","received_events_url":"https://api.github.com/users/ittaisays/received_events","type":"User","site_admin":false},"body":"Fixed some of the bugs preventing Hummingbird from truly flying, and created a Django interface so users can help themselves. They can add multiple devices, update songs, etc.","created_at":"2015-12-02T18:29:32Z","updated_at":"2015-12-02T21:02:45Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a17fbf83722fc5c62cb270ca8773066c91767d5a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/1/commits","review_comments_url":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/1/comments","review_comment_url":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/comments{/number}","comments_url":"https://api.github.com/repos/RevolutionTech/hummingbird/issues/1/comments","statuses_url":"https://api.github.com/repos/RevolutionTech/hummingbird/statuses/65e048d196ea2ebec60599513d06fb402bebeaea","head":{"label":"RevolutionTech:hummingbird-django","ref":"hummingbird-django","sha":"65e048d196ea2ebec60599513d06fb402bebeaea","user":{"login":"RevolutionTech","id":6820092,"avatar_url":"https://avatars.githubusercontent.com/u/6820092?v=3","gravatar_id":"","url":"https://api.github.com/users/RevolutionTech","html_url":"https://github.com/RevolutionTech","followers_url":"https://api.github.com/users/RevolutionTech/followers","following_url":"https://api.github.com/users/RevolutionTech/following{/other_user}","gists_url":"https://api.github.com/users/RevolutionTech/gists{/gist_id}","starred_url":"https://api.github.com/users/RevolutionTech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RevolutionTech/subscriptions","organizations_url":"https://api.github.com/users/RevolutionTech/orgs","repos_url":"https://api.github.com/users/RevolutionTech/repos","events_url":"https://api.github.com/users/RevolutionTech/events{/privacy}","received_events_url":"https://api.github.com/users/RevolutionTech/received_events","type":"User","site_admin":false},"repo":{"id":47238885,"name":"hummingbird","full_name":"RevolutionTech/hummingbird","owner":{"login":"RevolutionTech","id":6820092,"avatar_url":"https://avatars.githubusercontent.com/u/6820092?v=3","gravatar_id":"","url":"https://api.github.com/users/RevolutionTech","html_url":"https://github.com/RevolutionTech","followers_url":"https://api.github.com/users/RevolutionTech/followers","following_url":"https://api.github.com/users/RevolutionTech/following{/other_user}","gists_url":"https://api.github.com/users/RevolutionTech/gists{/gist_id}","starred_url":"https://api.github.com/users/RevolutionTech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RevolutionTech/subscriptions","organizations_url":"https://api.github.com/users/RevolutionTech/orgs","repos_url":"https://api.github.com/users/RevolutionTech/repos","events_url":"https://api.github.com/users/RevolutionTech/events{/privacy}","received_events_url":"https://api.github.com/users/RevolutionTech/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RevolutionTech/hummingbird","description":"A Django application and daemon that plays walk-in songs by monitoring network activity.","fork":false,"url":"https://api.github.com/repos/RevolutionTech/hummingbird","forks_url":"https://api.github.com/repos/RevolutionTech/hummingbird/forks","keys_url":"https://api.github.com/repos/RevolutionTech/hummingbird/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RevolutionTech/hummingbird/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RevolutionTech/hummingbird/teams","hooks_url":"https://api.github.com/repos/RevolutionTech/hummingbird/hooks","issue_events_url":"https://api.github.com/repos/RevolutionTech/hummingbird/issues/events{/number}","events_url":"https://api.github.com/repos/RevolutionTech/hummingbird/events","assignees_url":"https://api.github.com/repos/RevolutionTech/hummingbird/assignees{/user}","branches_url":"https://api.github.com/repos/RevolutionTech/hummingbird/branches{/branch}","tags_url":"https://api.github.com/repos/RevolutionTech/hummingbird/tags","blobs_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/refs{/sha}","trees_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RevolutionTech/hummingbird/statuses/{sha}","languages_url":"https://api.github.com/repos/RevolutionTech/hummingbird/languages","stargazers_url":"https://api.github.com/repos/RevolutionTech/hummingbird/stargazers","contributors_url":"https://api.github.com/repos/RevolutionTech/hummingbird/contributors","subscribers_url":"https://api.github.com/repos/RevolutionTech/hummingbird/subscribers","subscription_url":"https://api.github.com/repos/RevolutionTech/hummingbird/subscription","commits_url":"https://api.github.com/repos/RevolutionTech/hummingbird/commits{/sha}","git_commits_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/commits{/sha}","comments_url":"https://api.github.com/repos/RevolutionTech/hummingbird/comments{/number}","issue_comment_url":"https://api.github.com/repos/RevolutionTech/hummingbird/issues/comments{/number}","contents_url":"https://api.github.com/repos/RevolutionTech/hummingbird/contents/{+path}","compare_url":"https://api.github.com/repos/RevolutionTech/hummingbird/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RevolutionTech/hummingbird/merges","archive_url":"https://api.github.com/repos/RevolutionTech/hummingbird/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RevolutionTech/hummingbird/downloads","issues_url":"https://api.github.com/repos/RevolutionTech/hummingbird/issues{/number}","pulls_url":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls{/number}","milestones_url":"https://api.github.com/repos/RevolutionTech/hummingbird/milestones{/number}","notifications_url":"https://api.github.com/repos/RevolutionTech/hummingbird/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RevolutionTech/hummingbird/labels{/name}","releases_url":"https://api.github.com/repos/RevolutionTech/hummingbird/releases{/id}","created_at":"2015-12-02T05:21:14Z","updated_at":"2015-12-02T05:23:15Z","pushed_at":"2015-12-02T18:29:32Z","git_url":"git://github.com/RevolutionTech/hummingbird.git","ssh_url":"git@github.com:RevolutionTech/hummingbird.git","clone_url":"https://github.com/RevolutionTech/hummingbird.git","svn_url":"https://github.com/RevolutionTech/hummingbird","homepage":null,"size":1798,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"RevolutionTech:master","ref":"master","sha":"d16376cb6f7ca4ecf58cdaf84b576c2586394645","user":{"login":"RevolutionTech","id":6820092,"avatar_url":"https://avatars.githubusercontent.com/u/6820092?v=3","gravatar_id":"","url":"https://api.github.com/users/RevolutionTech","html_url":"https://github.com/RevolutionTech","followers_url":"https://api.github.com/users/RevolutionTech/followers","following_url":"https://api.github.com/users/RevolutionTech/following{/other_user}","gists_url":"https://api.github.com/users/RevolutionTech/gists{/gist_id}","starred_url":"https://api.github.com/users/RevolutionTech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RevolutionTech/subscriptions","organizations_url":"https://api.github.com/users/RevolutionTech/orgs","repos_url":"https://api.github.com/users/RevolutionTech/repos","events_url":"https://api.github.com/users/RevolutionTech/events{/privacy}","received_events_url":"https://api.github.com/users/RevolutionTech/received_events","type":"User","site_admin":false},"repo":{"id":47238885,"name":"hummingbird","full_name":"RevolutionTech/hummingbird","owner":{"login":"RevolutionTech","id":6820092,"avatar_url":"https://avatars.githubusercontent.com/u/6820092?v=3","gravatar_id":"","url":"https://api.github.com/users/RevolutionTech","html_url":"https://github.com/RevolutionTech","followers_url":"https://api.github.com/users/RevolutionTech/followers","following_url":"https://api.github.com/users/RevolutionTech/following{/other_user}","gists_url":"https://api.github.com/users/RevolutionTech/gists{/gist_id}","starred_url":"https://api.github.com/users/RevolutionTech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RevolutionTech/subscriptions","organizations_url":"https://api.github.com/users/RevolutionTech/orgs","repos_url":"https://api.github.com/users/RevolutionTech/repos","events_url":"https://api.github.com/users/RevolutionTech/events{/privacy}","received_events_url":"https://api.github.com/users/RevolutionTech/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/RevolutionTech/hummingbird","description":"A Django application and daemon that plays walk-in songs by monitoring network activity.","fork":false,"url":"https://api.github.com/repos/RevolutionTech/hummingbird","forks_url":"https://api.github.com/repos/RevolutionTech/hummingbird/forks","keys_url":"https://api.github.com/repos/RevolutionTech/hummingbird/keys{/key_id}","collaborators_url":"https://api.github.com/repos/RevolutionTech/hummingbird/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/RevolutionTech/hummingbird/teams","hooks_url":"https://api.github.com/repos/RevolutionTech/hummingbird/hooks","issue_events_url":"https://api.github.com/repos/RevolutionTech/hummingbird/issues/events{/number}","events_url":"https://api.github.com/repos/RevolutionTech/hummingbird/events","assignees_url":"https://api.github.com/repos/RevolutionTech/hummingbird/assignees{/user}","branches_url":"https://api.github.com/repos/RevolutionTech/hummingbird/branches{/branch}","tags_url":"https://api.github.com/repos/RevolutionTech/hummingbird/tags","blobs_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/refs{/sha}","trees_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/trees{/sha}","statuses_url":"https://api.github.com/repos/RevolutionTech/hummingbird/statuses/{sha}","languages_url":"https://api.github.com/repos/RevolutionTech/hummingbird/languages","stargazers_url":"https://api.github.com/repos/RevolutionTech/hummingbird/stargazers","contributors_url":"https://api.github.com/repos/RevolutionTech/hummingbird/contributors","subscribers_url":"https://api.github.com/repos/RevolutionTech/hummingbird/subscribers","subscription_url":"https://api.github.com/repos/RevolutionTech/hummingbird/subscription","commits_url":"https://api.github.com/repos/RevolutionTech/hummingbird/commits{/sha}","git_commits_url":"https://api.github.com/repos/RevolutionTech/hummingbird/git/commits{/sha}","comments_url":"https://api.github.com/repos/RevolutionTech/hummingbird/comments{/number}","issue_comment_url":"https://api.github.com/repos/RevolutionTech/hummingbird/issues/comments{/number}","contents_url":"https://api.github.com/repos/RevolutionTech/hummingbird/contents/{+path}","compare_url":"https://api.github.com/repos/RevolutionTech/hummingbird/compare/{base}...{head}","merges_url":"https://api.github.com/repos/RevolutionTech/hummingbird/merges","archive_url":"https://api.github.com/repos/RevolutionTech/hummingbird/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/RevolutionTech/hummingbird/downloads","issues_url":"https://api.github.com/repos/RevolutionTech/hummingbird/issues{/number}","pulls_url":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls{/number}","milestones_url":"https://api.github.com/repos/RevolutionTech/hummingbird/milestones{/number}","notifications_url":"https://api.github.com/repos/RevolutionTech/hummingbird/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/RevolutionTech/hummingbird/labels{/name}","releases_url":"https://api.github.com/repos/RevolutionTech/hummingbird/releases{/id}","created_at":"2015-12-02T05:21:14Z","updated_at":"2015-12-02T05:23:15Z","pushed_at":"2015-12-02T18:29:32Z","git_url":"git://github.com/RevolutionTech/hummingbird.git","ssh_url":"git@github.com:RevolutionTech/hummingbird.git","clone_url":"https://github.com/RevolutionTech/hummingbird.git","svn_url":"https://github.com/RevolutionTech/hummingbird","homepage":null,"size":1798,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/1"},"html":{"href":"https://github.com/RevolutionTech/hummingbird/pull/1"},"issue":{"href":"https://api.github.com/repos/RevolutionTech/hummingbird/issues/1"},"comments":{"href":"https://api.github.com/repos/RevolutionTech/hummingbird/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/RevolutionTech/hummingbird/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/RevolutionTech/hummingbird/statuses/65e048d196ea2ebec60599513d06fb402bebeaea"}}}}