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

Issue:
Create genfors admin panel list of eligible voters that has not cast a vote yet
This would only be active if the voting is non-anonymous.  Otherwise there would be a link with the anonvoter objects, and the last incoming vote result would be linked to the user, thus revealing their vote.



Discussion:

Resolving patch:
diff --git a/apps/genfors/views.py b/apps/genfors/views.py
--- a/apps/genfors/views.py
+++ b/apps/genfors/views.py
@@ -94,13 +94,20 @@ def admin(request):
             aq = meeting.get_active_question()
             a = anonymous_voter(request.COOKIES.get('anon_voter'), request.user.username)
             r = RegisteredVoter.objects.filter(user=request.user, meeting=meeting).first()
-            v = a if aq.anonymous else r
+            if aq:
+                context['not_voted'] = None
+                v = a if aq.anonymous else r
+                context['already_voted'] = aq.already_voted(v)
+                not_voted = []
+                for person in meeting.get_can_vote():
+                    if not aq.already_voted(person):
+                        not_voted.append(person)
+                context['not_voted'] = not_voted
 
             context['meeting'] = meeting
-            context['question'] = meeting.get_active_question()
+            context['question'] = aq
             context['questions'] = meeting.get_locked_questions()
             context['pin_code'] = meeting.get_pin_code()
-            context['already_voted'] = aq.already_voted(v)
         elif request.method == 'POST':
             form = MeetingForm(request.POST)
             context['form'] = form


Test patch:
Repository: dotkom/onlineweb4

Issue:
Users applying for membership changes with field of study gets expiredate in the past
If you apply for membership today with a Bachelor started in 2011, you will get an expiry date of 2014-09-16.

The given expiration date for a membership should be adjusted upward if the suggested duration of a field of study puts this date in the past.



Discussion:

Resolving patch:
diff --git a/apps/approval/views.py b/apps/approval/views.py
--- a/apps/approval/views.py
+++ b/apps/approval/views.py
@@ -6,6 +6,7 @@
 from django.contrib.auth.decorators import login_required
 from django.http import Http404
 from django.shortcuts import get_object_or_404, redirect
+from django.utils import timezone
 from django.utils.translation import ugettext as _
 
 from apps.approval.forms import FieldOfStudyApplicationForm
@@ -59,9 +60,7 @@ def create_fos_application(request):
 
             length_of_fos = get_length_of_field_of_study(field_of_study)
             if length_of_fos > 0:
-                # Expiry dates should be 15th September, so that we have tiem to get new lists from NTNU
-                application.new_expiry_date = datetime.date(
-                    started_year, 9, 16) + datetime.timedelta(days=365*length_of_fos)
+                application.new_expiry_date = get_expiry_date(started_year, length_of_fos)
             application.save()
 
             messages.success(request, _("Søknad om bytte av studieretning er sendt."))
@@ -70,6 +69,21 @@ def create_fos_application(request):
     raise Http404
 
 
+def get_expiry_date(started_year, length_of_fos):
+    today = timezone.now().date()
+    # Expiry dates should be 15th September, so that we have time to get new lists from NTNU
+    new_expiry_date = datetime.date(
+        started_year, 9, 16) + datetime.timedelta(days=365*length_of_fos)
+    # Expiry dates in the past sets the expiry date to next september
+    if new_expiry_date < today:
+        if today < datetime.date(today.year, 9, 15):
+            new_expiry_date = datetime.date(today.year, 9, 15)
+        else:
+            new_expiry_date = datetime.date(
+                today.year, 9, 16) + datetime.timedelta(days=365)
+    return new_expiry_date
+
+
 @login_required
 def create_membership_application(request):
     if request.method == 'POST':


Test patch:
Repository: dotkom/onlineweb4

Issue:
Show price on event before attending



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
@@ -136,6 +136,10 @@ def check_refund(self, payment_relation):
     def prices(self):
         return self.paymentprice_set.all()
 
+    def price(self):
+        # TODO implement group based pricing
+        return self.paymentprice_set.all()[0]
+
     def _is_type(self, model_type):
         return ContentType.objects.get_for_model(model_type) == self.content_type
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Unchosen extras for events not counted correctly
See https://online.ntnu.no/dashboard/events/265/attendees/
There are 3-4 people who haven't chosen any extras, but in the summary at the bottom, it sais Ikke valgt: 0



Discussion:

Resolving patch:
diff --git a/apps/events/dashboard/views.py b/apps/events/dashboard/views.py
--- a/apps/events/dashboard/views.py
+++ b/apps/events/dashboard/views.py
@@ -210,16 +210,16 @@ def event_change_attendees(request, event_id, active_tab='attendees'):
     return render(request, 'events/dashboard/details.html', context)
 
 
-def count_extras(arr, inlist, atts):
-    for att in atts:
-        choice = "Ikke valgt" if att.extras is None else att.extras
-        if att.extras not in arr:
-            arr[choice] = {"type": choice, "attending": 0, "waits": 0, "allergics": []}
-        ex = arr[choice]
-        ex[inlist] += 1
-        if att.user.allergies:
-            what_list = "påmeldt" if inlist is "attending" else "venteliste"
-            ex["allergics"].append({"user": att.user, "list": what_list})
+def count_extras(event_extras, attendance_list, attendees):
+    for attendee in attendees:
+        choice = attendee.extras
+        if attendee.extras not in event_extras:
+            event_extras[choice] = {"type": choice, "attending": 0, "waits": 0, "allergics": []}
+        ex = event_extras[choice]
+        ex[attendance_list] += 1
+        if attendee.user.allergies:
+            what_list = "påmeldt" if attendance_list is "attending" else "venteliste"
+            ex["allergics"].append({"user": attendee.user, "list": what_list})
 
 
 @login_required


Test patch:
Repository: dotkom/onlineweb4

Issue:
Delete user in Dashboard user edit doesn't perform any action
The delete user button does not actually perform a request.



Discussion:

Resolving patch:
diff --git a/apps/authentication/dashboard/views.py b/apps/authentication/dashboard/views.py
--- a/apps/authentication/dashboard/views.py
+++ b/apps/authentication/dashboard/views.py
@@ -172,6 +172,7 @@ class UserDetailView(DashboardPermissionMixin, DetailView):
 class UserUpdateView(DashboardPermissionMixin, UpdateView):
     form_class = UserUpdateForm
     model = User
+    context_object_name = 'user'
     permission_required = 'authentication.change_onlineuser'
     pk_url_kwarg = 'user_id'
     template_name = 'auth/dashboard/user_edit.html'
@@ -184,7 +185,7 @@ class UserDeleteView(DashboardPermissionMixin, DeleteView):
     model = User
     permission_required = 'authentication.delete_onlineuser'
     pk_url_kwarg = 'user_id'
-    success_url = reverse_lazy('auth_index')
+    success_url = reverse_lazy('user_list')
 
 
 @login_required


Test patch:
Repository: dotkom/onlineweb4

Issue:
Company.short_description field has lower max_length than database data
Some companies on https://online.ntnu.no has `short_description`s with a length longer than 200 characters. This makes it impossible to save the model without reducing the character count in that field. 

The field is a TextField which supports an arbitrary long length, so the `max_length` parameter set on the field is simply for form validation. 

I suggest bumping it to a reasonable amount.



Discussion:
Do we really need a max length for this?

Not necessarily, it depends on how much text we want to display. 

I think it's fair to set a limit for an ingress, or "short description". However, 200 characters is too low a limit.


Resolving patch:
diff --git a/apps/companyprofile/migrations/0004_auto_20160413_2328.py b/apps/companyprofile/migrations/0004_auto_20160413_2328.py
new file mode 100644
--- /dev/null
+++ b/apps/companyprofile/migrations/0004_auto_20160413_2328.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.9.5 on 2016-04-13 21:28
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('companyprofile', '0003_company_image'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='company',
+            name='short_description',
+            field=models.TextField(verbose_name='kort beskrivelse'),
+        ),
+    ]
diff --git a/apps/companyprofile/models.py b/apps/companyprofile/models.py
--- a/apps/companyprofile/models.py
+++ b/apps/companyprofile/models.py
@@ -11,7 +11,7 @@ class Company(models.Model):
     IMAGE_EXTENSIONS = ['.jpg', '.jpeg', '.gif', '.png', '.tif', '.tiff']
 
     name = models.CharField(_("bedriftsnavn"), max_length=100)
-    short_description = models.TextField(_("kort beskrivelse"), max_length=200)
+    short_description = models.TextField(_("kort beskrivelse"))
     long_description = models.TextField(_("utdypende beskrivelse"), blank=True, null=True)
     old_image = FileBrowseField(_("bilde"), max_length=200, directory=IMAGE_FOLDER,
                                 extensions=IMAGE_EXTENSIONS, null=False, blank=False)


Test patch:
Repository: dotkom/onlineweb4

Issue:
Hide irrelevant information if not applicable to the event
The event dashboard should provide useful information to the administrators of the events, and I think it should refrain from displaying information that's not relevant.

For example, all events include a column about "Extras" for the event, even though the event has no extras assigned. The column for "Paid" could be stripped if the event does not have a payment relation. If it's not an attendance event, the column for "showed up" could be removed.

This way we could add more information for events where this would be useful, without the table being too cramped.



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
@@ -375,6 +375,10 @@ def has_reservation(self):
         except Reservation.DoesNotExist:
             return False
 
+    @property
+    def has_extras(self):
+        return bool(self.extras.exists())
+
     @property
     def attendees_qs(self):
         """ Queryset with all attendees not on waiting list """


Test patch:
Repository: dotkom/onlineweb4

Issue:
Events ending early in they day still on frontpage after ending
This happened to "Låvefesten" which was set to end at 00:00:00, which is "today" for the same day and thus prioritized to be on the front page, even if it has passed.



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
@@ -39,22 +39,23 @@ class EventOrderedByRegistration(models.Manager):
     Order events by registration start if registration start is within 7 days of today.
     """
     def get_queryset(self):
-        today = timezone.now()
-        DELTA_FUTURE = settings.OW4_SETTINGS.get('events').get('FEATURED_DAYS_FUTURE')
-        DELTA_PAST = settings.OW4_SETTINGS.get('events').get('FEATURED_DAYS_PAST')
-        week_back = timezone.now() - timedelta(days=DELTA_PAST)
-        week_in_future = timezone.now() + timedelta(days=DELTA_FUTURE)
+        now = timezone.now()
+        DELTA_FUTURE_SETTING = settings.OW4_SETTINGS.get('events').get('FEATURED_DAYS_FUTURE')
+        DELTA_PAST_SETTING = settings.OW4_SETTINGS.get('events').get('FEATURED_DAYS_PAST')
+        DAYS_BACK_DELTA = timezone.now() - timedelta(days=DELTA_PAST_SETTING)
+        DAYS_FORWARD_DELTA = timezone.now() + timedelta(days=DELTA_FUTURE_SETTING)
 
         return super(EventOrderedByRegistration, self).get_queryset().\
             annotate(registration_filtered=Case(
-                When(Q(attendance_event__registration_start__gte=week_back) &
-                     Q(attendance_event__registration_start__lte=week_in_future),
+                When(Q(event_end__gte=now) &
+                     Q(attendance_event__registration_start__gte=DAYS_BACK_DELTA) &
+                     Q(attendance_event__registration_start__lte=DAYS_FORWARD_DELTA),
                      then='attendance_event__registration_start'),
                 default='event_end',
                 output_field=models.DateTimeField()
             )
         ).annotate(is_today=Case(
-            When(event_end__date=today.date(),
+            When(event_end__date=now.date(),
                  then=Value(1)),
             default=Value(0),
             output_field=models.IntegerField()


Test patch:
Repository: dotkom/onlineweb4

Issue:
Make sure people with `webshop.view_model` can view detail views in dashboard
Users with access to webshop dashboard cannot get a list of products (dashboard -> webshop -> kategorier -> click on a category), nor view the details of an order (dashboard -> webshop -> bestillinger -> click on an order)



Discussion:

Resolving patch:
diff --git a/apps/dashboard/chunks/dashboard/views.py b/apps/dashboard/chunks/dashboard/views.py
--- a/apps/dashboard/chunks/dashboard/views.py
+++ b/apps/dashboard/chunks/dashboard/views.py
@@ -25,12 +25,6 @@ class ChunkCreate(DashboardPermissionMixin, CreateView):
     fields = ('key', 'description', 'content')
     permission_required = 'chunks.add_chunk'
 
-    def get_object(self, queryset=None):
-        # Overridden to work around https://github.com/django-guardian/django-guardian/issues/146,
-        # an issue with regards to guardian's PermissionMixin working with CreateView -
-        # where it requires an object even in a CreateView.
-        return None
-
     def get_success_url(self):
         return reverse('chunk-dashboard:update', args=(self.object.id,))
 
diff --git a/apps/dashboard/tools.py b/apps/dashboard/tools.py
--- a/apps/dashboard/tools.py
+++ b/apps/dashboard/tools.py
@@ -124,4 +124,12 @@ class DashboardPermissionMixin(DashboardMixin, PermissionRequiredMixin):
     permissions to access a certain view.
     """
 
+    def get_permission_object(self, *args, **kwargs):
+        """
+        By default PermissionRequiredMixin works with object permissions.
+        By returning None we force guardian to only check if the user
+        has the proper permission.
+        """
+        return None
+
     return_403 = True
diff --git a/apps/webshop/dashboard/views.py b/apps/webshop/dashboard/views.py
--- a/apps/webshop/dashboard/views.py
+++ b/apps/webshop/dashboard/views.py
@@ -42,10 +42,6 @@ class CategoryCreate(DashboardPermissionMixin, CreateView):
     template_name = 'webshop/dashboard/category_update.html'
     permission_required = 'webshop.add_category'
 
-    def get_object(self, *args, **kwargs):
-        # django-guardian hack https://github.com/django-guardian/django-guardian/issues/195
-        return None
-
     def get_success_url(self):
         return reverse('dashboard-webshop:categories')
 
@@ -94,10 +90,6 @@ def form_valid(self, form):
         product.category = category
         return super(ProductCreate, self).form_valid(form)
 
-    def get_object(self, *args, **kwargs):
-        # django-guardian hack https://github.com/django-guardian/django-guardian/issues/195
-        return None
-
     def get_success_url(self):
         return reverse('dashboard-webshop:category', kwargs={'slug': self.kwargs.get('category_slug')})
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Add itex to "Send mail to participants" list



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
@@ -350,6 +350,8 @@ def handle_mail_participants(event, _from_email, _to_email_value, subject, _mess
         from_email = settings.EMAIL_FAGKOM
     elif from_email_value == '5':
         from_email = settings.EMAIL_EKSKOM
+    elif from_email_value == '6':
+        from_email = settings.EMAIL_ITEX
 
     # Who to send emails to
     send_to_users = _to_email_options[_to_email_value][0]
diff --git a/onlineweb4/settings/base.py b/onlineweb4/settings/base.py
--- a/onlineweb4/settings/base.py
+++ b/onlineweb4/settings/base.py
@@ -28,6 +28,7 @@
 EMAIL_DOTKOM = 'dotkom@online.ntnu.no'
 EMAIL_EKSKOM = 'ekskom@online.ntnu.no'
 EMAIL_FAGKOM = 'fagkom@online.ntnu.no'
+EMAIL_ITEX = 'itex@online.ntnu.no'
 EMAIL_PROKOM = 'prokom@online.ntnu.no'
 EMAIL_TRIKOM = 'trikom@online.ntnu.no'
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Shorten required length for some event fields
This is to accomodate for events planned long into the future, where all information may not be known at the time of event creation. However, we still want to have a lower limit - as the front page would look ugly if there was not enough text to ~fill the "featured" events' text boxes.



Discussion:
What about not having this limit, AND prevent "TBA" events from being one of the two featured events?


Resolving patch:
diff --git a/apps/events/admin.py b/apps/events/admin.py
--- a/apps/events/admin.py
+++ b/apps/events/admin.py
@@ -1,7 +1,6 @@
 # -*- coding: utf-8 -*-
 
 from django.contrib import admin, messages
-from django.core import validators
 from django.utils.translation import ugettext as _
 from reversion.admin import VersionAdmin
 
@@ -156,13 +155,6 @@ def save_formset(self, request, form, formset, change):
             instance.save()
         formset.save_m2m()
 
-    def get_form(self, request, obj=None, **kwargs):
-        form = super(EventAdmin, self).get_form(request, obj, **kwargs)
-        form.base_fields['ingress_short'].validators = [validators.MinLengthValidator(50)]
-        form.base_fields['ingress'].validators = [validators.MinLengthValidator(75)]
-        form.base_fields['description'].validators = [validators.MinLengthValidator(140)]
-        return form
-
 
 class ReserveeInline(admin.TabularInline):
     model = Reservee
diff --git a/apps/events/models.py b/apps/events/models.py
--- a/apps/events/models.py
+++ b/apps/events/models.py
@@ -7,6 +7,7 @@
 from django.conf import settings
 from django.contrib.auth.models import Group
 from django.contrib.contenttypes.models import ContentType
+from django.core import validators
 from django.db import models
 from django.db.models import Case, Q, Value, When
 from django.template.defaultfilters import slugify
@@ -79,9 +80,10 @@ class Event(models.Model):
     event_start = models.DateTimeField(_('start-dato'))
     event_end = models.DateTimeField(_('slutt-dato'))
     location = models.CharField(_('lokasjon'), max_length=100)
-    ingress_short = models.CharField(_("kort ingress"), max_length=150)
-    ingress = models.TextField(_('ingress'))
-    description = models.TextField(_('beskrivelse'))
+    ingress_short = models.CharField(_("kort ingress"), max_length=150,
+                                     validators=[validators.MinLengthValidator(25)])
+    ingress = models.TextField(_('ingress'), validators=[validators.MinLengthValidator(25)])
+    description = models.TextField(_('beskrivelse'), validators=[validators.MinLengthValidator(45)])
     image = FileBrowseField(_("bilde"), max_length=200,
                             directory=IMAGE_FOLDER, extensions=IMAGE_EXTENSIONS, null=True, blank=True)
     event_type = models.SmallIntegerField(_('type'), choices=TYPE_CHOICES, null=False)


Test patch:
Repository: dotkom/onlineweb4

Issue:
Application for extending membership marks field of study as guest
When someone applies to get their membership prolonged their field of study is set to "guest" instead of what they previously were registered as. 



Discussion:

Resolving patch:
diff --git a/apps/approval/views.py b/apps/approval/views.py
--- a/apps/approval/views.py
+++ b/apps/approval/views.py
@@ -101,6 +101,7 @@ def create_membership_application(request):
 
         application = MembershipApproval(
             applicant=request.user,
+            field_of_study=request.user.field_of_study,
             new_expiry_date=new_expiration_date,
         )
         application.save()


Test patch:
Repository: dotkom/onlineweb4

Issue:
'Suspensjon' is spelled incorrectly
It is written suspensjon, not suspansjon



Discussion:
To add to this, I assume she means under "Prikker & Suspansjoner" in the profiles.


Resolving patch:
diff --git a/apps/profiles/views.py b/apps/profiles/views.py
--- a/apps/profiles/views.py
+++ b/apps/profiles/views.py
@@ -83,8 +83,8 @@ def _create_profile_context(request):
         ],
         'suspensions': [
             # Tuple syntax ('title', list_of_marks, is_collapsed)
-            (_('aktive suspansjoner'), Suspension.objects.filter(user=request.user, active=True), False),
-            (_('inaktive suspansjoner'), Suspension.objects.filter(user=request.user, active=False), True),
+            (_('aktive suspensjoner'), Suspension.objects.filter(user=request.user, active=True), False),
+            (_('inaktive suspensjoner'), Suspension.objects.filter(user=request.user, active=False), True),
         ],
         # password
         'password_change_form': PasswordChangeForm(request.user),


Test patch:
Repository: dotkom/onlineweb4

Issue:
Deleting a Careeropportunity in the dashboard does not actually delete
When trying to delete a career opportunity in the dashboard, it does not actually delete it.



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
@@ -1,4 +1,6 @@
 # -*- encoding: utf-8 -*-
+import logging
+
 from django.contrib import messages
 from django.contrib.auth.decorators import login_required
 from django.core.exceptions import PermissionDenied
@@ -32,6 +34,8 @@ def index(request):
 @login_required
 @permission_required('careeropportunity.change_careeropportunity', return_403=True)
 def detail(request, opportunity_id=None):
+    logger = logging.getLogger(__name__)
+    logger.debug('Editing careeropportunity with id: %s' % (opportunity_id))
 
     if not has_access(request):
         raise PermissionDenied
@@ -66,6 +70,8 @@ def detail(request, opportunity_id=None):
 @login_required
 @permission_required('careeropportunity.change_careeropportunity', return_403=True)
 def delete(request, opportunity_id=None):
+    logger = logging.getLogger(__name__)
+    logger.debug('Deleting careeropportunitywith id: %s' % (opportunity_id))
     if not has_access(request):
         raise PermissionDenied
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Filtering on attendance event on attendees admin doesn't work
This is only relevant for the admin panel and not the dashboard.

```
DisallowedModelAdminLookup at /admin/events/attendee/
Filtering by event__event__title not allowed
```

Can be reproduced by simply going to `/admin/events/attendee/` and filtering by some event.



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
@@ -73,7 +73,7 @@ def mark_not_attended(modeladmin, request, queryset):
 class AttendeeAdmin(VersionAdmin):
     model = Attendee
     list_display = ('user', 'event', 'paid', 'attended', 'note', 'extras')
-    list_filter = ('event__event__title',)
+    list_filter = ('event__event',)
     actions = [mark_paid, mark_attended, mark_not_paid, mark_not_attended]
 
     # Disable delete_selected http://bit.ly/1o4nleN


Test patch: