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

Issue:
Committee positions in dashboard looks ugly as shit



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
@@ -276,7 +276,7 @@ def __unicode__(self):
     class Meta:
         verbose_name = _(u'posisjon')
         verbose_name_plural = _(u'posisjoner')
-        ordering = (u'user',)
+        ordering = (u'user', u'period', )
 
 # Static method for resetting all users mark rules accepted field to false due to changes in mark rules
 def reset_marks_acceptance():


Test patch:
Repository: dotkom/onlineweb4

Issue:
Make invalid answers in the feedback form clearer
Add an error message when answers are missing.



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
@@ -40,6 +40,8 @@ def feedback(request, applabel, appmodel, object_id, feedback_id):
 
             messages.success(request, _(u"Takk for at du svarte"))
             return redirect("home")
+        else:
+            messages.error(request, _(u"Du må svare på alle påkrevde felt"))
     else:
         answers = create_answer_forms(fbr)
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Ability to format company-url
![screenshot from 2014-01-29 17 32 37](https://f.cloud.github.com/assets/1758308/2031524/225447e4-8903-11e3-9de0-90237ad655ba.png)
Like in this case, this ugly url should be formated to vimsa.no or the like. 



Discussion:
What about enabling markdown on this field?

Sounds like a fair solution to me.


Resolving patch:
diff --git a/apps/companyprofile/models.py b/apps/companyprofile/models.py
--- a/apps/companyprofile/models.py
+++ b/apps/companyprofile/models.py
@@ -14,7 +14,7 @@ class Company(models.Model):
     image = FileBrowseField(_(u"bilde"), 
         max_length=200, directory=IMAGE_FOLDER,
         extensions=IMAGE_EXTENSIONS, null=False, blank=False)
-    site = models.URLField(_(u"hjemmeside"))
+    site = models.CharField(_(u"hjemmeside"), max_length=100)
     email_address = models.EmailField(_(u"epostaddresse"), max_length=75, blank=True, null=True)
     phone_number = models.CharField(_(u"telefonnummer"), max_length=20, blank=True, null=True)
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Filtering my events doesn't work
_Actually I'm not even sure if it's just my local setup that's fucking around or not, but this doesn't seem to work at all.
I can't check with moonshine or prod because everything is down atm, so I'm just making this before I forget._

```
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')
```

in events/views.py _search_indexed

Comparing attendance_event__attendees (Attendee) with request.user (OnlineUser) doesn't make sense. 

It should be attendance_event__attendees__user which from limited testing seems to work. 



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
@@ -149,7 +149,7 @@ def _search_indexed(request, query, filters):
         kwargs['event_start__gte'] = timezone.now()
 
     if filters['myevents'] == 'true':
-        kwargs['attendance_event__attendees'] = request.user
+        kwargs['attendance_event__attendees__user'] = request.user
 
     events = Event.objects.filter(**kwargs).order_by('event_start').prefetch_related(
             'attendance_event', 'attendance_event__attendees')


Test patch:
Repository: dotkom/onlineweb4

Issue:
Saving an event without attendance_event fails
[Line 84 in events/models.py](https://github.com/dotKom/onlineweb4/blob/b369c82d5387f108463a617f766061374437cd96/apps/events/models.py#L84):

`return True if self.attendance_event else False`

Using self.attendance_event raises a DoesNotExist on not found. 
So either catch the exception or find another neater way to check if foreign keys exists. 



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
@@ -97,7 +97,7 @@ def save_model(self, request, obj, form, change):
         else:
             # If attendance max capacity changed we will notify users that they are now on the attend list
             old_event = Event.objects.get(id=obj.id)
-            if obj.is_attendance_event() and old_event.wait_list:
+            if old_event.is_attendance_event() and old_event.wait_list:
                 diff_capacity = obj.attendance_event.max_capacity - old_event.attendance_event.max_capacity
                 if diff_capacity > 0:
                     if diff_capacity > len(old_event.wait_list):
diff --git a/apps/events/models.py b/apps/events/models.py
--- a/apps/events/models.py
+++ b/apps/events/models.py
@@ -81,7 +81,10 @@ def number_of_attendees_not_on_waiting_list(self):
 
     def is_attendance_event(self):
         """ Returns true if the event is an attendance event """
-        return True if self.attendance_event else False
+        try:
+            return True if self.attendance_event else False
+        except AttendanceEvent.DoesNotExist:
+            return False
 
     def is_eligible_for_signup(self, user):
         """


Test patch:
Repository: dotkom/onlineweb4

Issue:
unattendEvent doesn't check if event allows attendance
Harmless bug and you'd be pretty stupid to run into, but still a bug. 



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
@@ -121,8 +121,18 @@ def attendEvent(request, event_id):
 def unattendEvent(request, event_id):
 
     event = get_object_or_404(Event, pk=event_id)
+
+    if not event.is_attendance_event():
+        messages.error(request, _(u"Dette er ikke et påmeldingsarrangement."))
+        return redirect(event)
+
     attendance_event = event.attendance_event
 
+    # Check if user is attending
+    if len(Attendee.objects.filter(event=attendance_event, user=request.user)) == 0:
+        messages.error(request, _(u"Du er ikke påmeldt dette arrangementet."))
+        return redirect(event)
+
     # Check if the deadline for unattending has passed
     if attendance_event.unattend_deadline < timezone.now():
         messages.error(request, _(u"Avmeldingsfristen for dette arrangementet har utløpt."))


Test patch:
Repository: dotkom/onlineweb4

Issue:
django.utils.simplejson is deprecated
```
/home/vagrant/.virtualenvs/onlineweb/local/lib/python2.7/site-packages/compressor/cache.py:8: DeprecationWarning: django.utils.simplejson is deprecated; use json instead.
```



Discussion:
https://docs.djangoproject.com/en/1.5/releases/1.5/#system-version-of-simplejson-no-longer-used

We must test and make sure this does not break our code.


Resolving patch:
diff --git a/apps/feedback/views.py b/apps/feedback/views.py
--- a/apps/feedback/views.py
+++ b/apps/feedback/views.py
@@ -8,11 +8,12 @@
 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 _
 from django.utils.safestring import SafeString
 
+import json
+
 from apps.feedback.models import FeedbackRelation, FieldOfStudyAnswer, RATING_CHOICES, TextAnswer, RegisterToken
 from apps.feedback.forms import create_answer_forms
 
@@ -117,7 +118,7 @@ def get_chart_data(request, applabel, appmodel, object_id, feedback_id):
     answer_collection['replies']['titles'] = rating_titles
     answer_collection['replies']['fos'] = answer_count.items()
    
-    return HttpResponse(simplejson.dumps(answer_collection), mimetype='application/json')
+    return HttpResponse(json.dumps(answer_collection), mimetype='application/json')
 
 
 @staff_member_required
diff --git a/utils/helpers.py b/utils/helpers.py
--- a/utils/helpers.py
+++ b/utils/helpers.py
@@ -1,12 +1,12 @@
 # -*- coding: utf8 -*-
 from datetime import datetime, date
-import simplejson
+import json
 
 from django.db.models.query import QuerySet
 from django.db import models
 
 
-class JsonHelper(simplejson.JSONEncoder):
+class JsonHelper(json.JSONEncoder):
 
     def default(self, obj):
         if isinstance(obj, datetime):
@@ -21,4 +21,4 @@ def default(self, obj):
         elif isinstance(obj, QuerySet):
             return list(obj)
 
-        return simplejson.JSONEncoder.default(self, obj)
\ No newline at end of file
+        return json.JSONEncoder.default(self, obj)
\ No newline at end of file


Test patch:
Repository: dotkom/onlineweb4

Issue:
Google Calendar export doesn't work with https
I guess I'll just hack together some "unhttps" templatefilter to change https to http when using Google Calendar. 



Discussion:

Resolving patch:
diff --git a/apps/events/templatetags/__init__.py b/apps/events/templatetags/__init__.py
new file mode 100644
diff --git a/apps/events/templatetags/calendar_filters.py b/apps/events/templatetags/calendar_filters.py
new file mode 100644
--- /dev/null
+++ b/apps/events/templatetags/calendar_filters.py
@@ -0,0 +1,8 @@
+from django import template
+import re
+
+register = template.Library()
+
+@register.filter
+def unhttps(url):
+    return re.sub(r'^https', 'http', url)


Test patch:
Repository: dotkom/onlineweb4

Issue:
Non-terminating anchor in event details template
``` html
<li><a href="/events/mail-participants/35">Send epost til deltakere<a/></li>
```

notice the

``` html
<a/>
```



Discussion:
OOOOOMG. I have spent so long on figuring out why the fuck some events got their whole ingress in an a-tag. This is fucking it. Great Espen!

Haha, fuckin' lold! Remember, the inspect elements view in Chrome fixes the DOM automatically for you, so you won't necessarily see it there. Source code view is the way to go, if anyone runs into something like this in the future.

![omg](http://i.imgur.com/NiDZf.gif)

Yes, I know. This was just way high up in the source code that it caught my eye.


Resolving patch:
diff --git a/apps/events/views.py b/apps/events/views.py
--- a/apps/events/views.py
+++ b/apps/events/views.py
@@ -282,12 +282,12 @@ def mail_participants(request, event_id):
         from_email = 'kontakt@online.ntnu.no'
         from_email_value = request.POST.get('from_email')
 
-        if from_email_value == 1:
-            from_email = settings.ARRKOM_EMAIL
-        elif from_email_value == 2:
-            from_email = settings.BEDKOM_EMAIL
-        elif from_email_value == 3:
-            from_email = settings.FAGKOM_EMAIL
+        if from_email_value == '1':
+            from_email = settings.EMAIL_ARRKOM
+        elif from_email_value == '2':
+            from_email = settings.EMAIL_BEDKOM
+        elif from_email_value == '3':
+            from_email = settings.EMAIL_FAGKOM
 
         signature = u'\n\nVennlig hilsen Linjeforeningen Online.\n(Denne eposten kan besvares til %s)' % from_email
 
@@ -295,9 +295,10 @@ def mail_participants(request, event_id):
         to_emails = []
         to_emails_value = request.POST.get('to_email')
 
-        if to_emails_value == 1:
+        if to_emails_value == '1':
             to_emails = [attendee.user.email for attendee in all_attendees.all()]
-        elif to_emails_value == 2:
+            print to_emails
+        elif to_emails_value == '2':
             to_emails = [attendee.user.email for attendee in attendees_on_waitlist.all()]
         else:
             to_emails = [attendee.user.email for attendee in attendees_not_paid.all()]


Test patch:
Repository: dotkom/onlineweb4

Issue:
Regex error in authentication
https://github.com/dotKom/onlineweb4/blob/develop/apps/authentication/views.py#L121

The "."s should be changed to "."



Discussion:
Seems that github screwed you over there, you mean \ . in reference to irc, right?

While this is a mistake, it'll only be a bug which can be used if someone controls domains which are named "studantnu.no" or something similar. The example you gave which was someone@stud@ntnu.no will never be the case anyway.

yes, backslash . That is true, they can't use this to anything out of the blue. It's such a small fix that I just thought we could correct it so it is proper.


Resolving patch:
diff --git a/apps/authentication/views.py b/apps/authentication/views.py
--- a/apps/authentication/views.py
+++ b/apps/authentication/views.py
@@ -118,7 +118,7 @@ def verify(request, token):
         user = getattr(rt, 'user')
 
         # If it is a stud email, set the ntnu_username for user
-        if re.match(r'[^@]+@stud.ntnu.no', rt.email):
+        if re.match(r'[^@]+@stud\.ntnu\.no', rt.email):
             user.ntnu_username = rt.email.split("@")[0]
 
         user_activated = False


Test patch:
Repository: dotkom/onlineweb4

Issue:
Accessing feedback results via tokens (no login) displays delete buttons
I opened a fresh incognito window and tried the token-based link below:
https://online.ntnu.no/feedback/events/event/33/2/results/16323ffa19014de8b02b3647a2d94f33/

If I hover over answers, I get the delete X and can press it. It then removes the answer from the DOM. It does not actually do the deletion server side (since the view is login required), but it can not be like this.

The behavior looks unprofessional and the system can not be used actively towards companys in this state.

The icon for deletion should not appear when viewing the results this way.



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
@@ -53,7 +53,7 @@ def feedback(request, applabel, appmodel, object_id, feedback_id):
 
 @staff_member_required
 def result(request, applabel, appmodel, object_id, feedback_id):
-    return feedback_results(request, applabel, appmodel, object_id, feedback_id)
+    return feedback_results(request, applabel, appmodel, object_id, feedback_id, True)
 
 def results_token(request, applabel, appmodel, object_id, feedback_id,  token):
     rt = get_object_or_404(RegisterToken, token = token)
@@ -63,7 +63,7 @@ def results_token(request, applabel, appmodel, object_id, feedback_id,  token):
     else:
         raise Http404
 
-def feedback_results(request, applabel, appmodel, object_id, feedback_id):
+def feedback_results(request, applabel, appmodel, object_id, feedback_id, delete_permission=False):
     fbr = _get_fbr_or_404(applabel, appmodel, object_id, feedback_id)
 
     Qa = namedtuple("Qa", "question, answers")
@@ -77,7 +77,7 @@ def feedback_results(request, applabel, appmodel, object_id, feedback_id):
     token_url = u"%s%sresults/%s" % (request.META['HTTP_HOST'], fbr.get_absolute_url(), rt.token)
         
     return render(request, 'feedback/results.html',{'question_and_answers': question_and_answers, 
-        'description': fbr.description, 'token_url' : token_url})
+        'description': fbr.description, 'token_url' : token_url, 'delete_permission': delete_permission})
 
 
 @staff_member_required


Test patch:
Repository: dotkom/onlineweb4

Issue:
Registration form needs help text
To be a valid online user the user must register with their student emails. This is not indicated in the registration form.



Discussion:
But you mustn't? You can register your user with what the fuck you want. Only if you want to be a Online-member you have to register your NTNU-username and confirm this from your NTNU-mail. Then the membership-app will tell you if you are valid or not.

Fuck all. It should still be indicated in the registration form that you must either register with your student email or later register your student email. In the registr4tion form or elsewhere where the user will def1n37ly see it.

I think, as stated in the response to the user complaint, that we should ad some microcopy in the form telling the user that register with what the fuck you want. Preferably a non-NTNU email, since this will get deleted when you quit the university, and you will be able to register your NTNU username for member validation after the registration. (And maybe how you do it.)

:shit:

Has this been mentioned often? I feel that this is just Jonathan being Jonathan.. Once you log in and check your profile and membership page, this becomes abundantly clear.


Resolving patch:
diff --git a/apps/authentication/forms.py b/apps/authentication/forms.py
--- a/apps/authentication/forms.py
+++ b/apps/authentication/forms.py
@@ -40,14 +40,14 @@ def login(self, request):
         return False
 
 class RegisterForm(forms.Form):
-    username = forms.CharField(label=_("Brukernavn"), max_length=20)
-    first_name = forms.CharField(label=_("Fornavn"), max_length=50)
+    username = forms.CharField(label=_("Brukernavn"), max_length=20, help_text=u'Valgfritt brukernavn')
+    first_name = forms.CharField(label=_("Fornavn"), max_length=50, help_text=u'Mellomnavn inkluderer du etter fornavnet ditt')
     last_name = forms.CharField(label=_("Etternavn"), max_length=50)
-    email = forms.EmailField(label=_("Epost"), max_length=50)
+    email = forms.EmailField(label=_("Epost"), max_length=50, help_text=u'Du kan legge til flere epostadresser senere i din profil.')
     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=100, required=False)
-    zip_code = forms.CharField(label=_("Postnummer"), max_length=4, required=False)
+    address = forms.CharField(label=_("Adresse"), max_length=100, required=False, widget=forms.Textarea(attrs={'rows':3}))
+    zip_code = forms.CharField(label=_("Postnummer"), max_length=4, required=False, help_text=u'Vi henter by basert på postnummer')
     phone = forms.CharField(label=_("Telefon"), max_length=20, required=False)
     
     def clean(self):


Test patch:
Repository: dotkom/onlineweb4

Issue:
Active feedbacks bug
Minor bug where feedbacks where everyone answers does not get set to inactive.



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
@@ -45,7 +45,10 @@ def generate_message(feedback, logger):
 
         #return if everyone has answered
         if not not_responded:
+            feedback.active = False
+            feedback.save()
             logger.info('Everyone has answered')
+            logger.info('Feedback set to innactive')
             return message
 
         


Test patch:
Repository: dotkom/onlineweb4

Issue:
Hide attendanceevent from django admin
https://online.ntnu.no/admin/events/attendanceevent/

This view should not be used by anyone and attendance info should be edited through the event directly. 

Should be possible to hide this by removing 
`admin.site.register(AttendanceEvent, AttendanceEventAdmin)`
 in events/admin.py (untested)



Discussion:
I agree, the AttendanceEventAdmin should just be inline and does not need a place, even for dotkom, on the front page of the admin interface.


Resolving patch:
diff --git a/apps/events/admin.py b/apps/events/admin.py
--- a/apps/events/admin.py
+++ b/apps/events/admin.py
@@ -40,11 +40,6 @@ class RuleBundleInline(admin.TabularInline):
     inline_classes = ('grp-collapse grp-open',)  # style
 
 
-class AttendanceEventAdmin(admin.ModelAdmin):
-    model = AttendanceEvent
-    inlines = (AttendeeInline, RuleBundleInline)
-
-
 class AttendeeAdmin(admin.ModelAdmin):
     model = Attendee
     list_display = ('user', 'event', 'paid')
@@ -119,9 +114,9 @@ def get_form(self, request, obj=None, **kwargs):
         form.base_fields['description'].validators=[validators.MinLengthValidator(140)]
         return form
 
+
 admin.site.register(Event, EventAdmin)
 admin.site.register(Attendee, AttendeeAdmin)
-admin.site.register(AttendanceEvent, AttendanceEventAdmin)
 admin.site.register(RuleBundle, RuleBundleAdmin)
 admin.site.register(GradeRule, GradeRuleAdmin)
 admin.site.register(UserGroupRule, UserGroupRuleAdmin)


Test patch:
Repository: dotkom/onlineweb4

Issue:
Marks "delay" signup even after they expire
This isn't a critical bug, the title of this issue is somewhat misleading.

The real issue is that if I had a mark which was given February 1st, and I was looking at event details for an event that has signups in april. My attendance would show up as "delayed due to marks". This isn't actually the case, my signup won't be delayed because the mark will have expired before signups open.

Right now I have this case going for me with the signups to "Studenterhytta", where signups open April 1st, and my mark expires March 30th.

This means that marks would need a new way to fetch active marks, not only based on "now", but the ability to filter on a date in the future as well, such as the date signups start, and that date will be deciding which marks are active.

Another potential case here is that if a user was given two marks in the same day. If both marks expired the day after a signup would open, the user would be able to signup with only 1 day delay, even though it should have been two, since the marks aren't active any more. I'm not sure this qualifies as a situation we should take into consideration, mostly because the marks are expired and the user is out of punishment, but the signups were inside the punishment period, and should possibly still count for that signup?

The first case is a bad interface mechanic that isn't a real issue, it just feeds misinformation and should be fixed. The second case is just something to have at the back of our heads.



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
@@ -140,12 +140,17 @@ def is_eligible_for_signup(self, user):
                 return response
         
         # Do I have any marks that postpone my registration date?
-        active_marks = Mark.active.filter(given_to = user).count()
-        if active_marks > 0:
+        active_marks = Mark.active.filter(given_to = user)
+        num_active_marks = active_marks.count()
+
+        if num_active_marks > 0:
             # Offset is currently 1 day per mark. 
-            mark_offset = timedelta(days=active_marks)
+            mark_offset = timedelta(days=num_active_marks)
             postponed_registration_start = self.attendance_event.registration_start + mark_offset
-            if postponed_registration_start > timezone.now():
+
+            before_expiry = self.attendance_event.registration_start.date() < active_marks.aggregate(models.Max('expiration_date'))['expiration_date__max']
+
+            if postponed_registration_start > timezone.now() and before_expiry:
                 if 'offset' in response and response['offset'] < postponed_registration_start or 'offset' not in response:    
                     response['status'] = False
                     response['status_code'] = 401


Test patch: