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

Issue:
Scheduler for FeedbackMail causes a mess when testing
When running tests, the scheduler for feedback mail causes a lot of text to be printed to console. There should be a setting variable to enable/disable this scheduler so that you don't run it in development.



Discussion:

Resolving patch:
diff --git a/apps/feedback/mommy.py b/apps/feedback/mommy.py
--- a/apps/feedback/mommy.py
+++ b/apps/feedback/mommy.py
@@ -196,4 +196,6 @@ def __unicode__(self):
             self.end)
         return message
 
-schedule.register(FeedbackMail, day_of_week='mon-sun', hour=8, minute=0)
+
+if settings.FEEDBACK_MAIL_SCHEDULER:
+    schedule.register(FeedbackMail, day_of_week='mon-sun', hour=8, minute=0)
diff --git a/onlineweb4/settings/base.py b/onlineweb4/settings/base.py
--- a/onlineweb4/settings/base.py
+++ b/onlineweb4/settings/base.py
@@ -29,6 +29,8 @@
 EMAIL_FAGKOM = 'fagkom@online.ntnu.no'
 EMAIL_PROKOM = 'prokom@online.ntnu.no'
 EMAIL_TRIKOM = 'trikom@online.ntnu.no'
+# Whether or not django should start the scheduler for feedback mails
+FEEDBACK_MAIL_SCHEDULER = True
 
 # We will receive errors and other django messages from this email
 SERVER_EMAIL = 'onlineweb4-error@online.ntnu.no'


Test patch:
Repository: dotkom/onlineweb4

Issue:
(User creation) Some fields are required that should not be
Address, zip and phone should not be required. People will complain.



Discussion:

Resolving patch:
diff --git a/apps/authentication/forms.py b/apps/authentication/forms.py
--- a/apps/authentication/forms.py
+++ b/apps/authentication/forms.py
@@ -47,9 +47,9 @@ class RegisterForm(forms.Form):
     email = forms.EmailField(label=_("Epost"), max_length=50)
     password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_("Passord"))
     repeat_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label=_("Gjenta passord"))
-    address = forms.CharField(label=_("Adresse"), max_length=50)
-    zip_code = forms.CharField(label=_("Postnummer"), max_length=4)
-    phone = forms.CharField(label=_("Telefon"), max_length=20)
+    address = forms.CharField(label=_("Adresse"), max_length=50, required=False)
+    zip_code = forms.CharField(label=_("Postnummer"), max_length=4, required=False)
+    phone = forms.CharField(label=_("Telefon"), max_length=20, required=False)
     
     def clean(self):
         super(RegisterForm, self).clean()
@@ -74,8 +74,9 @@ def clean(self):
 
             # ZIP code digits only
             zip_code = cleaned_data['zip_code']
-            if len(zip_code) != 4 or not zip_code.isdigit():
-                self._errors['zip_code'] = self.error_class([_(u"Postnummer må bestå av fire siffer.")])
+            if len(zip_code) != 0:
+                if len(zip_code) != 4 or len(zip_code) != 0 or not zip_code.isdigit():
+                    self._errors['zip_code'] = self.error_class([_(u"Postnummer må bestå av fire siffer.")])
 
             return cleaned_data 
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Error reports should not contain sensitive data
https://docs.djangoproject.com/en/dev/howto/error-reporting/#filtering-error-reports

Here is a guide how to do it.



Discussion:

Resolving patch:
diff --git a/apps/authentication/views.py b/apps/authentication/views.py
--- a/apps/authentication/views.py
+++ b/apps/authentication/views.py
@@ -9,12 +9,15 @@
 from django.shortcuts import render, redirect, get_object_or_404
 from django.http import HttpResponseRedirect
 from django.utils.translation import ugettext as _
+from django.views.decorators.debug import sensitive_post_parameters
 
 from django.conf import settings
 from apps.authentication.forms import (LoginForm, RegisterForm, 
                             RecoveryForm, ChangePasswordForm)
 from apps.authentication.models import OnlineUser as User, RegisterToken, Email
 
+
+@sensitive_post_parameters()
 def login(request):
     redirect_url = request.REQUEST.get('next', '')
     if request.method == 'POST':
@@ -31,11 +34,14 @@ def login(request):
     response_dict = { 'form' : form, 'next' : redirect_url}
     return render(request, 'auth/login.html', response_dict)
 
+
 def logout(request):
     auth.logout(request)
     messages.success(request, _(u'Du er nå logget ut.'))
     return HttpResponseRedirect('/')
 
+
+@sensitive_post_parameters()
 def register(request):
     if request.user.is_authenticated():
         messages.error(request, _(u'Registrering av ny konto krever at du er logget ut.'))
@@ -100,6 +106,7 @@ def register(request):
 
         return render(request, 'auth/register.html', {'form': form, })
 
+
 def verify(request, token):
     rt = get_object_or_404(RegisterToken, token=token)
     
@@ -181,6 +188,8 @@ def recover(request):
 
         return render(request, 'auth/recover.html', {'form': form})
 
+
+@sensitive_post_parameters()
 def set_password(request, token=None): 
     if request.user.is_authenticated():
         return HttpResponseRedirect('/')


Test patch:
Repository: dotkom/onlineweb4

Issue:
Usernames are forced to lowercase on register.
Just witnessed a registration process with a username starting with a capital letter. When user tried to log in after e-mail verification, he could not log in. Changing capital to lowercase did the trick. This is however very unintuitive, so capital letters should be allowed in username, or atleast there should be a notification or warning.



Discussion:

Resolving patch:
diff --git a/apps/authentication/views.py b/apps/authentication/views.py
--- a/apps/authentication/views.py
+++ b/apps/authentication/views.py
@@ -54,7 +54,7 @@ def register(request):
 
                 # Create user
                 user = User(
-                    username=cleaned['username'].lower(), 
+                    username=cleaned['username'], 
                     first_name=cleaned['first_name'].title(), 
                     last_name=cleaned['last_name'].title(),
                 )


Test patch:
Repository: dotkom/onlineweb4

Issue:
Recovery of passwords link is valid multiple times.
The RegisterToken that allows recovery seems to be valid more than once.
I'm guessing it's not getting deleted like it should be.



Discussion:

Resolving patch:
diff --git a/apps/authentication/views.py b/apps/authentication/views.py
--- a/apps/authentication/views.py
+++ b/apps/authentication/views.py
@@ -194,31 +194,32 @@ def set_password(request, token=None):
     if request.user.is_authenticated():
         return HttpResponseRedirect('/')
     else:
-        rt = get_object_or_404(RegisterToken, token=token)
+        tokens = RegisterToken.objects.filter(token=token)
        
-        if rt.is_valid:
-            if request.method == 'POST':
-                form = ChangePasswordForm(request.POST, auto_id=True)
-                if form.is_valid():
-                    user = getattr(rt, 'user')
-
-                    user.is_active = True
-                    user.set_password(form.cleaned_data['new_password'])
-                    user.save()
-                    
-                    rt.delete()
-
-                    messages.success(request, _(u'Bruker %s har gjennomført vellykket gjenoppretning av passord. Du kan nå logge inn.') % user.username)
-                    
-                    return HttpResponseRedirect('/')        
-            else:
-                
-                form = ChangePasswordForm()
-
-                messages.success(request, _(u'Lenken er akseptert. Vennligst skriv inn ønsket passord.'))
-
-            return render(request, 'auth/set_password.html', {'form': form, 'token': token})
+        if tokens.count() == 1:
+            rt = tokens[0]
+            if rt.is_valid:
+                if request.method == 'POST':
+                    form = ChangePasswordForm(request.POST, auto_id=True)
+                    if form.is_valid():
+                        user = getattr(rt, 'user')
+
+                        user.is_active = True
+                        user.set_password(form.cleaned_data['new_password'])
+                        user.save()
+                        
+                        rt.delete()
+
+                        messages.success(request, _(u'Bruker %s har gjennomført vellykket gjenoppretning av passord. Du kan nå logge inn.') % user.username)
+                        
+                        return HttpResponseRedirect('/')        
+                else:
+                    form = ChangePasswordForm()
+
+                    messages.success(request, _(u'Lenken er akseptert. Vennligst skriv inn ønsket passord.'))
+
+                return render(request, 'auth/set_password.html', {'form': form, 'token': token})
 
         else:
-            messages.error(request, _(u'Lenken er utløpt. Vennligst bruk gjenoppretning av passord for å få tilsendt en ny lenke.'))
+            messages.error(request, _(u'Lenken er ugyldig. Vennligst bruk gjenoppretning av passord for å få tilsendt en ny lenke.'))
             return HttpResponseRedirect('/')        


Test patch:
Repository: dotkom/onlineweb4

Issue:
Order of events in event archive is non-logical
As it is now:

28.11.13
04.04.14
16.01.14
23.11.13
27.02.14

and so on...



Discussion:

Resolving patch:
diff --git a/apps/events/views.py b/apps/events/views.py
--- a/apps/events/views.py
+++ b/apps/events/views.py
@@ -147,15 +147,15 @@ def _search_indexed(request, query, filters):
     if filters['myevents'] == 'true':
         kwargs['attendance_event__attendees'] = request.user
 
+    events = Event.objects.filter(**kwargs).order_by('event_start').prefetch_related(
+            'attendance_event', 'attendance_event__attendees')
+
     if query:
-        for result in watson.search(query, models=(
-            Event.objects.filter(**kwargs).prefetch_related(
-                'attendance_event', 'attendance_event__attendees'),)):
+        for result in watson.search(query, models=(events,)):
             results.append(result.object)
         return results[:10]
 
-    return Event.objects.filter(**kwargs).prefetch_related(
-            'attendance_event', 'attendance_event__attendees')
+    return events
 
 
 @login_required()


Test patch:
Repository: dotkom/onlineweb4

Issue:
Gravatar default images do not load correctly



Discussion:

Resolving patch:
diff --git a/apps/authentication/templatetags/gravatar_url_resolver.py b/apps/authentication/templatetags/gravatar_url_resolver.py
--- a/apps/authentication/templatetags/gravatar_url_resolver.py
+++ b/apps/authentication/templatetags/gravatar_url_resolver.py
@@ -6,8 +6,11 @@
 
 @register.assignment_tag(takes_context=True)
 def gravatar_url(context, user, size):
-    default = "%s%s_%s.png" % (context['request'].META['HTTP_HOST'],
+
+    prefix = "https://" if context['request'].is_secure() else "http://"
+    default = "%s%s%s_%s.png" % (prefix, context['request'].META['HTTP_HOST'],
                                settings.DEFAULT_PROFILE_PICTURE_PREFIX, user.gender)
+
     gravatar_url = "https://www.gravatar.com/avatar/" + hashlib.md5(user.get_email().email).hexdigest() + "?"
     gravatar_url += urllib.urlencode({'d': default, 's':str(size)})
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Upgrade to Bootstrap 3.0.2
We are still running 3.0.0 or RC1 I think. Remember that some config files are altered and needs to be diffed for icons and shit to work.



Discussion:

Resolving patch:
diff --git a/onlineweb4/settings/base.py b/onlineweb4/settings/base.py
--- a/onlineweb4/settings/base.py
+++ b/onlineweb4/settings/base.py
@@ -79,7 +79,6 @@
 )
 
 COMPRESS_FILES = True
-COMPRESS_ENABLED = True
 COMPRESS_OUTPUT_DIR = 'cache'
 COMPRESS_PRECOMPILERS = (
     ('text/less', 'lessc {infile} {outfile}'),


Test patch:
Repository: dotkom/onlineweb4

Issue:
When "venteliste" is enabled you can attend an event before registration opens
Can currently be testet on moonshine using this event: http://moonshine.online.ntnu.no/events/4/test/



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
@@ -118,6 +118,11 @@ def is_eligible_for_signup(self, user):
             response['message'] = _(u'Påmeldingen er ikke lenger åpen.')
             response['status_code'] = 502 
             return response
+
+        if timezone.now() < self.attendance_event.registration_start:
+            response['message'] = _(u'Påmeldingen har ikke åpnet enda.')
+            response['status_code'] = 504
+            return response
         
         #Room for me on the event?
         if not self.attendance_event.room_on_event:


Test patch:
diff --git a/apps/events/tests.py b/apps/events/tests.py
--- a/apps/events/tests.py
+++ b/apps/events/tests.py
@@ -171,7 +171,7 @@ def testUserGroupRule(self):
     def testFutureAccessTrumpsOffset(self):
         self.logger.debug("Testing restriction with group rules.")
         
-        # Create two different rules, and verify that the response is false, but without offset
+        # Create two different rules, and verify that the response is true, but without offset
         # Group rule
         self.group = G(Group, name="Testgroup")
         self.grouprule = G(UserGroupRule, group=self.group, offset=0)
@@ -189,4 +189,4 @@ def testFutureAccessTrumpsOffset(self):
         self.attendance_event.registration_start = self.now + datetime.timedelta(hours=1)
         response = self.event.is_eligible_for_signup(self.user)
         self.assertFalse(response['status'])
-        self.assertEqual(402, response['status_code'])
+        self.assertEqual(504, response['status_code'])
Repository: dotkom/onlineweb4

Issue:
Feedback views need @login_required
Right now users get this reply when trying to answer: "Du kan ikke svare på dette skjemaet."

Most of the cases, the user just needs to login for this to work.



Discussion:

Resolving patch:
diff --git a/apps/feedback/views.py b/apps/feedback/views.py
--- a/apps/feedback/views.py
+++ b/apps/feedback/views.py
@@ -7,6 +7,7 @@
 from django.contrib.contenttypes.models import ContentType
 from django.contrib import messages
 from django.contrib.admin.views.decorators import staff_member_required
+from django.contrib.auth.decorators import login_required
 from django.utils import simplejson
 from django.core.exceptions import ObjectDoesNotExist
 from django.utils.translation import ugettext_lazy as _
@@ -15,6 +16,7 @@
 from apps.feedback.models import FeedbackRelation, FieldOfStudyAnswer, RATING_CHOICES, TextAnswer, RegisterToken
 from apps.feedback.forms import create_answer_forms
 
+@login_required
 def feedback(request, applabel, appmodel, object_id, feedback_id):
     fbr = _get_fbr_or_404(applabel, appmodel, object_id, feedback_id)
 


Test patch:
diff --git a/apps/feedback/tests.py b/apps/feedback/tests.py
--- a/apps/feedback/tests.py
+++ b/apps/feedback/tests.py
@@ -166,16 +166,23 @@ def test_good_urls(self):
         response = client.get(feedback_relation.get_absolute_url() + 'results/')
         self.assertEqual(response.status_code, 200)
     '''
-    
-    def test_bad_urls(self):
+
+    def test_should_redirect(self): #login_required / not logged inn
         response = self.client.get("/feedback/events/event/100/1/")
+        self.assertEqual(response.status_code, 302)
+
+    def test_bad_urls(self):
+        client = Client()
+        client.login(username="user1", password="Herpaderp123")
+
+        response = client.get("/feedback/events/event/100/1/")
         self.assertEqual(response.status_code, 404)
 
-        response = self.client.get("/feedback/events/event/1/100/")
+        response = client.get("/feedback/events/event/1/100/")
         self.assertEqual(response.status_code, 404)
 
-        response = self.client.get("/feedback/events/event/100/100/")
+        response = client.get("/feedback/events/event/100/100/")
         self.assertEqual(response.status_code, 404)
 
-        response = self.client.get("/feedback/events/derp/1/1/")
+        response = client.get("/feedback/events/derp/1/1/")
         self.assertEqual(response.status_code, 404)
Repository: dotkom/onlineweb4

Issue:
Minor issues in feedback
- We have said that rating questions go up to 5, they actually go to 6. This must be either changed, or the committees must be informed so questions can be altered.
- Norwegian dates in the mail sent to users
- The domain used for the links should be https://online.ntnu.no, not morgan.online.ntnu.no
- Online linjeforening should be Linjeforeningen Online
- Errors on required fields should stand out more, see appendix 1 for current.

"Hei, vi ønsker tilbakemelding på "Kurs med Steria" som du var med på den 23. January:

morgan.online.ntnu.no/feedback/events/event/23/2/

Fristen for å svare på skjema er 30. January innen kl 23:59.
Vær oppmerksom på at du får prikk dersom du ikke svarer på disse spørsmålene innen fristen.

Eventuelle spørsmål sendes til fagkom@online.ntnu.no

Mvh
Online linjeforening"

Appendix 1
![required field](https://f.cloud.github.com/assets/632466/1994553/9b936e4e-84f0-11e3-9deb-e1a8bc3892dd.png)



Discussion:

Resolving patch:
diff --git a/apps/feedback/mommy.py b/apps/feedback/mommy.py
--- a/apps/feedback/mommy.py
+++ b/apps/feedback/mommy.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 import datetime
 import socket
+import locale
 
 from django.utils import timezone
 from django.contrib.contenttypes.models import ContentType
@@ -16,9 +17,10 @@ class FeedbackMail(Task):
 
     @staticmethod
     def run():
-       active_feedbacks = FeedbackRelation.objects.filter(active=True)
+        locale.setlocale(locale.LC_ALL, "nb_NO.UTF-8")
+        active_feedbacks = FeedbackRelation.objects.filter(active=True)
        
-       for feedback in active_feedbacks:
+        for feedback in active_feedbacks:
             message = FeedbackMail.generate_message(feedback)
 
             if message.send:
@@ -178,7 +180,7 @@ class Message():
     contact = ""
     link = ""
     send = False
-    end = u"\n\nMvh\nOnline linjeforening"
+    end = u"\n\nMvh\nLinjeforeningen Online"
     results_message = False
 
     committee_mail = ""
@@ -196,4 +198,4 @@ def __unicode__(self):
             self.end)
         return message
 
-schedule.register(FeedbackMail, day_of_week='mon-sun', hour=8, minute=0)
+schedule.register(FeedbackMail, day_of_week='mon-sun', hour=8, minute=00)


Test patch:
Repository: dotkom/onlineweb4

Issue:
Session cookie should not expire
I don't like login in places



Discussion:

Resolving patch:
diff --git a/apps/authentication/forms.py b/apps/authentication/forms.py
--- a/apps/authentication/forms.py
+++ b/apps/authentication/forms.py
@@ -36,7 +36,6 @@ def login(self, request):
             return False
         if self.is_valid():
             auth.login(request, self.user)
-            request.session.set_expiry(0)
             return True
         return False
 
diff --git a/onlineweb4/settings/base.py b/onlineweb4/settings/base.py
--- a/onlineweb4/settings/base.py
+++ b/onlineweb4/settings/base.py
@@ -52,6 +52,9 @@
 DATETIME_FORMAT = 'N j, Y, H:i'
 SECRET_KEY = 'override-this-in-local.py'
 
+# Session cookie expires after one year
+SESSION_COOKIE_AGE = 31540000
+
 # Override this in local if you need to :)
 BASE_URL = 'https://online.ntnu.no'
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Users should not be able to remove the acceptance of mark rules
When a user has accepted the mark rules, it should not be possible to take it off again.

The only case where the user should have to interact with this feature again is if the rules have been updated.



Discussion:

Resolving patch:
diff --git a/apps/authentication/models.py b/apps/authentication/models.py
--- a/apps/authentication/models.py
+++ b/apps/authentication/models.py
@@ -273,5 +273,11 @@ class Meta:
         verbose_name_plural = _(u'posisjoner')
         ordering = (u'user',)
 
+# Static method for resetting all users mark rules accepted field to false due to changes in mark rules
+def reset_marks_acceptance():
+    for user in OnlineUser.objects.all():
+        user.mark_rules = False
+        user.save()
+
 # Register OnlineUser in watson index for searching
 watson.register(OnlineUser)
diff --git a/apps/profiles/views.py b/apps/profiles/views.py
--- a/apps/profiles/views.py
+++ b/apps/profiles/views.py
@@ -208,9 +208,8 @@ def update_mark_rules(request):
                 request.user.mark_rules = True
                 request.user.save()
             else:
-                return_status = json.dumps({'message': _(u"Du har valgt å ikke akseptere prikkereglene.")})
-                request.user.mark_rules = False
-                request.user.save()
+                return_status = json.dumps({'message': _(u"Du kan ikke endre din godkjenning av prikkereglene.")})
+		return HttpResponse(status=403, content=return_status)
 
             return HttpResponse(status=212, content=return_status)
         return HttpResponse(status=405)


Test patch:
Repository: dotkom/onlineweb4

Issue:
Alergies should be tied to names in pdf
Request from arrKom among others. 



Discussion:
The whole point of having it this way was to preserve privacy. I agree that it's a bit inconvenient when people list random stuff and you don't know who to approach about it, but this was even discussed at GenFors.

As mentioned, arrkom (and maybe others) needs this info tied to persons and we have discussed this in HS :-) 

I disagree that they needs this tied to persons. However if HS says it should be that way, we'll do that.


Resolving patch:
diff --git a/apps/events/pdf_generator.py b/apps/events/pdf_generator.py
--- a/apps/events/pdf_generator.py
+++ b/apps/events/pdf_generator.py
@@ -19,8 +19,8 @@ def __init__(self, event):
         self.event = event
         self.attendees = sorted(event.attendance_event.attendees.all()[:event.attendance_event.max_capacity], key=lambda attendee: attendee.user.last_name)
         self.waiters = event.wait_list
-        self.attendee_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon'), ]
-        self.waiters_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon'), ]
+        self.attendee_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon', u'Allergier'), ]
+        self.waiters_table_data = [(u'Navn', u'Klasse', u'Studie', u'Telefon',  u'Allergier'), ]
         self.allergies_table_data = ()
 
         self.create_attendees_table_data()
@@ -34,7 +34,7 @@ def create_attendees_table_data(self):
             user = attendee.user
             self.attendee_table_data.append((create_body_text("%s, %s" % (user.last_name, user.first_name)),
                                              user.year, create_body_text(user.get_field_of_study_display()),
-                                             user.phone_number))
+                                             user.phone_number, user.allergies))
 
             if user.allergies:
                 self.allergies_table_data = self.allergies_table_data + (user.allergies,)
@@ -46,13 +46,13 @@ def create_waiters_table_data(self):
             user = attendee.user
             self.waiters_table_data.append((create_body_text("%s, %s" % (user.last_name, user.first_name)),
                                             user.year, create_body_text(user.get_field_of_study_display()),
-                                            user.phone_number))
+                                            user.phone_number, user.allergies))
 
             if user.allergies:
                 self.allergies_table_data = self.allergies_table_data + (user.allergies,)
 
     def attendee_column_widths(self):
-        return (200, 40, 170, 60)
+        return (150, 40, 170, 60, 100)
 
     def allergies_column_widths(self):
         return (200, 200)


Test patch: