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

Issue:
Mail for waitlist bumps on payment events gets duplicate first line
The first line in the mail for a waitlist bump on a payment event is added twice. 
Ex: 

> Du har stått på venteliste for arrangementet "Blåtur" og har nå fått plass.
> Du har stått på venteliste for arrangementet "Blåtur" og har nå fått plass.
> Dette arrangementet krever betaling og du må betale innen 2 dager.
> Prisen for dette arrangementet er 100kr.



Discussion:

Resolving patch:
diff --git a/apps/events/utils.py b/apps/events/utils.py
--- a/apps/events/utils.py
+++ b/apps/events/utils.py
@@ -58,7 +58,7 @@ def handle_waitlist_bump(event, host, attendees, payment=None):
     message = 'Du har stått på venteliste for arrangementet "%s" og har nå fått plass.\n' % (str(event.title))
 
     if payment:
-        message += _handle_waitlist_bump_payment(payment, attendees, message)
+        message += _handle_waitlist_bump_payment(payment, attendees)
     else:
         message += "Det kreves ingen ekstra handling fra deg med mindre du vil melde deg av."
 
@@ -69,8 +69,9 @@ def handle_waitlist_bump(event, host, attendees, payment=None):
         send_mail(title, message, settings.DEFAULT_FROM_EMAIL, [attendee.user.email])
 
 
-def _handle_waitlist_bump_payment(payment, attendees, message):
+def _handle_waitlist_bump_payment(payment, attendees):
     extended_deadline = timezone.now() + timedelta(days=2)
+    message = ""
 
     if payment.payment_type == 1:  # Instant
         for attendee in attendees:


Test patch:
Repository: dotkom/onlineweb4

Issue:
attendees_not_paid property is plain wrong
It returns all attendees who have paid instead. It is only used for sending out emails afaik.

https://github.com/dotKom/onlineweb4/blob/2347446f5bb66d202b7adecc9433a8e26fe3b0b4/apps/events/models.py#L450

IMO it should be something like `return list(self.attendees.filter(paid=False))` instead of simply adding a `not`,



Discussion:
https://github.com/dotKom/onlineweb4/commit/7ee69ebc135131eb5742a99ad33ab2f5587ae35d#diff-3310307136147b680a88626a2444fbf8R439

Was this fixed? 

Nope


Resolving patch:
diff --git a/apps/events/models.py b/apps/events/models.py
--- a/apps/events/models.py
+++ b/apps/events/models.py
@@ -449,7 +449,7 @@ def reservees_qs(self):
 
     @property
     def attendees_not_paid(self):
-        return [a for a in self.attendees_qs if a.paid]
+        return list(self.attendees.filter(paid=False))
 
     @property
     def number_of_attendees(self):


Test patch:
Repository: dotkom/onlineweb4

Issue:
Alter event permission text slightly
Could be only me but "Du er ikke i et klassetrinn som har tilgang til dette arrangementet" sounds a bit weird. How about changing them around to "Du er i et klassetrinn som ikke har tilgang til dette arrangementet".

VERY FRIKKIN IMPORTANT PLS FIX



Discussion:
#1735 

I think the current wording is fine. 


Resolving patch:
diff --git a/apps/events/models.py b/apps/events/models.py
--- a/apps/events/models.py
+++ b/apps/events/models.py
@@ -222,7 +222,7 @@ def satisfied(self, user, registration_start):
                 return {"status": True, "message": None, "status_code": 210}
             # If there is no offset, the signup just hasn't started yet
             elif self.offset == 0:
-                return {"status": False, "message": _("Påmeldingen er ikke åpnet enda."), "status_code": 402}
+                return {"status": False, "message": _("Påmeldingen har ikke åpnet enda."), "status_code": 402}
             # In the last case there is a delayed signup
             else:
                 return {"status": False, "message": _("Din studieretning har utsatt påmelding."),
@@ -257,7 +257,7 @@ def satisfied(self, user, registration_start):
                 return {"status": True, "message": None, "status_code": 211}
             # If there is no offset, the signup just hasn't started yet
             elif self.offset == 0:
-                return {"status": False, "message": _("Påmeldingen er ikke åpnet enda."), "status_code": 402}
+                return {"status": False, "message": _("Påmeldingen har ikke åpnet enda."), "status_code": 402}
             # In the last case there is a delayed signup
             else:
                 return {
@@ -265,7 +265,7 @@ def satisfied(self, user, registration_start):
                     _("Ditt klassetrinn har utsatt påmelding."), "offset": offset_datetime, "status_code": 421}
         return {
             "status": False, "message":
-                _("Du er ikke i et klassetrinn som har tilgang til dette arrangementet."), "status_code": 411}
+                _("Ditt klassetrinn har ikke tilgang til dette arrangementet."), "status_code": 411}
 
     def __str__(self):
         if self.offset > 0:
@@ -298,7 +298,7 @@ def satisfied(self, user, registration_start):
                         "offset": offset_datetime, "status_code": 422}
         return {
             "status": False, "message":
-            _("Du er ikke i en brukergruppe som har tilgang til dette arrangmentet."), "status_code": 412}
+            _("Din brukergruppe har ikke tilgang til dette arrangementet."), "status_code": 412}
 
     def __str__(self):
         if self.offset > 0:


Test patch:
Repository: dotkom/onlineweb4

Issue:
Do not fadeout alert error messages
At the moment all error messages to the user fade out after a few seconds.
This is okay for normal alert messages, but errors should stay on the screen. The user can hide them manually if they want.



Discussion:
I suggest we add functionality which will tell if the alert should be automagically dismissed.
- User logging in will trigger alert-success "User successfully logged in", which can be hidden automagically.
- User paying for an event will trigger alert-success "You have successfully paid for this event", which we should let stay on the screen

I'm not sure about the policy we've incorporated for warnings and errors, but we can probably let them stay on the screen without having to worry. 

Since we have alert-success' that we _want_ to auto-dismiss, and we have alert-success' that we _don't want_ to auto-dismiss, I suggest we add conditional in the dismiss-job that checks for a data property which will tell us if the alert should be automagically dismissed and do so, otherwise, don't dismiss it.

To automagically dismiss the alerts we _want_ to dismiss, we have to add the data-property to those events. For anything else, we don't have to do anything. This means we can add the functionality without having to do any refactoring - but rather add the auto-dismiss property on elements at any point in the future.


Resolving patch:
diff --git a/apps/authentication/views.py b/apps/authentication/views.py
--- a/apps/authentication/views.py
+++ b/apps/authentication/views.py
@@ -30,7 +30,7 @@ def login(request):
     if request.method == 'POST':
         form = LoginForm(request.POST)
         if form.login(request):
-            messages.success(request, _('Du er nå logget inn.'))
+            messages.success(request, _('Du er nå logget inn.'), extra_tags='data-dismiss')
             if redirect_url:
                 return HttpResponseRedirect(redirect_url)
             return HttpResponseRedirect('/')
@@ -45,7 +45,7 @@ def login(request):
 
 def logout(request):
     auth.logout(request)
-    messages.success(request, _('Du er nå logget ut.'))
+    messages.success(request, _('Du er nå logget ut.'), extra_tags='data-dismiss')
     return HttpResponseRedirect('/')
 
 
diff --git a/onlineweb4/settings/base.py b/onlineweb4/settings/base.py
--- a/onlineweb4/settings/base.py
+++ b/onlineweb4/settings/base.py
@@ -375,7 +375,7 @@
                 messages.INFO: 'alert-info',
                 messages.SUCCESS: 'alert-success',
                 messages.WARNING: 'alert-warning',
-                messages.ERROR: 'alert-error'}
+                messages.ERROR: 'alert-danger'}
 
 
 # Not really sure what this does.


Test patch:
Repository: dotkom/onlineweb4

Issue:
Show extra warning if trying to attend event where unattend_deadline has passed
If an event has `registration_end` _later_ than `unattend_deadline`, we should show a warning to users who attend that they may NOT unattend the event after they sign up.



Discussion:

Resolving patch:
diff --git a/apps/events/utils.py b/apps/events/utils.py
--- a/apps/events/utils.py
+++ b/apps/events/utils.py
@@ -199,6 +199,7 @@ def handle_attendance_event_detail(event, user, context):
     attendee = False
     place_on_wait_list = 0
     will_be_on_wait_list = False
+    can_unattend = True
     rules = []
     user_status = False
 
@@ -214,6 +215,8 @@ def handle_attendance_event_detail(event, user, context):
 
         will_be_on_wait_list = attendance_event.will_i_be_on_wait_list
 
+        can_unattend = timezone.now() < attendance_event.registration_end
+
         user_status = event.attendance_event.is_eligible_for_signup(user)
 
         # Check if this user is on the waitlist
@@ -226,6 +229,7 @@ def handle_attendance_event_detail(event, user, context):
         'attendee': attendee,
         'user_attending': user_attending,
         'will_be_on_wait_list': will_be_on_wait_list,
+        'can_unattend': can_unattend,
         'rules': rules,
         'user_status': user_status,
         'place_on_wait_list': int(place_on_wait_list),


Test patch:
Repository: dotkom/onlineweb4

Issue:
Send copy of emails to committee when sending emails on behalf of a committee
E.g. when sending an email to all the participants on an event, send a copy to the committee SEND FROM email.



Discussion:

Resolving patch:
diff --git a/apps/events/utils.py b/apps/events/utils.py
--- a/apps/events/utils.py
+++ b/apps/events/utils.py
@@ -347,7 +347,7 @@ def handle_mail_participants(event, _from_email, _to_email_value, subject, _mess
     # Send mail
     try:
         email_addresses = [a.user.get_email().email for a in send_to_users]
-        _email_sent = EmailMessage(str(subject), str(message), from_email, [], email_addresses).send()
+        _email_sent = EmailMessage(str(subject), str(message), from_email, [from_email], email_addresses).send()
         logger.info('Sent mail to %s for event "%s".' % (_to_email_options[_to_email_value][1], event))
         return _email_sent, all_attendees, attendees_on_waitlist, attendees_not_paid
     except ImproperlyConfigured as e:


Test patch:
Repository: dotkom/onlineweb4

Issue:
Posters assign person bug
```
Internal Server Error: /dashboard/posters/assign_person/

ValueError at /dashboard/posters/assign_person/
invalid literal for int() with base 10: '------'
```

I think this happens if you click on the "Assign person" on a poster order, in the available poster orders list, and not select a person. 



Discussion:

Resolving patch:
diff --git a/apps/posters/dashboard/views.py b/apps/posters/dashboard/views.py
--- a/apps/posters/dashboard/views.py
+++ b/apps/posters/dashboard/views.py
@@ -215,23 +215,15 @@ def _handle_poster_add(request, form, order_type):
 def assign_person(request):
     if request.is_ajax():
         if request.method == 'POST':
-            order_id = request.POST.get('order_id')
-            orders = Poster.objects.filter(pk=order_id)
-            assign_to_id = request.POST.get('assign_to_id')
-            assign_to = User.objects.get(pk=assign_to_id)
-
-            if orders.count() == 0:
-                logging.debug("Trying to assign to non-existing order \"%s\" (user: %s)." % (order_id, request.user))
-                response_text = json.dumps({'message': _(
-                    """Kan ikke finne en ordre med denne IDen (%s).
-Om feilen vedvarer etter en refresh, kontakt dotkom@online.ntnu.no.""") % order_id})
-                return HttpResponse(status=412, content=response_text)
-
-            order = orders[0]
+            order = get_object_or_404(Poster, pk=request.POST.get('order_id'))
+            if request.POST.get('assign_to_id') and not str(request.POST.get('assign_to_id')).isnumeric():
+                return HttpResponse(status=400, content=json.dumps(
+                    {'message': 'Denne brukerprofilen kunne ikke tilordnes til ordren.'}))
+            assign_to = get_object_or_404(User, pk=request.POST.get('assign_to_id'))
 
             if order.finished or order.assigned_to is not None:
                 response_text = json.dumps({'message': _("Denne ordren er allerede behandlet.")})
-                return HttpResponse(status=412, content=response_text)
+                return HttpResponse(status=400, content=response_text)
 
             order.assigned_to = assign_to
             order.save()


Test patch:
Repository: dotkom/onlineweb4

Issue:
Unable to remove image from event in dashboard
If an image has been selected for an event there is currently no way to remove the image after saving. 

A shitty workaround is to inspect the hidden input field and set the value to an empty string.


Discussion:
I think this is the case for article and companyprofile too (any other places using images?)

Resolving patch:
diff --git a/apps/gallery/widgets.py b/apps/gallery/widgets.py
--- a/apps/gallery/widgets.py
+++ b/apps/gallery/widgets.py
@@ -15,7 +15,9 @@
 <a href="#" class="btn btn-primary" id="add-responsive-image">\r\n
 <i class="fa fa-plus fa-lg"></i> Velg</a>\r\n
 <a href="{}" class="btn btn-primary" target="_blank">\r\n
-<i class="fa fa-image fa-lg"></i> Last opp</a><br>\r\n
+<i class="fa fa-image fa-lg"></i> Last opp</a>\r\n
+<a href="#" class="btn btn-danger" id="dashboard-gallery-remove-image">\r\n
+<i class="fa fa-times fa-lg"></i> Fjern bilde</a><br>\r\n
 <div id="image-selection-wrapper">\r\n
 <h2 id="image-selection-title">Velg bilde</h2>\r\n
 <div class="row">\r\n


Test patch:
Repository: dotkom/onlineweb4

Issue:
Consider adding Sentry + Raven
Should we fire up [Sentry](https://getsentry.com) with [Raven](https://pypi.python.org/pypi/raven) (python client for Sentry) for teh lulz?

It looks kinda nice.



Discussion:
Looks neat. What about pricing though? If I'm not mistaken, there's no free option for us as a non-profit here. Don't get me wrong, I do love me some lulz, but is it worth spending any amount of time on setting it up if we can't keep it?
EDIT: I suppose after the free trial, you do get downgraded to a free plan of sorts, but it seems fairly limited.

> When your trial expires we'll downgrade you to our free tier. Our free tier is limited to a single user and 250 events per day.

> I suppose after the free trial, you do get downgraded to a free plan of sorts, but it seems fairly limited.

Closing since it is not interesting if it costs :dollar: 

Got it for free for nonprofits, reopening.

Resolving patch:
diff --git a/onlineweb4/settings/base.py b/onlineweb4/settings/base.py
--- a/onlineweb4/settings/base.py
+++ b/onlineweb4/settings/base.py
@@ -232,6 +232,7 @@
     'datetimewidget',
     'webpack_loader',
     'oidc_provider',
+    'raven.contrib.django.raven_compat',  # Sentry, error tracking
 
     # Django apps
     'django.contrib.admin',
@@ -331,6 +332,10 @@
             'level': 'DEBUG',
             'class': 'logging.StreamHandler',
             'formatter': 'standard'
+        },
+        'sentry': {
+            'level': 'ERROR',  # Decides what is sent to Sentry. Error is only error and above.
+            'class': 'raven.contrib.django.raven_compat.handlers.SentryHandler',
         }
     },
     'loggers': {
@@ -353,6 +358,11 @@
             'level': 'DEBUG',
             'propagate': True,
         },
+        'raven': {
+            'level': 'DEBUG',
+            'handlers': ['console'],
+            'propagate': False,
+        },
         '': {
             'handlers': ['console'],
             'level': 'DEBUG',
@@ -507,7 +517,7 @@
 }
 
 # Remember to keep 'local' last, so it can override any setting.
-for settings_module in ['filebrowser', 'django_wiki', 'local']:  # local last
+for settings_module in ['filebrowser', 'django_wiki',  'raven', 'local']:  # local last
     if not os.path.exists(os.path.join(PROJECT_SETTINGS_DIRECTORY,
             settings_module + ".py")):
         if settings_module == 'local':
diff --git a/onlineweb4/settings/raven.py b/onlineweb4/settings/raven.py
new file mode 100644
--- /dev/null
+++ b/onlineweb4/settings/raven.py
@@ -0,0 +1,11 @@
+import os
+import raven
+
+from decouple import config
+
+RAVEN_CONFIG = {
+    'dsn': config('OW4_RAVEN_DSN', default='https://user:pass@sentry.io/project'),
+    'environment': config('OW4_ENVIRONMENT', default='DEVELOP'),
+    # Use git to determine release
+    'release': raven.fetch_git_sha(os.path.dirname(os.pardir)),
+}


Test patch:
Repository: dotkom/onlineweb4

Issue:
Cannot view inventory
## What kind of an issue is this?

- [x] Bug report


## What is the expected behaviour?

To be able to view the inventory

## What is the current behaviour?

A 500 error, with the message `TypeError: '>=' not supported between instances of 'datetime.date' and 'NoneType'`. 


## How do you reproduce this problem? 

Make sure the inventory is not empty, and try to visit it.


Discussion:
https://sentry.io/dotkom/onlineweb-4/issues/345689413/

Resolving patch:
diff --git a/apps/inventory/models.py b/apps/inventory/models.py
--- a/apps/inventory/models.py
+++ b/apps/inventory/models.py
@@ -55,7 +55,7 @@ def total_amount(self):
 
     @property
     def has_expired_batch(self):
-        if timezone.now().date() >= self.oldest_expiration_date:
+        if self.oldest_expiration_date and timezone.now().date() >= self.oldest_expiration_date:
             return True
         return False
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
G Suite group syncer does not respect group syncer whitelist
## What kind of an issue is this?

- [x] Bug report

## What is the expected behaviour?

If a group is not in the OW4_GSUITE_SETTINGS groups list, it should not be affected by changes to the group.

## What is the current behaviour?

If a group membership is changed, the group is synced, and people will be removed from the group if not using their online mail.


## How do you reproduce this problem? 

Add or remove a person to a group not set up for G Suite syncing (in settings)



Discussion:

Resolving patch:
diff --git a/apps/gsuite/mail_syncer/main.py b/apps/gsuite/mail_syncer/main.py
--- a/apps/gsuite/mail_syncer/main.py
+++ b/apps/gsuite/mail_syncer/main.py
@@ -1,5 +1,7 @@
 import logging
 
+from django.conf import settings
+
 from apps.gsuite.mail_syncer.utils import (get_excess_groups_for_user, get_excess_users_in_g_suite,
                                            get_g_suite_users_for_group,
                                            get_missing_g_suite_group_names_for_user,
@@ -107,6 +109,12 @@ def update_g_suite_group(domain, group_name, suppress_http_errors=False):
     :param suppress_http_errors: Whether or not to suppress HttpErrors happening during execution.
     :type suppress_http_errors: bool
     """
+
+    if group_name.lower() not in settings.OW4_GSUITE_SYNC.get('GROUPS', {}).keys():
+        logger.debug('Not running group syncer for group {} - group syncing not enabled for this group'
+                     .format(group_name))
+        return
+
     g_suite_users = get_g_suite_users_for_group(domain, group_name, suppress_http_errors=suppress_http_errors)
     ow4_users = get_ow4_users_for_group(group_name)
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
PaymentPrice description is not required by manager but required for __str__
## What kind of an issue is this?

- [x] Bug report


## What is the expected behaviour?

That you can create a PaymentPrice by following the guidelines, which are a required price and an optional description.

## What is the current behaviour?

By creating a PaymentPrice with a required price but no description the system fails with the error message

```
TypeError at /admin/payment/payment/add/
unsupported operand type(s) for +: 'NoneType' and 'str'
```


## How do you reproduce this problem? 

* Create an event with an attached attendance
* Navigate to /admin/payment/payment/add/
* Add a payment to the attendance event you created, without a description (but with a price)
* The system crashes with the error message `unsupported operand type(s) for +: 'NoneType' and 'str'`



Discussion:

Resolving patch:
diff --git a/apps/payment/models.py b/apps/payment/models.py
--- a/apps/payment/models.py
+++ b/apps/payment/models.py
@@ -175,6 +175,8 @@ class PaymentPrice(models.Model):
     description = models.CharField(max_length=128, null=True, blank=True)
 
     def __str__(self):
+        if not self.description:
+            return str(self.price) + "kr"
         return self.description + " (" + str(self.price) + "kr)"
 
     class Meta(object):


Test patch:
Repository: dotkom/onlineweb4

Issue:
SSO base template should extend the base template
## What kind of an issue is this?

- [x] Bug report


## What is the expected behaviour?

The template for the SSO app should extend the base template so we don't have to maintain multiple base templates.


## What is the current behaviour?

It's a custom template, which looks copy/pasted from the base template.



Discussion:

Resolving patch:
diff --git a/apps/sso/views.py b/apps/sso/views.py
--- a/apps/sso/views.py
+++ b/apps/sso/views.py
@@ -18,7 +18,7 @@ def index(request):
 
     context = {}
 
-    return render(request, 'sso/index.html', context)
+    return render(request, 'sso/authorize.html', context)
 
 
 class AuthorizationView(DefaultAuthorizationView):


Test patch:
Repository: dotkom/onlineweb4

Issue:
Webshop send too many mails when something is purchased
## What kind of an issue is this?

- [x] Bug report
- [ ] Feature request


## What is the expected behavior?
Webshop should only send one receipt.

## What is the current behavior?
When buying something in the Webshop, there are sent 4 receipts.
First receipt is sent before the purchase is completed, and does not contain any purchased items.
The three remaining receipts are all for the same purchased product(s), all with their own unique ID.

## How do you reproduce this problem? 
 - Buy a 'Planet Online-genser' in the Webshop.
 - Wait for incoming mail.



Discussion:

Resolving patch:
diff --git a/apps/payment/views.py b/apps/payment/views.py
--- a/apps/payment/views.py
+++ b/apps/payment/views.py
@@ -140,9 +140,6 @@ def webshop_pay(request):
                 order_line.stripe_id = charge.id
                 order_line.save()
 
-                receipt = PaymentReceipt(object_id=order_line.id,
-                                         content_type=ContentType.objects.get_for_model(order_line))
-                receipt.save()
                 messages.success(request, "Betaling utført")
 
                 return HttpResponse("Betaling utført.", content_type="text/plain", status=200)
diff --git a/apps/webshop/models.py b/apps/webshop/models.py
--- a/apps/webshop/models.py
+++ b/apps/webshop/models.py
@@ -234,6 +234,7 @@ def pay(self):
         self.paid = True
         self.datetime = timezone.now()
         self.save()
+        self.send_receipt()
 
     def get_timestamp(self):
         return self.datetime
@@ -262,8 +263,7 @@ def get_from_mail(self):
     def get_to_mail(self):
         return self.user.email
 
-    def save(self, *args, **kwargs):
-        super(OrderLine, self).save(*args, **kwargs)
+    def send_receipt(self):
         receipt = PaymentReceipt(object_id=self.id,
                                  content_type=ContentType.objects.get_for_model(self))
         receipt.save()


Test patch: