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

Issue:
Civis are probably now deleted from the DB
If there is a problem with one cause and two solutions the total number of Civis is 4. 
If I delete the cause, the number of Civis changes to 3 instead of 1.
I suspect that in this case the solutions are not deleted.


Discussion:
Let's see if we can verify this bug with the recent CiviWiki codebase.
@brylie, may I work on this one as well?
@silvarthur, sure. Let's just be cautious about how much work we take at once. Hopefully, this and #147 won't be too difficult.
Ok, @brylie . I will be working only on those two issues you assigned to me.

Resolving patch:
diff --git a/project/threads/api.py b/project/threads/api.py
--- a/project/threads/api.py
+++ b/project/threads/api.py
@@ -355,6 +355,11 @@ def delete_civi(request):
         return JsonResponse({"error": "No Edit Rights"}, status=400)
 
     try:
+        if c.c_type == "cause":
+            for cv in c.linked_civis.all():
+                if cv.c_type == "solution":
+                    cv.delete()
+
         c.delete()
         return JsonResponse({"result": "Success"})
     except Exception as e:


Test patch:
Repository: CiviWiki/OpenCiviWiki

Issue:
Add "Following" tab to the user profile view
We recently removed some features from the user Profile view and now want to reimplement them using only Django.

This task will be to add a "Following" tab to the user profile view. The tab should link to a sub-path of the user profile, so it is clear to the viewer that they are viewing users that a particular user is following.

## Task
All of these tasks should be done in the `accounts` app.

- [ ] create a Django view called `UserFollowing` (in `accounts/views.py`)
- [ ] create a URL definition `profile/<str:username>/following` that renders the `UserFollowing` view ( in `accounts/urls.py`)
- [ ] ensure the `UserFollowing` view context contains a list of users that the relevant user is following (given via the `username` in the URL) 
    - note, it should be possible to get profiles that the user follower via `user.profile.following` or just `profile.following`
- [ ] create a template to render the followed usernames - for now, extending `base.html` so we have consistent branding  (in `accounts/templates/accounts/user_civis.html`)



Discussion:
I would like to work on this.

Resolving patch:
diff --git a/project/accounts/urls.py b/project/accounts/urls.py
--- a/project/accounts/urls.py
+++ b/project/accounts/urls.py
@@ -8,6 +8,7 @@
     ProfileUnfollow,
     RegisterView,
     SettingsView,
+    ProfileFollowing,
     UserProfileView,
     expunge_user,
 )
@@ -37,6 +38,11 @@
         ProfileUnfollow.as_view(),
         name="profile-unfollow",
     ),
+    path(
+        "profile/<str:username>/following",
+        ProfileFollowing.as_view(),
+        name="profile-following",
+    ),
     path(
         "accounts/password_reset/",
         PasswordResetView.as_view(),
diff --git a/project/accounts/views.py b/project/accounts/views.py
--- a/project/accounts/views.py
+++ b/project/accounts/views.py
@@ -188,6 +188,24 @@ def get(self, request, username=None):
         )
 
 
+class ProfileFollowing(LoginRequiredMixin, View):
+    """
+    A view that shows list of profiles
+    that profile with given username is following
+    """
+
+    def get(self, request, username=None):
+        profile = get_object_or_404(Profile, user__username=username)
+
+        return TemplateResponse(
+            request,
+            "profile_following.html",
+            {
+                "profile": profile,
+            },
+        )
+
+
 @login_required
 def expunge_user(request):
     """


Test patch:
Repository: CiviWiki/OpenCiviWiki

Issue:
Fix symmetrical relationship warning
### Idea summary

Our Civi model has a relationship to itself with a `related_name` defined, causing the following warning to appear.

### Further details

```
WARNINGS:
threads.Civi.linked_civis: (fields.W345) related_name has no effect on ManyToManyField with a symmetrical relationship, e.g. to "self".
```

## Task

- [ ] ensure the above warning doesn't display anymore
    - e.g., remove the `related_name` argument, or set it to `+`



Discussion:
Hey, I'm interested in working on this issue. Can you please elaborate more?

Thanks, @poorvaditya18! I'll assign you to the issue.
Can you specify the path where I could exactly find this function?
It looks like the warning message stems from the following line.

https://github.com/CiviWiki/OpenCiviWiki/blob/034d8df40ff6224c352f8bddfc3c1a162163f55a/project/threads/models.py#L227
I am facing the issue while running  python manage.py runserver . Could you tell me the steps/commands how to start it ? 
@poorvaditya18, please follow the [instructions in our development guide](https://github.com/CiviWiki/OpenCiviWiki/blob/develop/CONTRIBUTING.md#development). If you encounter any issues, let us know which step is failing and the specific error so we can help troubleshoot.

What error are you getting when running `python manage.py runserver`?
Hey I'm interested in contributing to this issue
@poorvaditya18, are you still working on this task, or should we assign it to @macintushar?
> @poorvaditya18, are you still working on this task, or should we assign it to @macintushar?

Yes I'm working on it. 
Let me know if it is up for grab, @poorvaditya18 & @brylie. 
I've assigned you both since you have both expressed interest.
Hi @brylie , being new to Open Source, I'm not sure what the etiquette is... I believe I've got a fix for this so I'm just putting it in here (but if this is a fix and people are happy for me to go through the steps, I'd love to be assigned and able to make my first contribution to open source)

in  ...project\threads\models.py line 234

> linked_civis = models.ManyToManyField("self", related_name="links", **symmetrical=False,** blank=True)
 
 
That looks like the correct solution. We'll give @darshanip and @poorvaditya18 some time to resolve the issue.

Resolving patch:
diff --git a/project/threads/models.py b/project/threads/models.py
--- a/project/threads/models.py
+++ b/project/threads/models.py
@@ -231,7 +231,7 @@ class Civi(models.Model):
 
     tags = TaggableManager()
 
-    linked_civis = models.ManyToManyField("self", related_name="links", blank=True)
+    linked_civis = models.ManyToManyField("self", related_name="links", symmetrical=False, blank=True)
 
     title = models.CharField(max_length=255, blank=False, null=False)
     body = models.CharField(max_length=1023, blank=False, null=False)


Test patch:
Repository: CiviWiki/OpenCiviWiki

Issue:
Add "Followers" tab to the user profile view
We recently removed some features from the user Profile view and now want to reimplement them using only Django.

This task will be to add a "Followers" tab to the user profile view. The tab should link to a sub-path of the user profile so it is clear to the viewer that they are viewing followers related to the user.

## Task
All of these tasks should be done in the `accounts` app.

- [ ] create a Django view called `UserFollowers` (in `accounts/views.py`)
- [ ] create a URL definition `profile/<str:username>/followers` that renders the `UserFollowers` view ( in `accounts/urls.py`)
- [ ] ensure the `UserFollowers` view context contains a list of users that are following the relevant user (given via the `username` in the URL) 
    - note, it should be possible to get the followers via `user.profile.followers` or just `profile.followers`
- [ ] create a template to render the user followers - for now, extending `base.html` so we have consistent branding  (in `accounts/templates/accounts/user_civis.html`)



Discussion:
I'd like to work on this issue.

Resolving patch:
diff --git a/project/accounts/urls.py b/project/accounts/urls.py
--- a/project/accounts/urls.py
+++ b/project/accounts/urls.py
@@ -8,6 +8,7 @@
     ProfileUnfollow,
     RegisterView,
     SettingsView,
+    UserFollowers,
     ProfileFollowing,
     UserProfileView,
     UserCivis,
@@ -34,6 +35,11 @@
     path(
         "profile/<str:username>/follow", ProfileFollow.as_view(), name="profile-follow"
     ),
+    path(
+        "profile/<str:username>/followers",
+        UserFollowers.as_view(),
+        name="user-followers",
+    ),
     path(
         "profile/<str:username>/unfollow",
         ProfileUnfollow.as_view(),
diff --git a/project/accounts/views.py b/project/accounts/views.py
--- a/project/accounts/views.py
+++ b/project/accounts/views.py
@@ -188,6 +188,22 @@ def get(self, request, username=None):
         )
 
 
+
+class UserFollowers(LoginRequiredMixin, View):
+    """A view that shows the followers for authorized users"""
+    
+    def get(self, request, username=None):
+        profile = get_object_or_404(Profile, user__username=username)
+
+        return TemplateResponse(
+            request,
+            "user_followers.html",
+            {
+                "profile": profile,
+            },
+        )
+
+
 class ProfileFollowing(LoginRequiredMixin, View):
     """
     A view that shows list of profiles
@@ -199,13 +215,16 @@ def get(self, request, username=None):
 
         return TemplateResponse(
             request,
+
             "profile_following.html",
+
             {
                 "profile": profile,
             },
         )
 
 
+
 class UserCivis(LoginRequiredMixin, View):
     """
     A view that shows list of civis
@@ -224,6 +243,7 @@ def get(self, request, username=None):
         )
 
 
+
 @login_required
 def expunge_user(request):
     """


Test patch:
Repository: CiviWiki/OpenCiviWiki

Issue:
Reimplement user categories feature
We recently removed some features from the user Profile view and now want to reimplement them using only Django.

This task will be to add a "categories" field to the User Profile ("settings") view).

## Task

All of these tasks should be done in the `accounts` app.

- [ ] determine how to add a multi-select field to a Django form
- [ ] users should be able to select zero or more categories when editing their profile
- [ ] when a user updates their categories, the categories should be listed on the user profile page



Discussion:
Hello @brylie I'll love to work on this issue please assign it to me.
Hello @brylie haven't heard from you, please 
should I go ahead?
@TimOsahenru, thanks for taking this issue. I'll assign you.

Please keep in mind that people are working in different time zones worldwide and typically in their spare time, so they might not be able to respond immediately when mentioned.
Hello @brylie I am having a bit of a challenge displaying the list of categories; the issue is, it just display's as a plain list instead of a clickable selective list, please I need assistance on how to execute this, below is a screenshot of my code and a description of my challenge. Please I need your assistance

![1](https://user-images.githubusercontent.com/93861430/199154757-d7ef0518-44aa-4d98-9b9b-bbfce084f58b.png)

![2](https://user-images.githubusercontent.com/93861430/199154773-58ea0cbb-cd07-490d-ace5-c6b1fc3d6030.png)

Go ahead and commit your code, push the changes to GitHub, and open a pull request where we can discuss the code. That will help move the discussion forward since reviewers can also check out your code.

I think the solution may be to use the ModelMultipleChoiceField:

https://docs.djangoproject.com/en/4.1/ref/forms/fields/#modelmultiplechoicefield

Is this issue closed? I would love to handle this issue
@Nehemiah60 this issue is still open. Please review the discussion and try to carry forward the existing pull request.

Resolving patch:
diff --git a/project/accounts/views.py b/project/accounts/views.py
--- a/project/accounts/views.py
+++ b/project/accounts/views.py
@@ -178,7 +178,6 @@ class UserProfileView(LoginRequiredMixin, View):
 
     def get(self, request, username=None):
         profile = get_object_or_404(Profile, user__username=username)
-
         return TemplateResponse(
             request,
             "account.html",
@@ -193,7 +192,6 @@ class UserFollowers(LoginRequiredMixin, View):
 
     def get(self, request, username=None):
         profile = get_object_or_404(Profile, user__username=username)
-
         return TemplateResponse(
             request,
             "user_followers.html",


Test patch:
Repository: liqd/a4-meinberlin

Issue:
HTML editor in create-text process not fully working
The HTML editor in create-text-process not working. I currently can't add links to other website or upload pictures ;)

<img width="803" alt="bildschirmfoto 2017-02-13 um 17 24 40" src="https://cloud.githubusercontent.com/assets/11075214/22891998/5bc735ac-f211-11e6-8766-a7588873b436.png">



Discussion:
Tabs are fixed. Image upload is still an issue.

Resolving patch:
diff --git a/meinberlin/settings/base.py b/meinberlin/settings/base.py
--- a/meinberlin/settings/base.py
+++ b/meinberlin/settings/base.py
@@ -146,6 +146,9 @@
 STATIC_ROOT = os.path.join(BASE_DIR, 'static')
 STATIC_URL = '/static/'
 
+MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
+MEDIA_URL = '/media/'
+
 IMAGE_ALIASES = {
     '*': {
         'max_size': 5*10**6,
diff --git a/meinberlin/urls.py b/meinberlin/urls.py
--- a/meinberlin/urls.py
+++ b/meinberlin/urls.py
@@ -2,6 +2,7 @@
 
 from allauth import urls as allauth_urls
 from ckeditor_uploader import views as ck_views
+from django.conf import settings
 from django.conf.urls import include
 from django.conf.urls import url
 from django.contrib import admin
@@ -55,3 +56,12 @@
         js_info_dict, name='javascript-catalog'),
     url(r'', include(wagtail_urls)),
 ]
+
+if settings.DEBUG:
+    from django.conf.urls.static import static
+    from django.contrib.staticfiles.urls import staticfiles_urlpatterns
+
+    # Serve static and media locally
+    urlpatterns += staticfiles_urlpatterns()
+    urlpatterns += static(settings.MEDIA_URL,
+                          document_root=settings.MEDIA_ROOT)


Test patch:
Repository: liqd/a4-meinberlin

Issue:
Validate phase dates when publishing projects



Discussion:

Resolving patch:
diff --git a/apps/dashboard/forms.py b/apps/dashboard/forms.py
--- a/apps/dashboard/forms.py
+++ b/apps/dashboard/forms.py
@@ -1,6 +1,7 @@
 from django import forms
 from django.contrib import messages
 from django.core.exceptions import ObjectDoesNotExist
+from django.core.exceptions import ValidationError
 from django.db.models import loading
 from django.forms import modelformset_factory
 from django.utils.translation import ugettext as _
@@ -333,6 +334,14 @@ class ExternalProjectBaseForm(forms.ModelForm):
     start_date = forms.DateTimeField(required=False)
     end_date = forms.DateTimeField(required=False)
 
+    def clean_end_date(self, *args, **kwargs):
+        start_date = self.cleaned_data['start_date']
+        end_date = self.cleaned_data['end_date']
+        if start_date and end_date and end_date < start_date:
+            raise ValidationError(
+                _('End date can not be smaller than the start date.'))
+        return end_date
+
     class Meta:
         model = extproject_models.ExternalProject
         fields = ['name', 'url', 'description', 'image', 'is_archived']
diff --git a/apps/dashboard/mixins.py b/apps/dashboard/mixins.py
--- a/apps/dashboard/mixins.py
+++ b/apps/dashboard/mixins.py
@@ -54,13 +54,31 @@ def post(self, request, *args, **kwargs):
                 raise PermissionDenied
 
             if request.POST['submit_action'] == 'publish':
-                project.is_draft = False
-                messages.success(request, _('Project successfully published.'))
+                phases = project.phases
+
+                # Assure that every phase has a start and an end date
+                missing_date = False
+                for phase in phases:
+                    if not phase.start_date or not phase.end_date:
+                        missing_date = True
+                        break
+
+                if missing_date:
+                    messages.error(request,
+                                   _('Project can not be published until'
+                                     ' every Phase it contains has start and'
+                                     ' end dates.'))
+                else:
+                    project.is_draft = False
+                    messages.success(request,
+                                     _('Project successfully published.'))
+                    project.save()
+
             elif request.POST['submit_action'] == 'unpublish':
                 project.is_draft = True
                 messages.success(request,
                                  _('Project successfully unpublished.'))
-            project.save()
+                project.save()
 
         return redirect('dashboard-project-list',
                         organisation_slug=self.organisation.slug)


Test patch:
Repository: liqd/a4-meinberlin

Issue:
Order of poll answer choices mixed up after saving
The order of poll answer choices is mixed up after saving. Restoring original order is not possible:
![bildschirmfoto 2017-05-12 um 17 11 59](https://cloud.githubusercontent.com/assets/11075214/26004427/226d3d8c-3736-11e7-8759-ccf91a1e1da8.png)



Discussion:

Resolving patch:
diff --git a/apps/polls/models.py b/apps/polls/models.py
--- a/apps/polls/models.py
+++ b/apps/polls/models.py
@@ -60,6 +60,9 @@ class Choice(models.Model):
 
     objects = ChoiceQuerySet.as_manager()
 
+    class Meta:
+        ordering = ['id']
+
     def __str__(self):
         return '%s @%s' % (self.label, self.question)
 


Test patch:
Repository: liqd/a4-meinberlin

Issue:
Filter archived and draft projects from the wagtail frontpage selection element



Discussion:

Resolving patch:
diff --git a/apps/cms/models.py b/apps/cms/models.py
--- a/apps/cms/models.py
+++ b/apps/cms/models.py
@@ -1,5 +1,6 @@
+from django import forms
 from django.db import models
-from django.forms import widgets
+from django.utils.functional import cached_property
 from modelcluster.fields import ParentalKey
 from modelcluster.models import ClusterableModel
 from wagtail.wagtailadmin import edit_handlers
@@ -30,13 +31,30 @@ class SimplePage(Page):
 
 class ProjectSelectionBlock(blocks.ChooserBlock):
     target_model = Project
-    widget = widgets.Select
+    widget = forms.widgets.Select
+
+    @cached_property
+    def field(self):
+        return forms.ModelChoiceField(
+            queryset=self.target_model.objects.filter(
+                is_draft=False,
+                is_archived=False,
+                is_public=True),
+            widget=self.widget,
+            required=self._required,
+            help_text=self._help_text)
 
     def value_for_form(self, value):
         if isinstance(value, Project):
             return value.pk
         return value
 
+    def value_from_form(self, value):
+        # if project became unavailable (unpublished), selection will become an
+        # empty string and cause a server error on save, so we give a fallback
+        value = value or None
+        return super().value_from_form(value)
+
 
 class ProjectsWrapperBlock(blocks.StructBlock):
     title = blocks.CharBlock(max_length=80)


Test patch:
Repository: liqd/a4-meinberlin

Issue:
link to profile breaks if space in username



Discussion:
Can you give an example? I found an example that works fine; https://meinberlin-stage.liqd.net/profile/Kerstin%20Josupeit/
I could not find any space related issues, but I found a 500 error on a username with umlaut: https://meinberlin-stage.liqd.net/profile/B%C3%A4rlinerin/


Resolving patch:
diff --git a/apps/embed/middleware.py b/apps/embed/middleware.py
--- a/apps/embed/middleware.py
+++ b/apps/embed/middleware.py
@@ -1,3 +1,6 @@
+from django.utils.http import urlquote
+
+
 class AjaxPathMiddleware(object):
     """Append request path as a header.
 
@@ -7,5 +10,5 @@ class AjaxPathMiddleware(object):
     """
 
     def process_response(self, request, response):
-        response['x-ajax-path'] = request.path
+        response['x-ajax-path'] = urlquote(request.path)
         return response


Test patch:
Repository: liqd/a4-meinberlin

Issue:
project list does not show text if there are no matching projects
It should show something like "No projects could be found". Note that the text should work for two cases: "there are no projects" and "there are no projects matching the filters".


Discussion:

Resolving patch:
diff --git a/apps/contrib/templatetags/contrib_tags.py b/apps/contrib/templatetags/contrib_tags.py
--- a/apps/contrib/templatetags/contrib_tags.py
+++ b/apps/contrib/templatetags/contrib_tags.py
@@ -17,3 +17,14 @@ def combined_url_parameter(request_query_dict, **kwargs):
         combined_query_dict.setlist(key, [kwargs[key]])
     encoded_parameter = '?' + combined_query_dict.urlencode()
     return encoded_parameter
+
+
+@register.assignment_tag
+def filter_has_perm(perm, user, objects):
+    """Filter a list of objects based on user permissions."""
+    if not hasattr(user, 'has_perm'):
+        # If the swapped user model does not support permissions, all objects
+        # will be returned. This is taken from rules.templatetags.has_perm.
+        return objects
+    else:
+        return (obj for obj in objects if user.has_perm(perm, obj))


Test patch:
Repository: liqd/a4-meinberlin

Issue:
Login with username
It is currently not possible to login with username, only with email. This *was* possible with the old meinberlin that was based on a3. So the login flow of established users breaks even though we migrated all accounts.


Discussion:

Resolving patch:
diff --git a/meinberlin/settings/base.py b/meinberlin/settings/base.py
--- a/meinberlin/settings/base.py
+++ b/meinberlin/settings/base.py
@@ -218,7 +218,7 @@
 )
 
 ACCOUNT_ADAPTER = 'apps.users.adapters.AccountAdapter'
-ACCOUNT_AUTHENTICATION_METHOD = 'email'
+ACCOUNT_AUTHENTICATION_METHOD = 'username_email'
 ACCOUNT_EMAIL_CONFIRMATION_EXPIRE_DAYS = 3
 ACCOUNT_EMAIL_REQUIRED = True
 ACCOUNT_EMAIL_VERIFICATION = 'mandatory'


Test patch:
Repository: liqd/a4-meinberlin

Issue:
Organisations listed in filter on project overview unsorted
The list of organisations listed in filter on the project overview page is unsorted and determined by the order of creating the organisations. I think it would be best to sort them alphabetically.


Discussion:

Resolving patch:
diff --git a/apps/projects/views.py b/apps/projects/views.py
--- a/apps/projects/views.py
+++ b/apps/projects/views.py
@@ -54,7 +54,8 @@ class TypeWidget(DropdownLinkWidget):
 
     def __init__(self, attrs=None):
         choices = (('', _('Any')),)
-        for blueprint_key, blueprint in blueprints.blueprints:
+        sorted_blueprints = sorted(blueprints.blueprints, key=lambda a: a[1])
+        for blueprint_key, blueprint in sorted_blueprints:
             choices += (blueprint_key, blueprint.title),
         super().__init__(attrs, choices)
 
@@ -74,7 +75,8 @@ class ProjectFilterSet(DefaultsFilterSet):
     )
 
     organisation = django_filters.ModelChoiceFilter(
-        queryset=apps.get_model(settings.A4_ORGANISATIONS_MODEL).objects.all(),
+        queryset=apps.get_model(settings.A4_ORGANISATIONS_MODEL).objects
+                     .order_by('name'),
         widget=OrganisationWidget,
     )
 


Test patch:
Repository: liqd/a4-meinberlin

Issue:
Participated projects visible for all on user profile
If I write a comment on platform meinBerlin and take part in a participation process, everyone can see my profile and in which participation process I took part, even I'm not logged in. It's not anonymous enough.


Discussion:

Resolving patch:
diff --git a/apps/users/views.py b/apps/users/views.py
--- a/apps/users/views.py
+++ b/apps/users/views.py
@@ -1,20 +1,8 @@
 from django.views.generic.detail import DetailView
 
-from adhocracy4.projects.models import Project
-
 from . import models
 
 
 class ProfileView(DetailView):
     model = models.User
     slug_field = 'username'
-
-    @property
-    def get_participated_projects(self):
-        user = self.object
-
-        qs = Project.objects.filter(
-            action__actor=user
-        ).distinct()
-
-        return qs


Test patch: