internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: shuup/shuup

Issue:
Admin: Fix category name in category edit view
Do not show the category with hierarchy on breadcrumbs and title

![image](https://user-images.githubusercontent.com/8770370/46307475-6926a100-c58d-11e8-82cf-cac5729c7563.png)



Discussion:

Resolving patch:
diff --git a/shuup/admin/modules/categories/views/edit.py b/shuup/admin/modules/categories/views/edit.py
--- a/shuup/admin/modules/categories/views/edit.py
+++ b/shuup/admin/modules/categories/views/edit.py
@@ -35,6 +35,9 @@ def get_context_data(self, **kwargs):
         context = super(CategoryEditView, self).get_context_data(**kwargs)
         context["tour_key"] = "category"
         context["tour_complete"] = is_tour_complete(get_shop(self.request), "category")
+        if self.object.pk:
+            context["title"] = self.object.name
+
         return context
 
     def form_valid(self, form):


Test patch:
Repository: shuup/shuup

Issue:
Admin: Main menu won't stay hidden
Two issues (at least):
Desktop:  If I close (minimize, desktop) main-menu and click any link, the menu appears again.
Desktop to mobile: If I minimize the menu on a bigger desktop and then drag window smaller the menu appears again. 


Discussion:
As a related issue, tour only shows the search bar and the "View your storefront" when the menu is hidden.

Resolving patch:
diff --git a/shuup/admin/views/menu.py b/shuup/admin/views/menu.py
--- a/shuup/admin/views/menu.py
+++ b/shuup/admin/views/menu.py
@@ -15,5 +15,5 @@ class MenuView(TemplateView):
 
 class MenuToggleView(View):
     def post(self, request, *args, **kwargs):
-        request.session["menu_open"] = int(request.POST.get("menu_open", 0))
+        request.session["menu_open"] = not bool(request.session.get("menu_open", True))
         return JsonResponse({"success": True})


Test patch:
diff --git a/shuup_tests/browser/admin/test_menu.py b/shuup_tests/browser/admin/test_menu.py
--- a/shuup_tests/browser/admin/test_menu.py
+++ b/shuup_tests/browser/admin/test_menu.py
@@ -82,11 +82,29 @@ def test_menu_toggle(browser, admin_user, live_server, settings):
     wait_until_condition(browser, lambda x: x.is_text_present("Welcome!"))
     wait_until_condition(browser, lambda x: x.is_text_present("Quicklinks"))
 
-    browser.find_by_css("#menu-button").first.click()
-    url = live_server + "/sa"
-    browser.visit(url)
-    assert browser.find_by_css(".desktop-menu-closed")
+    wait_until_condition(browser, lambda x: x.is_element_present_by_css("#menu-button"))
 
+    # Close menu
+    try:
+        browser.find_by_css("#menu-button").first.click()
+    except selenium.common.exceptions.TimeoutException as e:
+        browser.find_by_css("#menu-button").first.click()
+    wait_until_condition(browser, lambda x: x.is_element_present_by_css(".desktop-menu-closed"))
+
+    url = reverse("shuup_admin:order.list")
+    browser.visit("%s%s" % (live_server, url))
+    wait_until_condition(browser, condition=lambda x: x.is_text_present("Orders"))
+
+    # Should be closed after page load
+    wait_until_condition(browser, lambda x: x.is_element_present_by_css(".desktop-menu-closed"))
+
+    # Open menu
     browser.find_by_css("#menu-button").first.click()
-    browser.visit(url)
-    assert not browser.find_by_css(".desktop-menu-closed")
+    wait_until_condition(browser, lambda x: not x.is_element_present_by_css(".desktop-menu-closed"))
+
+    url = reverse("shuup_admin:shop_product.list")
+    browser.visit("%s%s" % (live_server, url))
+    wait_until_condition(browser, condition=lambda x: x.is_text_present("Products"))
+
+    # Should be still open after page load
+    wait_until_condition(browser, lambda x: not x.is_element_present_by_css(".desktop-menu-closed"))
Repository: shuup/shuup

Issue:
Admin UI: remove extra input box
There are two same input boxes in the "Contact Group Discount" and "Contact Group Pricing" section.

![screenshot at 2018-10-10 17-10-57](https://user-images.githubusercontent.com/3711883/46726423-e1d5dd80-ccb0-11e8-9dda-4e24cbe87f3c.png)



Discussion:

Resolving patch:
diff --git a/shuup/api/docs.py b/shuup/api/docs.py
--- a/shuup/api/docs.py
+++ b/shuup/api/docs.py
@@ -144,10 +144,15 @@ def get_serializer_fields(self, path, method, view):
         return fields
 
 
+class JSONOpenAPIRenderer(renderers.OpenAPIRenderer):
+    media_type = 'application/json'
+
+
 class SwaggerSchemaView(APIView):
     renderer_classes = [
         renderers.OpenAPIRenderer,
-        renderers.SwaggerUIRenderer
+        renderers.SwaggerUIRenderer,
+        JSONOpenAPIRenderer
     ]
 
     def get(self, request):
diff --git a/shuup/core/api/front_passwords.py b/shuup/core/api/front_passwords.py
--- a/shuup/core/api/front_passwords.py
+++ b/shuup/core/api/front_passwords.py
@@ -72,6 +72,8 @@ def save(self):
 
 
 class PasswordResetViewSet(GenericViewSet):
+    serializer_class = serializers.BaseSerializer
+
     def create(self, request):
         form = RecoverPasswordForm(request.data)
         if form.is_valid():
@@ -82,6 +84,8 @@ def create(self, request):
 
 
 class SetPasswordViewSet(GenericViewSet):
+    serializer_class = serializers.BaseSerializer
+
     def create(self, request):
         if not request.user.is_anonymous():
             serializer = SetAuthenticatedUserPasswordSerializer(data=request.data, context={'request': request})
diff --git a/shuup/customer_group_pricing/admin_form_part.py b/shuup/customer_group_pricing/admin_form_part.py
--- a/shuup/customer_group_pricing/admin_form_part.py
+++ b/shuup/customer_group_pricing/admin_form_part.py
@@ -33,9 +33,9 @@ def _build_fields(self):
             Q(price_display_options__show_pricing=True) |
             Q(
                 id__in=CgpPrice.objects.filter(product=self.product)
-                .values_list("group_id", flat=True).distinct()
+                .values_list("group_id", flat=True)
             )
-        ))
+        ).distinct())
         prices_by_shop_and_group = dict(
             ((shop_id or 0, group_id or 0), price)
             for (shop_id, group_id, price)
@@ -114,9 +114,9 @@ def _build_fields(self):
             Q(price_display_options__show_pricing=True) |
             Q(
                 id__in=CgpDiscount.objects.filter(product=self.product)
-                .values_list("group_id", flat=True).distinct()
+                .values_list("group_id", flat=True)
             )
-        ))
+        ).distinct())
         discounts_by_shop_and_group = dict(
             ((shop_id or 0, group_id or 0), discount_amount)
             for (shop_id, group_id, discount_amount)


Test patch:
Repository: shuup/shuup

Issue:
Add option to remove coupon code from basket
There isn't option to remove coupon code from basket. Should likely be done with basket command at basket view [this](https://github.com/shuup/shuup/blob/master/shuup/core/basket/commands.py#L177).


Discussion:

Resolving patch:
diff --git a/shuup/front/basket/commands.py b/shuup/front/basket/commands.py
--- a/shuup/front/basket/commands.py
+++ b/shuup/front/basket/commands.py
@@ -7,5 +7,5 @@
 # LICENSE file in the root directory of this source tree.
 from shuup.core.basket.commands import (  # noqa
     handle_add, handle_add_campaign_code, handle_add_var, handle_clear,
-    handle_del, handle_update
+    handle_del, handle_remove_campaign_code, handle_update
 )


Test patch:
diff --git a/shuup_tests/campaigns/test_basket_campaigns.py b/shuup_tests/campaigns/test_basket_campaigns.py
--- a/shuup_tests/campaigns/test_basket_campaigns.py
+++ b/shuup_tests/campaigns/test_basket_campaigns.py
@@ -28,7 +28,7 @@
 )
 from shuup.core.order_creator import OrderCreator
 from shuup.front.basket import get_basket
-from shuup.front.basket.commands import handle_add_campaign_code
+from shuup.front.basket.commands import handle_add_campaign_code, handle_remove_campaign_code
 from shuup.testing.factories import (
     CategoryFactory, create_product, get_default_product, get_default_shop,
     get_default_supplier, get_shipping_method
@@ -258,24 +258,34 @@ def test_multiple_campaigns_match_with_coupon(rf):
 
     dc = Coupon.objects.create(code="TEST", active=True)
     campaign2 = BasketCampaign.objects.create(
-            shop=shop, public_name="test",
-            name="test",
-            coupon=dc,
-            active=True
+        shop=shop, public_name="test",
+        name="test",
+        coupon=dc,
+        active=True
     )
 
     BasketDiscountAmount.objects.create(discount_amount=discount2, campaign=campaign2)
-
     basket.add_product(supplier=supplier, shop=shop, product=product, quantity=1)
 
     resp = handle_add_campaign_code(request, basket, dc.code)
     assert resp.get("ok")
 
-    discount_lines_values = [line.discount_amount for line in basket.get_final_lines()]
+    discount_lines_values = [line.discount_amount for line in basket.get_final_lines() if line.type == OrderLineType.DISCOUNT]
     assert price(discount1) in discount_lines_values
     assert price(discount2) in discount_lines_values
     assert basket.total_price == (price(product_price) * basket.product_count - price(discount1) - price(discount2))
 
+    assert basket.codes == [dc.code]
+
+    # test code removal
+    resp = handle_remove_campaign_code(request, basket, dc.code)
+    assert resp.get("ok")
+
+    assert basket.codes == []
+    discount_lines_values = [line.discount_amount for line in basket.get_final_lines() if line.type == OrderLineType.DISCOUNT]
+    assert price(discount1) in discount_lines_values
+    assert not price(discount2) in discount_lines_values
+
 
 @pytest.mark.django_db
 def test_percentage_campaign(rf):
Repository: shuup/shuup

Issue:
 Admin UI: Fix media browser file upload
An exception is raised when you manually select the file while uploading it. To reproduce:
- Go to Products
- Select/Create a product
- Go to Files section
- Click over the dropzone area
- In the media browser window, click Upload
- Select a file and check the console (error)

![image](https://user-images.githubusercontent.com/8770370/51994097-3b982880-2497-11e9-972e-9c890268ea5b.png)



Discussion:

Resolving patch:
diff --git a/shuup/admin/browser_config.py b/shuup/admin/browser_config.py
--- a/shuup/admin/browser_config.py
+++ b/shuup/admin/browser_config.py
@@ -7,6 +7,7 @@
 # LICENSE file in the root directory of this source tree.
 from django.conf import settings
 
+from shuup.admin.utils.permissions import has_permission
 from shuup.utils.i18n import get_current_babel_locale
 
 
@@ -26,7 +27,7 @@ def get_browser_urls(cls, request, **kwargs):
         return {
             "edit": "shuup_admin:edit",
             "select": "shuup_admin:select",
-            "media": "shuup_admin:media.browse",
+            "media": ("shuup_admin:media.browse" if has_permission(request.user, "shuup_admin:media.browse") else None),
             "product": "shuup_admin:shop_product.list",
             "contact": "shuup_admin:contact.list",
             "setLanguage": "shuup_admin:set-language",
@@ -42,5 +43,6 @@ def get_gettings(cls, request, **kwargs):
             "datetimeInputFormat": settings.SHUUP_ADMIN_DATETIME_INPUT_FORMAT,
             "timeInputFormat": settings.SHUUP_ADMIN_TIME_INPUT_FORMAT,
             "datetimeInputStep": settings.SHUUP_ADMIN_DATETIME_INPUT_STEP,
-            "dateInputLocale": get_current_babel_locale().language
+            "dateInputLocale": get_current_babel_locale().language,
+            "staticPrefix": settings.STATIC_URL,
         }


Test patch:
Repository: shuup/shuup

Issue:
Xtheme: there is no warning for usaved changes when switching between plugins
To reproduce:
1. Edit some content in Xtheme editor
2. Select another plugin without saving
3. See your changes to disappear

There probably should be warning before switching plugins when you have unsaved information.


Discussion:

Resolving patch:
diff --git a/shuup/campaigns/admin_module/forms/_basket.py b/shuup/campaigns/admin_module/forms/_basket.py
--- a/shuup/campaigns/admin_module/forms/_basket.py
+++ b/shuup/campaigns/admin_module/forms/_basket.py
@@ -30,7 +30,7 @@ def __init__(self, *args, **kwargs):
         if supplier:
             coupons = coupons.filter(supplier=supplier)
 
-        coupon_code_choices = [('', '')] + list(coupons.values_list("pk", "code"))
+        coupon_code_choices = [('', '---------')] + list(coupons.values_list("pk", "code"))
         field_kwargs = dict(choices=coupon_code_choices, required=False)
         field_kwargs["help_text"] = _("Define the required coupon for this campaign.")
         field_kwargs["label"] = _("Coupon")


Test patch:
Repository: shuup/shuup

Issue:
It is impossible to remove all Xtheme placeholder lines
I am trying to use the default content set by the template by deleting all the lines from the editor, but a blank line is always used, so the fallback content is never used. This is what the template uses:

```jinja
{% placeholder "content" %}
    {% column {"xs": 12} %}
        {% plugin "text" %}
            text = 'My default content'
        {% endplugin %}
    {% endcolumn %}
{% endplaceholder %}
``` 


Discussion:

Resolving patch:
diff --git a/shuup/xtheme/layout/_base.py b/shuup/xtheme/layout/_base.py
--- a/shuup/xtheme/layout/_base.py
+++ b/shuup/xtheme/layout/_base.py
@@ -415,12 +415,6 @@ def delete_row(self, y):
 
         self.rows.pop(y)
 
-        if len(self.rows) == 0:
-            # In case is deleting last row we don't want the
-            # placeholder defaults to kick in. Instead let's add
-            # empty row here to prevent that.
-            self.rows.append(LayoutRow(self.theme))
-
         return True
 
     def move_row_to_index(self, from_y, to_y):
diff --git a/shuup/xtheme/models.py b/shuup/xtheme/models.py
--- a/shuup/xtheme/models.py
+++ b/shuup/xtheme/models.py
@@ -130,6 +130,7 @@ def revert(self):
 
     def set_layout_data(self, layout_data_key, layout):
         if not layout:  # pragma: no cover
+            self._data.setdefault("layouts", {}).pop(layout_data_key, None)
             return None
         if not self.draft:
             raise ValueError("Unable to save things in non-draft mode!")


Test patch:
Repository: ansible/ansible

Issue:
ansible web-servers -m setup -a "http_port=8080" -u username
hpcloud-a | FAILED => Traceback (most recent call last):

  File "/Users/cocoy/fromLinux/github/ansible/lib/ansible/runner.py", line 537, in _executor
    (host, ok, data, err) = self._executor_internal(host)
  File "/Users/cocoy/fromLinux/github/ansible/lib/ansible/runner.py", line 576, in _executor_internal
    result = self._execute_normal_module(conn, host, tmp, module_name)
  File "/Users/cocoy/fromLinux/github/ansible/lib/ansible/runner.py", line 351, in _execute_normal_module
    self._add_result_to_setup_cache(conn, result)
  File "/Users/cocoy/fromLinux/github/ansible/lib/ansible/runner.py", line 324, in _add_result_to_setup_cache
    var_result = result['ansible_facts']
TypeError: string indices must be integers, not str

--btw, this is using Ubuntu Oneiric, passwordless login and ansible/devel branch



Discussion:
I can reproduce this. As I broke it, I will fix it.


Resolving patch:
diff --git a/lib/ansible/runner.py b/lib/ansible/runner.py
--- a/lib/ansible/runner.py
+++ b/lib/ansible/runner.py
@@ -347,8 +347,6 @@ def _execute_normal_module(self, conn, host, tmp, module_name):
         module = self._transfer_module(conn, tmp, module_name)
         (result, err, executed) = self._execute_module(conn, tmp, module, self.module_args)
 
-        if module_name == 'setup':
-            self._add_result_to_setup_cache(conn, result)
         (host, ok, data, err) = self._return_from_module(conn, host, result, err, executed)
 
         if ok:


Test patch:
Repository: ansible/ansible

Issue:
License not included in SDIST
Encountered this while addressing the points brought up by during the Fedora review process. Need to add the COPYING file to the MANIFEST.in so it's included in future tar.gz's. Until then (and a new tar.gz is available on Downloads) I'm going to patch the license file in manually.



Discussion:

Resolving patch:
diff --git a/lib/ansible/__init__.py b/lib/ansible/__init__.py
--- a/lib/ansible/__init__.py
+++ b/lib/ansible/__init__.py
@@ -14,5 +14,5 @@
 #
 # You should have received a copy of the GNU General Public License
 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
-__version__ = '0.3'
+__version__ = '0.3.1'
 __author__ = 'Michael DeHaan'
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -17,7 +17,7 @@
       author=__author__,
       author_email='michael.dehaan@gmail.com',
       url='http://ansible.github.com/',
-      license='GPLv3',
+      license='GPLv3+',
       install_requires=['paramiko', 'jinja2', "PyYAML"],
       package_dir={ 'ansible': 'lib/ansible' },
       packages=[


Test patch:
Repository: ansible/ansible

Issue:
AIX: /bin/ksh: mktemp:  not found 
AIX does not come with **mktemp**, which is a (hidden) requirement of Ansible at this point.



Discussion:
So the consensus is to have the server generate a string and then execute `mkdir -p ansible-<epoch>-<random>` on the remote end so that we do not rely on the availability of **mktemp**.


Resolving patch:
diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py
--- a/lib/ansible/runner/__init__.py
+++ b/lib/ansible/runner/__init__.py
@@ -639,7 +639,7 @@ def _executor_internal(self, host):
         cache = self.setup_cache.get(host, {})
         module_name = utils.template(self.module_name, cache, self.setup_cache)
 
-        tmp = self._get_tmp_path(conn)
+        tmp = self._make_tmp_path(conn)
         result = None
 
         if self.module_name == 'copy':
@@ -691,22 +691,20 @@ def _low_level_exec_command(self, conn, cmd, tmp, sudoable=False):
 
     # *****************************************************
 
-    def _get_tmp_path(self, conn):
-        ''' gets a temporary path on a remote box '''
+    def _make_tmp_path(self, conn):
+        ''' make and return a temporary path on a remote box '''
 
         basetmp = C.DEFAULT_REMOTE_TMP
         if self.remote_user == 'root':
-            basetmp ="/var/tmp"
-        cmd = "mktemp -d %s/ansible.XXXXXX" % basetmp
+            basetmp = "/var/tmp"
+        basetmp = os.path.join(basetmp, 'ansible-%s-%s' % (time.time(), random.randint(0, 2**48)))
+
+        cmd = "mkdir -p %s" % basetmp
         if self.remote_user != 'root':
-            cmd = "mkdir -p %s && %s" % (basetmp, cmd)
+            cmd += " && chmod a+x %s" % basetmp
 
         result = self._low_level_exec_command(conn, cmd, None, sudoable=False)
-        cleaned = result.split("\n")[0].strip() + '/'
-        if self.remote_user != 'root':
-            cmd = 'chmod a+x %s' % cleaned
-            self._low_level_exec_command(conn, cmd, None, sudoable=False)
-        return cleaned
+        return basetmp
 
 
     # *****************************************************
@@ -720,7 +718,7 @@ def _copy_module(self, conn, tmp, module):
         if not os.path.exists(in_path):
             raise errors.AnsibleFileNotFound("module not found: %s" % in_path)
 
-        out_path = tmp + module
+        out_path = os.path.join(tmp, module)
         conn.put_file(in_path, out_path)
         return out_path
 


Test patch:
Repository: ansible/ansible

Issue:
AIX: /bin/ksh: mktemp:  not found 
AIX does not come with **mktemp**, which is a (hidden) requirement of Ansible at this point.

Get rid of mktemp dependency to support AIX
The function call has been renamed to better reflect what it does, and we
reduced the number of calls from two to one in case the remote user is not
root.

This patch also fixes a string concatenation in _copy_module() that
should use os.path.join()

This closes #436



Discussion:
So the consensus is to have the server generate a string and then execute `mkdir -p ansible-<epoch>-<random>` on the remote end so that we do not rely on the availability of **mktemp**.

looks good, in queue for testing/merging.   Thanks!


Resolving patch:
diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py
--- a/lib/ansible/runner/__init__.py
+++ b/lib/ansible/runner/__init__.py
@@ -639,7 +639,7 @@ def _executor_internal(self, host):
         cache = self.setup_cache.get(host, {})
         module_name = utils.template(self.module_name, cache, self.setup_cache)
 
-        tmp = self._get_tmp_path(conn)
+        tmp = self._make_tmp_path(conn)
         result = None
 
         if self.module_name == 'copy':
@@ -691,21 +691,21 @@ def _low_level_exec_command(self, conn, cmd, tmp, sudoable=False):
 
     # *****************************************************
 
-    def _get_tmp_path(self, conn):
-        ''' gets a temporary path on a remote box '''
+    def _make_tmp_path(self, conn):
+        ''' make and return a temporary path on a remote box '''
 
-        basetmp = C.DEFAULT_REMOTE_TMP
+        basefile = 'ansible-%s-%s' % (time.time(), random.randint(0, 2**48))
+        basetmp = os.path.join(C.DEFAULT_REMOTE_TMP, basefile)
         if self.remote_user == 'root':
-            basetmp ="/var/tmp"
-        cmd = "mktemp -d %s/ansible.XXXXXX" % basetmp
+            basetmp = os.path.join('/var/tmp', basefile)
+
+        cmd = 'mkdir -p %s' % basetmp
         if self.remote_user != 'root':
-            cmd = "mkdir -p %s && %s" % (basetmp, cmd)
+            cmd += ' && chmod a+x %s' % basetmp
+        cmd += ' && echo %s' % basetmp
 
         result = self._low_level_exec_command(conn, cmd, None, sudoable=False)
         cleaned = result.split("\n")[0].strip() + '/'
-        if self.remote_user != 'root':
-            cmd = 'chmod a+x %s' % cleaned
-            self._low_level_exec_command(conn, cmd, None, sudoable=False)
         return cleaned
 
 
@@ -720,7 +720,7 @@ def _copy_module(self, conn, tmp, module):
         if not os.path.exists(in_path):
             raise errors.AnsibleFileNotFound("module not found: %s" % in_path)
 
-        out_path = tmp + module
+        out_path = os.path.join(tmp, module)
         conn.put_file(in_path, out_path)
         return out_path
 


Test patch: