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

Issue:
Users should be able to edit expired 'careeropportunity' from Dashboard
## What kind of an issue is this?
- Feature request

## What is the expected behaviour?

You should be able to click to edit from the list of expired careeropportunities in the Dashboard.

## Other information

This was requested by one of our users on email.



Discussion:

Resolving patch:
diff --git a/apps/careeropportunity/dashboard/views.py b/apps/careeropportunity/dashboard/views.py
--- a/apps/careeropportunity/dashboard/views.py
+++ b/apps/careeropportunity/dashboard/views.py
@@ -27,7 +27,7 @@ def index(request):
     cops = CareerOpportunity.objects.all()
     context['cops'] = cops.filter(end__gte=timezone.now()).order_by('end')
     context['archive'] = cops.filter(end__lte=timezone.now()).order_by('-id')
-
+    context['all'] = cops
     return render(request, 'careeropportunity/dashboard/index.html', context)
 
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Updating "My profile" does not save all profile fields
## What kind of an issue is this?

- [x] Bug report
- [ ] Feature request


## What is the expected behaviour?
Seeing my post number at my [profile overview page](https://online.ntnu.no/profile/overview/)


## What is the current behaviour?
Seeing `None Ugyldig postnummer` at my [profile overview page](https://online.ntnu.no/profile/overview/)

<!-- if this is a bug report -->


## How do you reproduce this problem? 

- Go to the [profile edit page](https://online.ntnu.no/profile/edit/), write `7050` (or another post number) into the _Postnummer_ field
- Press _Lagre brukerinformasjon_. No visible errors on page or in browser console, green status box at the top says _"Brukerprofilen din ble endret"_
- Go to the [profile overview page](https://online.ntnu.no/profile/overview/), look for the _Adresse_. You should now see `None Ugyldig postnummer`.

<!-- if this is a bug report -->
<!-- provide steps to reproduce this problem, preferably in a bullet point list -->


## Other information

<!-- include screenshots if appropriate -->
<!-- add labels you see fit. please do not exaggerate. -->
### Screenshots
[Profile edit page:](https://online.ntnu.no/profile/edit/)
![image](https://user-images.githubusercontent.com/12127271/32372177-150971b4-c094-11e7-8a05-01eee0603e30.png)
[Profile overview page:](https://online.ntnu.no/profile/overview/)
![image](https://user-images.githubusercontent.com/12127271/32372269-6b2cfdea-c094-11e7-9b39-a459a86451dd.png)




Discussion:
I suggest you move to a place with a valid zip code.
Okay, the issue has been identified and we'll fix it.

The problem is that the `post_code` field in the "My profile"-form is not stored when the form is submitted.

We should also verify that all other fields are stored.

Resolving patch:
diff --git a/apps/profiles/forms.py b/apps/profiles/forms.py
--- a/apps/profiles/forms.py
+++ b/apps/profiles/forms.py
@@ -37,9 +37,11 @@ class Meta(object):
 
     def clean_zip_code(self):
         zip_code = self.cleaned_data['zip_code']
-        if zip_code and len(zip_code) != 0 and not re.match(r'\d{4}', zip_code):
+        if not zip_code or not re.match(r'^\d{4}$', zip_code):
             self.add_error('zip_code', ZIP_CODE_VALIDATION_ERROR)
 
+        return zip_code
+
 
 class PrivacyForm(forms.ModelForm):
     class Meta(object):


Test patch:
Repository: dotkom/onlineweb4

Issue:
It's not possible to delete event relations in django admin
## What kind of an issue is this?

- [x] Bug report


## What is the expected behaviour?

When you mark an event relation for deletion it should be deleted when you save the object.

## What is the current behaviour?

The object is saved, but the relation is not removed.


## How do you reproduce this problem? 

* Create an event
* Add a relation (e.g. Company or Attendance)
* Save
* Go to the admin panel for the event
* Mark the relation for deletion (click the delete checkbox by the relation)
* Save
* The relation is still there


## Other information

This is most likely due to us overwriting the `save_formset()` method in EventAdmin[0] and not taking care of deleting objects marked for deleting in the formset [1].

We're not doing anything custom in the method, so there's really no reason to override it. The code could actually be removed.

[0]: https://github.com/dotkom/onlineweb4/blob/develop/apps/events/admin.py#L160
[1]: https://docs.djangoproject.com/en/1.11/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_formset


Discussion:

Resolving patch:
diff --git a/apps/events/admin.py b/apps/events/admin.py
--- a/apps/events/admin.py
+++ b/apps/events/admin.py
@@ -151,12 +151,6 @@ def save_model(self, request, obj, form, change):
             obj.author = request.user
         obj.save()
 
-    def save_formset(self, request, form, formset, change):
-        instances = formset.save(commit=False)
-        for instance in instances:
-            instance.save()
-        formset.save_m2m()
-
 
 class ReserveeInline(admin.TabularInline):
     model = Reservee


Test patch:
Repository: dotkom/onlineweb4

Issue:
Events with several companies tied to them and no event image breaks carousel in events archive
![](http://i.imgur.com/E2UiTim.png)

https://github.com/dotKom/onlineweb4/blob/develop/files/static/js/EventWidget.js#L97

All company thumbnails will be marked as active which makes them all show. 
This should be changed to only mark the first one as active. 



Discussion:
Also applies to the archive, but is slightly less critical. 

![screenshot from 2015-05-20 13 21 33](https://cloud.githubusercontent.com/assets/1758308/7724610/43d2dc02-fef3-11e4-99b6-4ee08e4129ca.png)

Is this fixed?

@OptimusCrime: I did you the favor of checking prod. No, it's not fixed.

It is fixed in the frontpage-react branch though. But the problem will remain in the events archive pave


Resolving patch:
diff --git a/apps/events/templatetags/shuffle.py b/apps/events/templatetags/shuffle.py
new file mode 100644
--- /dev/null
+++ b/apps/events/templatetags/shuffle.py
@@ -0,0 +1,10 @@
+import random
+from django import template
+
+register = template.Library()
+
+@register.filter
+def shuffle(arg):
+    li = list(arg)
+    random.shuffle(li)
+    return li


Test patch:
Repository: dotkom/onlineweb4

Issue:
Payment deadlines in dashboard/attendee-list
## What kind of an issue is this?

- [ ] Bug report
- [x] Feature request


## What is the expected behaviour?
There should be a field in dashboard-event-attendees where you can see the payment deadline.

## What is the current behaviour?

<!-- if this is a bug report -->


## How do you reproduce this problem? 

<!-- if this is a bug report -->
<!-- provide steps to reproduce this problem, preferably in a bullet point list -->


## Other information
This would be useful information for arrkom when payment is postponed xx days. 

You can find the deadline in the paymentrelation-model.



<!-- include screenshots if appr opriate -->
<!-- add labels you see fit. please do not exaggerate. -->


Discussion:

Resolving patch:
diff --git a/apps/events/models.py b/apps/events/models.py
--- a/apps/events/models.py
+++ b/apps/events/models.py
@@ -864,6 +864,15 @@ def delete(self):
 
         super(Attendee, self).delete()
 
+    def get_payment_deadline(self):
+        # Importing here to prevent circular dependencies
+        from apps.payment.models import PaymentDelay
+        try:
+            deadline = PaymentDelay.objects.filter(user=self.user, payment=self.event.payment())[0].valid_to
+        except PaymentDelay.DoesNotExist:
+            return
+        return deadline
+
     def is_on_waitlist(self):
         return self in self.event.waitlist_qs
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Membership application uses email object instead of email-address
Same as #2219

https://sentry.io/organizations/dotkom/issues/890887549/?project=204971&referrer=github_plugin

```
TypeError: object of type 'Email' has no len()
(16 additional frame(s) were not displayed)
...
  File "guardian/decorators.py", line 126, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "apps/approval/dashboard/views.py", line 105, in approve_application
    app.save()
  File "apps/approval/signals.py", line 50, in notify_membership_applicant_handler
    send_approval_status_update(instance)
  File "apps/approval/tasks.py", line 45, in send_approval_status_update
    [approval.applicant.get_email()],

TypeError: object of type 'Email' has no len()
```
Membership application uses email object instead of email-address
Same as #2219

https://sentry.io/organizations/dotkom/issues/890887549/?project=204971&referrer=github_plugin

```
TypeError: object of type 'Email' has no len()
(16 additional frame(s) were not displayed)
...
  File "guardian/decorators.py", line 126, in _wrapped_view
    return view_func(request, *args, **kwargs)
  File "apps/approval/dashboard/views.py", line 105, in approve_application
    app.save()
  File "apps/approval/signals.py", line 50, in notify_membership_applicant_handler
    send_approval_status_update(instance)
  File "apps/approval/tasks.py", line 45, in send_approval_status_update
    [approval.applicant.get_email()],

TypeError: object of type 'Email' has no len()
```


Discussion:

Resolving patch:
diff --git a/apps/approval/signals.py b/apps/approval/signals.py
--- a/apps/approval/signals.py
+++ b/apps/approval/signals.py
@@ -55,4 +55,4 @@ def notify_new_committee_application(sender, instance, created, **kwargs):
     if created:
         send_committee_application_notification(instance, [settings.EMAIL_OPPTAK], link_to_admin=True)
         if settings.APPROVAL_SETTINGS.get('SEND_COMMITTEEAPPLICATION_APPLICANT_EMAIL', False):
-            send_committee_application_notification(instance, [instance.get_email()], link_to_admin=False)
+            send_committee_application_notification(instance, [instance.get_email().email], link_to_admin=False)
diff --git a/apps/approval/tasks.py b/apps/approval/tasks.py
--- a/apps/approval/tasks.py
+++ b/apps/approval/tasks.py
@@ -42,7 +42,7 @@ def send_approval_status_update(approval):
         EmailMessage("Soknad om medlemskap i Online er vurdert",
                      message,
                      settings.DEFAULT_FROM_EMAIL,
-                     [approval.applicant.get_email()],
+                     [approval.applicant.get_email().email],
                      ).send()
     except ImproperlyConfigured:
         logger.warn('Failed to notify applicant about updated status on membership for approval#{pk}.'.format(


Test patch:
Repository: dotkom/onlineweb4

Issue:
Expand allergies to include diet
**Describe the bug**
Right now, we only describe "allergier" in the user profile field for allergies and food preferences. We'd like to expand this to include vegetarian and vegan options. The label could sound something like "Allergier / Ideologiske preferanser (f.eks. vegetar)"


Discussion:
Can this also be expanded to highlight that it is *food* allergies/preferences?

Alternatively splitting it into two fields: one for food allergies and one for other allergies.

We experience people writing allergies such as "dust" or "cats" which is not relevant for the committees using this information, and honestly annoying to filter through (both other legit allergies and bullshit...) when sending a list of allergies to restaurants etc. 

Resolving patch:
diff --git a/apps/authentication/migrations/0041_auto_20190911_2238.py b/apps/authentication/migrations/0041_auto_20190911_2238.py
new file mode 100644
--- /dev/null
+++ b/apps/authentication/migrations/0041_auto_20190911_2238.py
@@ -0,0 +1,18 @@
+# Generated by Django 2.1.11 on 2019-09-11 20:38
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('authentication', '0040_auto_20190801_2200'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='onlineuser',
+            name='allergies',
+            field=models.TextField(blank=True, null=True, verbose_name='matallergier/preferanser'),
+        ),
+    ]
diff --git a/apps/authentication/models.py b/apps/authentication/models.py
--- a/apps/authentication/models.py
+++ b/apps/authentication/models.py
@@ -122,7 +122,7 @@ class OnlineUser(AbstractUser):
     zip_code = models.CharField(_("postnummer"), max_length=4, blank=True, null=True)
 
     # Other
-    allergies = models.TextField(_("allergier"), blank=True, null=True)
+    allergies = models.TextField(_("matallergier/preferanser"), blank=True, null=True)
     mark_rules = models.BooleanField(_("godtatt prikkeregler"), default=False)
     rfid = models.CharField(_("RFID"), max_length=50, unique=True, blank=True, null=True, validators=[validate_rfid])
     nickname = models.CharField(_("nickname"), max_length=50, blank=True, null=True)


Test patch:
Repository: dotkom/onlineweb4

Issue:
OW doesnt support use of employee mails
**Describe the bug**
Apperantly OW4 doesnt support use of employee mails, which means the user has issues with verifying their membership if their main email is their employee mail

**Expected behavior**
An user should be able to verify their membership and use OW as long as they are a student too.



Discussion:
Student name is automatically retrieved from Feide, and on employees, it is set to "firstname.lastname". 
Seemingly, by changing adding  
`userid-feide` to scope in `apps/dataporten/settings.py` we can get the correct username
https://github.com/dotkom/onlineweb4/blob/develop/apps/dataporten/views.py
`ntnu_username_dataporten = userinfo.get('email').split('@')[0]`
I believe this needs to be changed after adding the `userid-feide` scope to not get email, but rather the approriate field.

Resolving patch:
diff --git a/apps/dataporten/settings.py b/apps/dataporten/settings.py
--- a/apps/dataporten/settings.py
+++ b/apps/dataporten/settings.py
@@ -8,6 +8,6 @@
         'CLIENT_SECRET': config('OW4_DP_STUDY_CLIENT_SECRET', default=''),
         'REDIRECT_URI': config('OW4_DP_STUDY_REDIRECT_URI', default=''),
         'PROVIDER_URL': 'https://auth.dataporten.no/oauth/token',
-        'SCOPES': ['openid', 'userid', 'profile', 'groups', 'email'],
+        'SCOPES': ['openid', 'userid-feide', 'profile', 'groups', 'email'],
     }
 }
diff --git a/apps/dataporten/views.py b/apps/dataporten/views.py
--- a/apps/dataporten/views.py
+++ b/apps/dataporten/views.py
@@ -102,7 +102,8 @@ def study_callback(request):
 
     # Do user info request
     userinfo = client.do_user_info_request(state=auth_resp['state'], behavior='use_authorization_header')
-    ntnu_username_dataporten = userinfo.get('email').split('@')[0]
+    # connect-userid_sec format is array with "feide:username@ntnu.no"
+    ntnu_username_dataporten = userinfo.get('connect-userid_sec')[0].split(':')[1].split('@')[0]
     if request.user.ntnu_username and request.user.ntnu_username != ntnu_username_dataporten:
         logger.warning(
             '{} tried to authorize, but the registered ntnu_username and the one received from Dataporten differ.'


Test patch:
Repository: dotkom/onlineweb4

Issue:
Atendee list bug when adding or removing users
<!-- If this is a security issue or information leakage (having access to something you (probably) shouldn't), please send an email rather than opening a public issue. -->

## What kind of an issue is this?

- Bug report


## What is the expected behaviour?
It should look normal where every box and number is under its corresponding column. It should just look normal. Even if we remove users or add users through the dashboard, nothing should change.

![screenshot from 2018-09-25 21-07-06](https://user-images.githubusercontent.com/41551253/46037365-3b160c80-c108-11e8-9de5-91ef62505aeb.png)


## What is the current behaviour?
If you remove or add a user through the dashboard menu at the attendee list it will look like the screenshot above. We have randomly two boxes, the x for removing users is all the way to the right and the text "none" is occupying the remove column. If you refresh the site it will go back to expected behaviour, its only after deleteing/adding a user

![screenshot from 2018-09-25 20-00-23](https://user-images.githubusercontent.com/41551253/46037343-29346980-c108-11e8-99e1-c69b77695d3e.png)
<!-- if this is a bug report -->


## How do you reproduce this problem? 
Remove or add a user to the attendee list manually.
<!-- if this is a bug report -->
<!-- provide steps to reproduce this problem, preferably in a bullet point list -->
1. go to the attendee list
2. Add a user by writing their name OR remove a user from the list
## Other information

This might be a bug which I didn't catch when I added "year of study" to the attendee list. I'm not sure if this was an issue before, but since it hasn't been brought up I will assume this is a bug from that pull request of mine


Discussion:

Resolving patch:
diff --git a/apps/events/dashboard/utils.py b/apps/events/dashboard/utils.py
--- a/apps/events/dashboard/utils.py
+++ b/apps/events/dashboard/utils.py
@@ -65,7 +65,9 @@ def _get_attendee_data(attendee_qs):
             'id': a.id,
             'first_name': a.user.first_name,
             'last_name': a.user.last_name,
+            'year_of_study': a.user.year,
             'paid': a.paid,
+            'payment_deadline': a.get_payment_deadline(),
             'extras': str(a.extras),
             'attended': a.attended,
             'link': reverse('dashboard_attendee_details', kwargs={'attendee_id': a.id})
@@ -77,6 +79,8 @@ def _get_attendee_data(attendee_qs):
 def _get_event_context(event: Event, response={}):
     response['attendees'] = _get_attendee_data(event.attendance_event.attending_attendees_qs)
     response['waitlist'] = _get_attendee_data(event.attendance_event.waitlist_qs)
+    response['is_payment_event'] = bool(event.attendance_event.payment())
+    response['has_extras'] = event.attendance_event.has_extras
 
     return response
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Show if inventory item is available in nibble shop in product listing
## What kind of an issue is this?

- [x] Feature request


## What is the expected behaviour?

There should be an icon in the dashboard product listing page that shows if an item is available for sale in Nibble.

This icon should also be clickable, to toggle whether or not the item should be available for sale in Nibble.

It should be possible to sort the items in the table according to the "available for sale"-state.


## Other information

This is how an event's attendee list looks, and it could probably be done in the same way (look at the rightmost column): 
![screenshot 2017-02-27 17 05 03](https://cloud.githubusercontent.com/assets/5422571/23368846/7f1a2600-fd0f-11e6-9499-7afeedf65f76.png)

This is to be done in this list:
![screenshot 2017-02-27 17 05 47](https://cloud.githubusercontent.com/assets/5422571/23368830/72016b18-fd0f-11e6-98f0-485ccebe14c7.png)



Discussion:
Solved in part by #2118 
But should add the rest of the requested functionality.

@R33an1 Didn't you start working on this?
Yes, however I was not able to add any more functionality than what was already done by #2118.

Resolving patch:
diff --git a/apps/inventory/dashboard/urls.py b/apps/inventory/dashboard/urls.py
--- a/apps/inventory/dashboard/urls.py
+++ b/apps/inventory/dashboard/urls.py
@@ -17,6 +17,7 @@
     url(r'^new/$', views.new, name='dashboard_inventory_new'),
     url(r'^item/(?P<item_pk>\d+)/$', views.details, name='dashboard_inventory_details'),
     url(r'^item/(?P<item_pk>\d+)/delete/$', views.item_delete, name='dashboard_inventory_delete'),
+    url(r'^item/(?P<item_pk>\d+)/change/$', views.item_change_availability, name='dashboard_inventory_change'),
     url(r'^item/(?P<item_pk>\d+)/batch/new/$', views.batch_new, name='dashboard_inventory_batch_new'),
     url(r'^item/(?P<item_pk>\d+)/batch/(?P<batch_pk>\d+)/$', views.batch, name='dashboard_inventory_batch'),
     url(r'^item/(?P<item_pk>\d+)/batch/(?P<batch_pk>\d+)/delete/$',
diff --git a/apps/inventory/dashboard/views.py b/apps/inventory/dashboard/views.py
--- a/apps/inventory/dashboard/views.py
+++ b/apps/inventory/dashboard/views.py
@@ -115,6 +115,23 @@ def item_delete(request, item_pk):
     raise PermissionDenied
 
 
+@login_required
+@permission_required('inventory.change_item', return_403=True)
+def item_change_availability(request, item_pk):
+    if not has_access(request):
+        raise PermissionDenied
+
+    item = get_object_or_404(Item, pk=item_pk)
+
+    # AJAX
+    if request.method == 'POST':
+        if request.is_ajax and 'action' in request.POST:
+            item.available = not item.available
+            item.save()
+
+            return JsonResponse({'message': 'OK', 'status': 200})
+
+
 @login_required
 @permission_required('inventory.add_batch', return_403=True)
 def batch_new(request, item_pk):


Test patch:
Repository: dotkom/onlineweb4

Issue:
Unexpected form parameter when creating new poster 
As reported by sentry:

```
Internal Server Error: /admin/posters/poster/

FieldError at /admin/posters/poster/
Cannot resolve keyword 'category' into field.
```

As reported: `reason = 'Jeg søkte etter 2 og fant 500 i stedet'`

Presume this is due to a form POSTing a field param that's not accounted for. Should be a quick and easy fix. 


Discussion:
Poster order creation is supposed to be done through the dashboard, the
admin part is simply nice to have. (or would be, if it worked)

On Tue, Oct 23, 2018, 09:43 Fredrik August Madsen-Malmo <
notifications@github.com> wrote:

> As reported by sentry:
>
> Internal Server Error: /admin/posters/poster/
>
> FieldError at /admin/posters/poster/
> Cannot resolve keyword 'category' into field.
>
> As reported: reason = 'Jeg søkte etter 2 og fant 500 i stedet'
>
> Presume this is due to a form POSTing a field param that's not accounted
> for. Should be a quick and easy fix.
>
> —
> You are receiving this because you are subscribed to this thread.
> Reply to this email directly, view it on GitHub
> <https://github.com/dotkom/onlineweb4/issues/2154>, or mute the thread
> <https://github.com/notifications/unsubscribe-auth/AFK962VV8miCNeSKFfcAUV-BO9nVsCWgks5unsiNgaJpZM4X055U>
> .
>


Resolving patch:
diff --git a/apps/posters/admin.py b/apps/posters/admin.py
--- a/apps/posters/admin.py
+++ b/apps/posters/admin.py
@@ -2,9 +2,10 @@
 from django.utils.translation import ugettext as _
 from reversion.admin import VersionAdmin
 
-from apps.posters.models import Poster
+from .models import Poster
 
 
+@admin.register(Poster)
 class PosterAdmin(VersionAdmin):
     model = Poster
     list_display = ('event', 'title', 'assigned_to', 'display_from',
@@ -14,8 +15,5 @@ class PosterAdmin(VersionAdmin):
         (_('Order info'), {'fields': ('amount',)}),
         (_('proKom'), {'fields': ('display_from', 'assigned_to', 'ordered_by', 'ordered_committee', 'finished')}),
     )
-    search_fields = ('title', 'category', 'company', 'when')
-
-
-admin.site.register(Poster, PosterAdmin)
-# username, expiration_date, registered, note
+    search_fields = ('title', 'event__title', 'assigned_to__first_name', 'assigned_to__last_name',
+                     'ordered_by__first_name', 'ordered_by__last_name')


Test patch: