{"action":"created","comment":{"url":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/comments/44009359","id":44009359,"diff_hunk":"@@ -113,111 +120,117 @@ class OffersEdit(View):\n     @staticmethod\n     @correct_slug(Offer, 'offers_edit', 'title')\n     def get(request, slug, id_):  # pylint: disable=unused-argument\n-        u\"\"\"Method responsible for rendering form for offer to be changed.\"\"\"\n+        u\"\"\"Method responsible for rendering form for offer to be changed.\n+\n+        :param request: WSGIRequest instance\n+        :param slug: string Offer title slugified\n+        :param id_: int Offer database unique identifier (primary key)\n+        \"\"\"\n         offer = Offer.objects.get(id=id_)\n-        organization = offer.organization\n-        form = CreateOfferForm()\n-        offer_image_form = OfferImageForm()\n-        images = OfferImage.objects.filter(offer=offer).all()\n \n-        context = {\n-            'offer_form': form,\n-            'organization': organization,\n-            'statuses': OFFERS_STATUSES,\n-            'offer': offer,\n-            'offer_image_form': offer_image_form,\n-            'images': images,\n-            'MEDIA_URL': settings.MEDIA_URL\n-        }\n+        if offer.id or request.user.userprofile.is_administrator:\n+            organizations = [offer.organization]\n+        else:\n+            organizations = request.user.userprofile.organizations.all()\n \n         return render(\n             request,\n             'offers/offer_form.html',\n-            context\n+            {\n+                'offer': offer,\n+                'offer_form': CreateOfferForm(),\n+                'organization': offer.organization,\n+                'organizations': organizations,\n+                'offer_image_form': OfferImageForm(),\n+                'images': OfferImage.objects.filter(offer=offer).all(),\n+                'MEDIA_URL': settings.MEDIA_URL\n+            }\n         )\n \n     @staticmethod\n+    # pylint: disable=too-many-branches\n     def post(request, slug, id_):  # pylint: disable=unused-argument\n-        u\"\"\"Method resposible for saving changed offer.\"\"\"\n-        def _set_main_image(offer, gallery_form):\n-            u\"\"\"Set main image flag unsetting other offers images.\"\"\"\n-            if gallery_form.cleaned_data[\"is_main\"]:\n-                OfferImage.objects.filter(offer=offer).update(is_main=False)\n-                return True\n-            return False\n-\n-        def _save_offer_image(offer, userprofile):\n-            u\"\"\"Handle image upload for user profile page.\"\"\"\n-            gallery_form = OfferImageForm(\n-                request.POST,\n-                request.FILES\n-            )\n-            if gallery_form.is_valid():\n-                gallery = gallery_form.save(commit=False)\n-                gallery.offer = offer\n-                gallery.userprofile = userprofile\n-                gallery.is_main = _set_main_image(offer, gallery_form)\n-                gallery.save()\n-                messages.success(request, u\"Dodano zdjęcie do galerii.\")\n+        u\"\"\"Method resposible for saving changed offer.\n+\n+        :param request: WSGIRequest instance\n+        :param slug: string Offer title slugified\n+        :param id_: int Offer database unique identifier (primary key)\n+        \"\"\"\n+        offer = Offer.objects.get(id=id_)\n+        if request.POST.get('submit') == 'save_image' and request.FILES:\n+            form = OfferImageForm(request.POST, request.FILES)\n+            if form.is_valid():\n+                result = offer.save_offer_image(\n+                    form.save(commit=False),\n+                    request.user.userprofile,\n+                    form.cleaned_data['is_main']\n+                )\n+                if result:","path":"apps/volontulo/views/offers.py","position":193,"original_position":193,"commit_id":"2cc79e9351a557c9b3f2cab5d1a5bf985bcf2ff5","original_commit_id":"2cc79e9351a557c9b3f2cab5d1a5bf985bcf2ff5","user":{"login":"radoslawroszkowiak","id":6575499,"avatar_url":"https://avatars.githubusercontent.com/u/6575499?v=3","gravatar_id":"","url":"https://api.github.com/users/radoslawroszkowiak","html_url":"https://github.com/radoslawroszkowiak","followers_url":"https://api.github.com/users/radoslawroszkowiak/followers","following_url":"https://api.github.com/users/radoslawroszkowiak/following{/other_user}","gists_url":"https://api.github.com/users/radoslawroszkowiak/gists{/gist_id}","starred_url":"https://api.github.com/users/radoslawroszkowiak/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/radoslawroszkowiak/subscriptions","organizations_url":"https://api.github.com/users/radoslawroszkowiak/orgs","repos_url":"https://api.github.com/users/radoslawroszkowiak/repos","events_url":"https://api.github.com/users/radoslawroszkowiak/events{/privacy}","received_events_url":"https://api.github.com/users/radoslawroszkowiak/received_events","type":"User","site_admin":false},"body":"Isn't Offer.save_offer_image() always evaluated to true?","created_at":"2015-11-05T13:13:16Z","updated_at":"2015-11-05T13:13:16Z","html_url":"https://github.com/stxnext-csr/volontulo/pull/364#discussion_r44009359","pull_request_url":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/364","_links":{"self":{"href":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/comments/44009359"},"html":{"href":"https://github.com/stxnext-csr/volontulo/pull/364#discussion_r44009359"},"pull_request":{"href":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/364"}}},"pull_request":{"url":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/364","id":49797669,"html_url":"https://github.com/stxnext-csr/volontulo/pull/364","diff_url":"https://github.com/stxnext-csr/volontulo/pull/364.diff","patch_url":"https://github.com/stxnext-csr/volontulo/pull/364.patch","issue_url":"https://api.github.com/repos/stxnext-csr/volontulo/issues/364","number":364,"state":"open","locked":false,"title":"Issue 62 - offer statuses","user":{"login":"filipgorczynski","id":467026,"avatar_url":"https://avatars.githubusercontent.com/u/467026?v=3","gravatar_id":"","url":"https://api.github.com/users/filipgorczynski","html_url":"https://github.com/filipgorczynski","followers_url":"https://api.github.com/users/filipgorczynski/followers","following_url":"https://api.github.com/users/filipgorczynski/following{/other_user}","gists_url":"https://api.github.com/users/filipgorczynski/gists{/gist_id}","starred_url":"https://api.github.com/users/filipgorczynski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/filipgorczynski/subscriptions","organizations_url":"https://api.github.com/users/filipgorczynski/orgs","repos_url":"https://api.github.com/users/filipgorczynski/repos","events_url":"https://api.github.com/users/filipgorczynski/events{/privacy}","received_events_url":"https://api.github.com/users/filipgorczynski/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-05T09:05:56Z","updated_at":"2015-11-05T13:13:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"06200da68e3b03c4b111df0700b941ffa7234d0b","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/364/commits","review_comments_url":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/364/comments","review_comment_url":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/comments{/number}","comments_url":"https://api.github.com/repos/stxnext-csr/volontulo/issues/364/comments","statuses_url":"https://api.github.com/repos/stxnext-csr/volontulo/statuses/2cc79e9351a557c9b3f2cab5d1a5bf985bcf2ff5","head":{"label":"filipgorczynski:issue-62","ref":"issue-62","sha":"2cc79e9351a557c9b3f2cab5d1a5bf985bcf2ff5","user":{"login":"filipgorczynski","id":467026,"avatar_url":"https://avatars.githubusercontent.com/u/467026?v=3","gravatar_id":"","url":"https://api.github.com/users/filipgorczynski","html_url":"https://github.com/filipgorczynski","followers_url":"https://api.github.com/users/filipgorczynski/followers","following_url":"https://api.github.com/users/filipgorczynski/following{/other_user}","gists_url":"https://api.github.com/users/filipgorczynski/gists{/gist_id}","starred_url":"https://api.github.com/users/filipgorczynski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/filipgorczynski/subscriptions","organizations_url":"https://api.github.com/users/filipgorczynski/orgs","repos_url":"https://api.github.com/users/filipgorczynski/repos","events_url":"https://api.github.com/users/filipgorczynski/events{/privacy}","received_events_url":"https://api.github.com/users/filipgorczynski/received_events","type":"User","site_admin":false},"repo":{"id":42521519,"name":"volontulo","full_name":"filipgorczynski/volontulo","owner":{"login":"filipgorczynski","id":467026,"avatar_url":"https://avatars.githubusercontent.com/u/467026?v=3","gravatar_id":"","url":"https://api.github.com/users/filipgorczynski","html_url":"https://github.com/filipgorczynski","followers_url":"https://api.github.com/users/filipgorczynski/followers","following_url":"https://api.github.com/users/filipgorczynski/following{/other_user}","gists_url":"https://api.github.com/users/filipgorczynski/gists{/gist_id}","starred_url":"https://api.github.com/users/filipgorczynski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/filipgorczynski/subscriptions","organizations_url":"https://api.github.com/users/filipgorczynski/orgs","repos_url":"https://api.github.com/users/filipgorczynski/repos","events_url":"https://api.github.com/users/filipgorczynski/events{/privacy}","received_events_url":"https://api.github.com/users/filipgorczynski/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/filipgorczynski/volontulo","description":"Portal łączący wolontariuszy, organizacje i instytucje.","fork":true,"url":"https://api.github.com/repos/filipgorczynski/volontulo","forks_url":"https://api.github.com/repos/filipgorczynski/volontulo/forks","keys_url":"https://api.github.com/repos/filipgorczynski/volontulo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/filipgorczynski/volontulo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/filipgorczynski/volontulo/teams","hooks_url":"https://api.github.com/repos/filipgorczynski/volontulo/hooks","issue_events_url":"https://api.github.com/repos/filipgorczynski/volontulo/issues/events{/number}","events_url":"https://api.github.com/repos/filipgorczynski/volontulo/events","assignees_url":"https://api.github.com/repos/filipgorczynski/volontulo/assignees{/user}","branches_url":"https://api.github.com/repos/filipgorczynski/volontulo/branches{/branch}","tags_url":"https://api.github.com/repos/filipgorczynski/volontulo/tags","blobs_url":"https://api.github.com/repos/filipgorczynski/volontulo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/filipgorczynski/volontulo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/filipgorczynski/volontulo/git/refs{/sha}","trees_url":"https://api.github.com/repos/filipgorczynski/volontulo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/filipgorczynski/volontulo/statuses/{sha}","languages_url":"https://api.github.com/repos/filipgorczynski/volontulo/languages","stargazers_url":"https://api.github.com/repos/filipgorczynski/volontulo/stargazers","contributors_url":"https://api.github.com/repos/filipgorczynski/volontulo/contributors","subscribers_url":"https://api.github.com/repos/filipgorczynski/volontulo/subscribers","subscription_url":"https://api.github.com/repos/filipgorczynski/volontulo/subscription","commits_url":"https://api.github.com/repos/filipgorczynski/volontulo/commits{/sha}","git_commits_url":"https://api.github.com/repos/filipgorczynski/volontulo/git/commits{/sha}","comments_url":"https://api.github.com/repos/filipgorczynski/volontulo/comments{/number}","issue_comment_url":"https://api.github.com/repos/filipgorczynski/volontulo/issues/comments{/number}","contents_url":"https://api.github.com/repos/filipgorczynski/volontulo/contents/{+path}","compare_url":"https://api.github.com/repos/filipgorczynski/volontulo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/filipgorczynski/volontulo/merges","archive_url":"https://api.github.com/repos/filipgorczynski/volontulo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/filipgorczynski/volontulo/downloads","issues_url":"https://api.github.com/repos/filipgorczynski/volontulo/issues{/number}","pulls_url":"https://api.github.com/repos/filipgorczynski/volontulo/pulls{/number}","milestones_url":"https://api.github.com/repos/filipgorczynski/volontulo/milestones{/number}","notifications_url":"https://api.github.com/repos/filipgorczynski/volontulo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/filipgorczynski/volontulo/labels{/name}","releases_url":"https://api.github.com/repos/filipgorczynski/volontulo/releases{/id}","created_at":"2015-09-15T13:35:41Z","updated_at":"2015-09-24T09:16:37Z","pushed_at":"2015-11-05T11:11:40Z","git_url":"git://github.com/filipgorczynski/volontulo.git","ssh_url":"git@github.com:filipgorczynski/volontulo.git","clone_url":"https://github.com/filipgorczynski/volontulo.git","svn_url":"https://github.com/filipgorczynski/volontulo","homepage":null,"size":4227,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"stxnext-csr:master","ref":"master","sha":"d00c2bad0a4d517c09271317553571bccb359173","user":{"login":"stxnext-csr","id":14179451,"avatar_url":"https://avatars.githubusercontent.com/u/14179451?v=3","gravatar_id":"","url":"https://api.github.com/users/stxnext-csr","html_url":"https://github.com/stxnext-csr","followers_url":"https://api.github.com/users/stxnext-csr/followers","following_url":"https://api.github.com/users/stxnext-csr/following{/other_user}","gists_url":"https://api.github.com/users/stxnext-csr/gists{/gist_id}","starred_url":"https://api.github.com/users/stxnext-csr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stxnext-csr/subscriptions","organizations_url":"https://api.github.com/users/stxnext-csr/orgs","repos_url":"https://api.github.com/users/stxnext-csr/repos","events_url":"https://api.github.com/users/stxnext-csr/events{/privacy}","received_events_url":"https://api.github.com/users/stxnext-csr/received_events","type":"Organization","site_admin":false},"repo":{"id":42171724,"name":"volontulo","full_name":"stxnext-csr/volontulo","owner":{"login":"stxnext-csr","id":14179451,"avatar_url":"https://avatars.githubusercontent.com/u/14179451?v=3","gravatar_id":"","url":"https://api.github.com/users/stxnext-csr","html_url":"https://github.com/stxnext-csr","followers_url":"https://api.github.com/users/stxnext-csr/followers","following_url":"https://api.github.com/users/stxnext-csr/following{/other_user}","gists_url":"https://api.github.com/users/stxnext-csr/gists{/gist_id}","starred_url":"https://api.github.com/users/stxnext-csr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stxnext-csr/subscriptions","organizations_url":"https://api.github.com/users/stxnext-csr/orgs","repos_url":"https://api.github.com/users/stxnext-csr/repos","events_url":"https://api.github.com/users/stxnext-csr/events{/privacy}","received_events_url":"https://api.github.com/users/stxnext-csr/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/stxnext-csr/volontulo","description":"Web portal for collaboration of community volunteers with organizations and institutions.","fork":false,"url":"https://api.github.com/repos/stxnext-csr/volontulo","forks_url":"https://api.github.com/repos/stxnext-csr/volontulo/forks","keys_url":"https://api.github.com/repos/stxnext-csr/volontulo/keys{/key_id}","collaborators_url":"https://api.github.com/repos/stxnext-csr/volontulo/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/stxnext-csr/volontulo/teams","hooks_url":"https://api.github.com/repos/stxnext-csr/volontulo/hooks","issue_events_url":"https://api.github.com/repos/stxnext-csr/volontulo/issues/events{/number}","events_url":"https://api.github.com/repos/stxnext-csr/volontulo/events","assignees_url":"https://api.github.com/repos/stxnext-csr/volontulo/assignees{/user}","branches_url":"https://api.github.com/repos/stxnext-csr/volontulo/branches{/branch}","tags_url":"https://api.github.com/repos/stxnext-csr/volontulo/tags","blobs_url":"https://api.github.com/repos/stxnext-csr/volontulo/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/stxnext-csr/volontulo/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/stxnext-csr/volontulo/git/refs{/sha}","trees_url":"https://api.github.com/repos/stxnext-csr/volontulo/git/trees{/sha}","statuses_url":"https://api.github.com/repos/stxnext-csr/volontulo/statuses/{sha}","languages_url":"https://api.github.com/repos/stxnext-csr/volontulo/languages","stargazers_url":"https://api.github.com/repos/stxnext-csr/volontulo/stargazers","contributors_url":"https://api.github.com/repos/stxnext-csr/volontulo/contributors","subscribers_url":"https://api.github.com/repos/stxnext-csr/volontulo/subscribers","subscription_url":"https://api.github.com/repos/stxnext-csr/volontulo/subscription","commits_url":"https://api.github.com/repos/stxnext-csr/volontulo/commits{/sha}","git_commits_url":"https://api.github.com/repos/stxnext-csr/volontulo/git/commits{/sha}","comments_url":"https://api.github.com/repos/stxnext-csr/volontulo/comments{/number}","issue_comment_url":"https://api.github.com/repos/stxnext-csr/volontulo/issues/comments{/number}","contents_url":"https://api.github.com/repos/stxnext-csr/volontulo/contents/{+path}","compare_url":"https://api.github.com/repos/stxnext-csr/volontulo/compare/{base}...{head}","merges_url":"https://api.github.com/repos/stxnext-csr/volontulo/merges","archive_url":"https://api.github.com/repos/stxnext-csr/volontulo/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/stxnext-csr/volontulo/downloads","issues_url":"https://api.github.com/repos/stxnext-csr/volontulo/issues{/number}","pulls_url":"https://api.github.com/repos/stxnext-csr/volontulo/pulls{/number}","milestones_url":"https://api.github.com/repos/stxnext-csr/volontulo/milestones{/number}","notifications_url":"https://api.github.com/repos/stxnext-csr/volontulo/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/stxnext-csr/volontulo/labels{/name}","releases_url":"https://api.github.com/repos/stxnext-csr/volontulo/releases{/id}","created_at":"2015-09-09T10:23:12Z","updated_at":"2015-10-30T13:49:08Z","pushed_at":"2015-11-05T11:12:29Z","git_url":"git://github.com/stxnext-csr/volontulo.git","ssh_url":"git@github.com:stxnext-csr/volontulo.git","clone_url":"https://github.com/stxnext-csr/volontulo.git","svn_url":"https://github.com/stxnext-csr/volontulo","homepage":"","size":5156,"stargazers_count":3,"watchers_count":3,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":68,"forks":6,"open_issues":68,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/364"},"html":{"href":"https://github.com/stxnext-csr/volontulo/pull/364"},"issue":{"href":"https://api.github.com/repos/stxnext-csr/volontulo/issues/364"},"comments":{"href":"https://api.github.com/repos/stxnext-csr/volontulo/issues/364/comments"},"review_comments":{"href":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/364/comments"},"review_comment":{"href":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/stxnext-csr/volontulo/pulls/364/commits"},"statuses":{"href":"https://api.github.com/repos/stxnext-csr/volontulo/statuses/2cc79e9351a557c9b3f2cab5d1a5bf985bcf2ff5"}}}}