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

Issue:
Auth templates does not use crispy forms
https://github.com/dotKom/onlineweb4/commit/26ae7847c2907895e6842061a848a2c0f47090a0

Håvard did some weird shit. Undo this and test that it still works.



Discussion:
I'll fix it.


Resolving patch:
diff --git a/apps/authentication/forms.py b/apps/authentication/forms.py
--- a/apps/authentication/forms.py
+++ b/apps/authentication/forms.py
@@ -82,7 +82,6 @@ class RecoveryForm(forms.Form):
     email = forms.EmailField(label="Email", max_length=50)
 
 class ChangePasswordForm(forms.Form):
-    old_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label="Old password", required=False)
     new_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label="New password")
     repeat_password = forms.CharField(widget=forms.PasswordInput(render_value=False), label="Repeat new password")
 
diff --git a/apps/authentication/urls.py b/apps/authentication/urls.py
--- a/apps/authentication/urls.py
+++ b/apps/authentication/urls.py
@@ -6,7 +6,7 @@
     url(r'^login/$', 'login', name='auth_login'),
     url(r'^logout/$', 'logout', name='auth_logout'),
     url(r'^register/$', 'register', name='auth_register'),
-    url(r'^verify/(\w+)/$', 'verify', name='auth_verify'),
+    url(r'^verify/(?P<token>\w+)/$', 'verify', name='auth_verify'),
     url(r'^recover/$', 'recover', name='auth_recover'),
-    url(r'^set_password/(\w+)/$', 'set_password', name='auth_set_password'),
+    url(r'^set_password/(?P<token>\w+)/$', 'set_password', name='auth_set_password'),
 )


Test patch:
Repository: dotkom/onlineweb4

Issue:
Registering user messes up values of address and zip code
For example trying to register with the zip code 1234 will add the value (u'1234',) to the database. Exact same thing with address. 

This also causes the zip code to go over the 4 character limit which again causes the database (if it's not SQLite) to throw an error. 



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,9 +54,9 @@ def register(request):
                     email=cleaned['email'].lower(),
                 )
                 # Set remaining fields
-                user.phone=cleaned['phone'],
-                user.address=cleaned['address'].title(),
-                user.zip_code=cleaned['zip_code'],
+                user.phone=cleaned['phone']
+                user.address=cleaned['address'].title()
+                user.zip_code=cleaned['zip_code']
                 # Store password properly
                 user.set_password(cleaned['password'])
                 # Users need to be manually activated


Test patch:
Repository: dotkom/onlineweb4

Issue:
Registering with an existing e-mail creates the user
When registering:

Choose a username
Enter an email-adresse already in use.
The user will be created, and your chosen username will be taken!

Registering with an existing e-mail creates the user
When registering:

Choose a username
Enter an email-adresse already in use.
The user will be created, and your chosen username will be taken!



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
@@ -7,7 +7,7 @@
 from django.contrib import auth
 from django.utils.translation import ugettext as _
 
-from apps.authentication.models import OnlineUser as User
+from apps.authentication.models import OnlineUser as User, Email
 
 class LoginForm(forms.Form):
     username = forms.CharField(widget=forms.TextInput(), label=_("Brukernavn"), max_length=50)
@@ -69,7 +69,7 @@ def clean(self):
 
             # Check email
             email = cleaned_data['email']
-            if User.objects.filter(email=email).count() > 0:
+            if Email.objects.filter(email=email).count() > 0:
                 self._errors['email'] = self.error_class([_(u"Det fins allerede en bruker med denne epostadressen.")])
 
             # ZIP code digits only


Test patch:
Repository: dotkom/onlineweb4

Issue:
All strings should be unicode
I'm quite sure there are some strings still missing the u. Should have a look at this as it can cause trouble. 



Discussion:
Assigning to @hernil 


Resolving patch:
diff --git a/apps/authentication/models.py b/apps/authentication/models.py
--- a/apps/authentication/models.py
+++ b/apps/authentication/models.py
@@ -133,9 +133,9 @@ class Meta:
 
 class RegisterToken(models.Model):
     user = models.ForeignKey(OnlineUser, related_name="register_user")
-    email = models.EmailField(_("epost"), max_length=254)
-    token = models.CharField(_("token"), max_length=32)
-    created = models.DateTimeField(_("opprettet dato"), editable=False, auto_now_add=True, default=datetime.datetime.now())
+    email = models.EmailField(_(u"epost"), max_length=254)
+    token = models.CharField(_(u"token"), max_length=32)
+    created = models.DateTimeField(_(u"opprettet dato"), editable=False, auto_now_add=True, default=datetime.datetime.now())
 
     @property
     def is_valid(self):
@@ -162,6 +162,6 @@ def __unicode__(self):
         return self.username
 
     class Meta:
-        verbose_name = _("tillatt brukernavn")
-        verbose_name_plural = _("tillatte brukernavn")
-        ordering = ("username",)
+        verbose_name = _(u"tillatt brukernavn")
+        verbose_name_plural = _(u"tillatte brukernavn")
+        ordering = (u"username",)


Test patch:
Repository: dotkom/onlineweb4

Issue:
Article archive should just list tags that are used
IMO, tags that are not used in any articles should not be listed in the tagcloud.

Feels unnecessary to have them there.



Discussion:

Resolving patch:
diff --git a/apps/article/views.py b/apps/article/views.py
--- a/apps/article/views.py
+++ b/apps/article/views.py
@@ -109,9 +109,8 @@ def archive(request, name=None, slug=None, year=None, month=None):
         articles = filtered
 
     # Get the 30 most used tags, then randomize them
-    tags = list(Tag.objects.all())
-    tags.sort(key=lambda x: x.frequency, reverse=True)
-    tags = tags[:30]
+    tags = Tag.objects.filter(article_tags__isnull=False).distinct().annotate(num_tags=Count('article_tags__tag')).order_by('-num_tags')
+    tags = list(tags[:30])
     random.shuffle(tags)
     # Get max frequency of tags. This is used for relative sizing in the tag cloud.
     try:


Test patch:
Repository: dotkom/onlineweb4

Issue:
It is possible to add an incomplete attendance option in new event in admin panel
I tried to create a new event with attendance option through the inline field.
I was able to save the event with a dummy attendance with no deadline or other options, resulting in a db-error while trying to re-access the event in the admin panel.



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
@@ -393,10 +393,10 @@ class AttendanceEvent(models.Model):
         primary_key=True,
         related_name='attendance_event')
 
-    max_capacity = models.PositiveIntegerField(_(u'maks-kapasitet'))
+    max_capacity = models.PositiveIntegerField(_(u'maks-kapasitet'), null=False, blank=False)
     waitlist = models.BooleanField(_(u'venteliste'), default=False)
-    registration_start = models.DateTimeField(_(u'registrerings-start'))
-    registration_end = models.DateTimeField(_(u'registrerings-slutt'))
+    registration_start = models.DateTimeField(_(u'registrerings-start'), null=False, blank=False)
+    registration_end = models.DateTimeField(_(u'registrerings-slutt'), null=False, blank=False)
 
     #Access rules
     rule_bundles = models.ManyToManyField(RuleBundle, blank=True, null=True)


Test patch:
Repository: dotkom/onlineweb4

Issue:
Trying to set primary e-mail in profile causes 500 server error
Traceback:
File "/usr/local/pythonenv/ow4beta/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
1.                         response = callback(request, _callback_args, *_callback_kwargs)
   File "/usr/local/pythonenv/ow4beta/lib/python2.7/site-packages/django/contrib/auth/decorators.py" in _wrapped_view
2.                 return view_func(request, _args, *_kwargs)
   File "/var/www/ow4beta/apps/profiles/views.py" in set_primary
3.             primary_email = request.user.get_email()
   File "/var/www/ow4beta/apps/authentication/models.py" in get_email
4.         return self.get_emails().filter(primary = True)[0]
   File "/usr/local/pythonenv/ow4beta/lib/python2.7/site-packages/django/db/models/query.py" in **getitem**
5.             return list(qs)[0]

Exception Type: IndexError at /profile/set_primary/
Exception Value: list index out of range
Request information:
GET: No GET data

POST:
email = u'aleksans@stud.ntnu.no'



Discussion:

Resolving patch:
diff --git a/apps/profiles/views.py b/apps/profiles/views.py
--- a/apps/profiles/views.py
+++ b/apps/profiles/views.py
@@ -320,14 +320,19 @@ def set_primary(request):
                 return HttpResponse(status=412, content=json.dumps(
                                                     {'message': _(u"%s er allerede satt som primær-epostaddresse.") % email.email}
                                                 ))
-            
-            # Deactivate old primary email
-            primary_email = request.user.get_email()
-            primary_email.primary = False
-            primary_email.save()
-            # Activate new primary
-            email.primary = True
-            email.save()
+
+            #Hack for develop branch where user is created with createsuperuser
+            try:
+                # Deactivate old primary email
+                primary_email = request.user.get_email()
+                primary_email.primary = False
+                primary_email.save()
+            except:
+                pass
+            finally:
+                # Activate new primary
+                email.primary = True
+                email.save()
 
             return HttpResponse(status=200)
     return HttpResponse(status=404)


Test patch:
Repository: dotkom/onlineweb4

Issue:
Create a separate branch containing the wiki, remove from develop



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
@@ -168,15 +168,6 @@
     'apps.feedback',
     'apps.mommy',
     'apps.profiles',
-    
-    # Wiki-related stuff
-    'wiki',
-    'wiki.plugins.attachments',
-    'wiki.plugins.notifications',
-    'wiki.plugins.images',
-    'wiki.plugins.macros',    
-
-    #'pizzasystem',
 )
 
 # A sample logging configuration. The only tangible logging
diff --git a/onlineweb4/urls.py b/onlineweb4/urls.py
--- a/onlineweb4/urls.py
+++ b/onlineweb4/urls.py
@@ -53,11 +53,8 @@
     # Online Notifier Owner Verification (checked yearly or so by Google)
     url(r'^google79c0b331a83a53de\.html$', lambda r: HttpResponse(
         "google-site-verification: google79c0b331a83a53de.html", mimetype="text/html")),
-    
-    # Wiki
-    (r'^notify/', get_notify_pattern()),
-    url(r'^wiki/', get_wiki_pattern()),
 )
+
 # pizzasystem
 if 'pizzasystem' in settings.INSTALLED_APPS:
     urlpatterns += patterns('', url(r'^pizza/', include('pizzasystem.urls')))


Test patch:
Repository: dotkom/onlineweb4

Issue:
Create a separate branch containing the wiki, remove from develop



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
@@ -131,10 +131,6 @@
     'django.contrib.humanize',
     'django_nose',
     'south',
-    'django_notify',
-    'mptt',
-    'sekizai',
-    'sorl.thumbnail',
     'grappelli',
     'filebrowser',
     'chunks',
@@ -232,7 +228,6 @@
     "django.core.context_processors.static",
     "django.core.context_processors.tz",
     "django.contrib.messages.context_processors.messages",
-    "sekizai.context_processors.sekizai",
 )
 
 # Remember to keep 'local' last, so it can override any setting.
diff --git a/onlineweb4/urls.py b/onlineweb4/urls.py
--- a/onlineweb4/urls.py
+++ b/onlineweb4/urls.py
@@ -3,11 +3,8 @@
 from django.contrib.staticfiles.urls import staticfiles_urlpatterns
 from django.contrib import admin
 from django.http import HttpResponse
-from django_notify.urls import get_pattern as get_notify_pattern
 from django.views.generic import TemplateView
 
-from wiki.urls import get_pattern as get_wiki_pattern
-
 from apps import mommy
 
 from filebrowser.sites import site


Test patch:
Repository: dotkom/onlineweb4

Issue:
Sort list of users when adding marks
When adding a mark, the list of user which the mark should relate to is not sorted. It should be. (It is probably sorted on realname instead of username)
- Change the list to display realname instead of username.
- Make sure it's sorted.

(Bonus would be to have a select2js-ish search on it as well, but don't use time on it.)



Discussion:
Tried to make the unicode in user return full name instead of username. This didnt really change anything, and it's still username in the dropdown.


Resolving patch:
diff --git a/apps/authentication/models.py b/apps/authentication/models.py
--- a/apps/authentication/models.py
+++ b/apps/authentication/models.py
@@ -116,6 +116,7 @@ def __unicode__(self):
         return self.get_full_name()
 
     class Meta:
+        ordering = ['first_name', 'last_name']
         verbose_name = _(u"brukerprofil")
         verbose_name_plural = _(u"brukerprofiler")
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Mark rules error for anonymous users on events
'AnonymousUser' object has no attribute 'mark_rules'



Discussion:

Resolving patch:
diff --git a/apps/events/forms.py b/apps/events/forms.py
--- a/apps/events/forms.py
+++ b/apps/events/forms.py
@@ -6,7 +6,7 @@ def __init__(self, *args, **kwargs):
         user = kwargs.pop('user', None)
         super(CaptchaForm, self).__init__(*args, **kwargs)
         # Removing mark rules field if user has already accepted the rules
-        if user and  user.mark_rules:
+        if user and user.is_authenticated() and user.mark_rules:
             del self.fields['mark_rules']
     mark_rules = forms.BooleanField(label=u'Jeg godtar <a href="/profile/#marks" target="_blank">prikkreglene</a>')
     captcha = CaptchaField()


Test patch:
Repository: dotkom/onlineweb4

Issue:
"Startet studie" in Profile -> Medlemskap requires defined format without specifying it
"Started studie" is a datefield. The problem is that most browsers (like FF, Chrome) don't render these fields with any additional tools which makes filling them out a pain in the ass (Safari@iOS has that fancy datepicker-shit).

The field requires the format 'yyyy-mm-dd', but does not specify this anywhere. This should be fixed somehow.



Discussion:

Resolving patch:
diff --git a/apps/profiles/forms.py b/apps/profiles/forms.py
--- a/apps/profiles/forms.py
+++ b/apps/profiles/forms.py
@@ -61,3 +61,7 @@ def __init__(self, *args, **kwargs):
     class Meta:
         model = OnlineUser
         fields = ['field_of_study', 'started_date', ]
+
+        widgets = {
+            'started_date' : forms.TextInput(attrs={'placeholder' : 'YYYY-MM-DD'}),
+        }


Test patch:
Repository: dotkom/onlineweb4

Issue:
(Event) Mark rules check does not consider previous acceptance
If a user has already accepted the mark rules, they are hidden from the signup form, but it isn't considered when the form is validated.



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
@@ -432,7 +432,6 @@ def rules_satisfied(self, user):
             responses.extend(rule_bundle.satisfied(user, self.registration_start))
         
         for response in responses:
-            print response
             if response['status']:
                 return response
             elif 'offset' in response:
diff --git a/apps/events/views.py b/apps/events/views.py
--- a/apps/events/views.py
+++ b/apps/events/views.py
@@ -90,7 +90,7 @@ def attendEvent(request, event_id):
     form = CaptchaForm(request.POST, user=request.user)
 
     if not form.is_valid():
-        if not 'mark_rules' in request.POST:
+        if not 'mark_rules' in request.POST and not request.user.mark_rules:
             error_message = u'Du må godta prikkreglene for å melde deg på.'
         else:
             error_message = u'Du klarte ikke captcha-en. Er du en bot?'
@@ -101,9 +101,9 @@ def attendEvent(request, event_id):
     # If not, an error message will be present in the returned dict
     attendance_event = event.attendance_event
 
-    user_eligible = event.is_eligible_for_signup(request.user);
+    response = event.is_eligible_for_signup(request.user);
 
-    if user_eligible['status']:   
+    if response['status']:   
         # First time accepting mark rules
         if 'mark_rules' in form.cleaned_data:
             request.user.mark_rules = True
@@ -112,7 +112,7 @@ def attendEvent(request, event_id):
         messages.success(request, _(u"Du er nå påmeldt på arrangementet!"))
         return redirect(event)
     else:
-        messages.error(request, user_eligible['message'])
+        messages.error(request, response['message'])
         return redirect(event)
 
 @login_required


Test patch:
Repository: dotkom/onlineweb4

Issue:
API should not show marks publicly
The API shows all marks for all users publicly. Should be unregistered from API if it is not utterly necessary by some client-side ajax call.



Discussion:
Shouldn't marks be removed from the entire api?

We do not need api-methods for this as far as I can see.

It is not necessary to remove the modelresource from the API. If we later on convert the entire site to an API based approach with full authentication/authorization, we would just have to rewrite the code.

By not registering the modelresource to the API, other resources can still use it, even though it is not available publicly.

As of now, there are no uses for marks in the API.

I have no idea how to prevent the methods from being public or open.

I am guessing you don't want people to be able to "guess" the endpoint either?

You don't need to guess the endpoint.

http://moonshine.online.ntnu.no/api/v0/?format=json

That will give you a complete overview of all the public endpoints of the api.


Resolving patch:
diff --git a/apps/api/v0/urls.py b/apps/api/v0/urls.py
--- a/apps/api/v0/urls.py
+++ b/apps/api/v0/urls.py
@@ -26,10 +26,10 @@
 v0_api.register(ArticleLatestResource())
 
 # marks
-v0_api.register(MarkResource())
-v0_api.register(EntryResource())
-v0_api.register(MyMarksResource())
-v0_api.register(MyActiveMarksResource())
+#v0_api.register(MarkResource())
+#v0_api.register(EntryResource())
+#v0_api.register(MyMarksResource())
+#v0_api.register(MyActiveMarksResource())
 
 # offline
 v0_api.register(IssueResource())


Test patch:
Repository: dotkom/onlineweb4

Issue:
Featured careeropprotunities are not featured
The featured opportunities are not prioritized over other opportunities. 



Discussion:

Resolving patch:
diff --git a/apps/careeropportunity/views.py b/apps/careeropportunity/views.py
--- a/apps/careeropportunity/views.py
+++ b/apps/careeropportunity/views.py
@@ -13,7 +13,7 @@
 
 def index(request):
     opportunities = CareerOpportunity.objects.filter(
-    	start__lte=timezone.now(), end__gte=timezone.now()).order_by('featured', '-start')
+    	start__lte=timezone.now(), end__gte=timezone.now()).order_by('-featured', '-start')
     
     return render_to_response('careeropportunity/index.html', \
             {'opportunities': opportunities}, \


Test patch:
Repository: dotkom/onlineweb4

Issue:
Add Google Analytics to base
Add a GOOGLE_ANALYTICS_KEY variable to local.py, then check if GOOGLE_ANALYTICS_KEY is true in the template and then include the javascript.

(Edited by lizter since the original ticket was utter rubbish.)



Discussion:
Enable? ... This is a big job, and is definitely something we could put in the dashboard, which will put it in the future milestone, imo?

What...stats?

Google Analytics?

I mean stats as in Google Analytics or something similar. No need for this to be in a user accessible dashboard. 

Haha, ticket of the year.

http://stackoverflow.com/questions/18992324/redesigning-an-existing-website-should-i-create-a-new-google-analytics-property

Should be considered when we release.

Regarding this, @lizter pointed out that there is no context to parse for api keys etc.

Either we need a small view to handle the rendering of front page, or it could be implemented with a middleware.


Resolving patch:
diff --git a/onlineweb4/context_processors.py b/onlineweb4/context_processors.py
new file mode 100644
--- /dev/null
+++ b/onlineweb4/context_processors.py
@@ -0,0 +1,7 @@
+from django.conf import settings
+
+def analytics(request):
+	context_extras = {}
+	if hasattr(settings, 'GOOGLE_ANALYTICS_KEY'):
+		context_extras['GOOGLE_ANALYTICS_KEY'] = settings.GOOGLE_ANALYTICS_KEY
+	return context_extras
diff --git a/onlineweb4/settings/base.py b/onlineweb4/settings/base.py
--- a/onlineweb4/settings/base.py
+++ b/onlineweb4/settings/base.py
@@ -228,6 +228,7 @@
     "django.core.context_processors.static",
     "django.core.context_processors.tz",
     "django.contrib.messages.context_processors.messages",
+    "onlineweb4.context_processors.analytics",
 )
 
 # Remember to keep 'local' last, so it can override any setting.
diff --git a/onlineweb4/settings/example-local.py b/onlineweb4/settings/example-local.py
--- a/onlineweb4/settings/example-local.py
+++ b/onlineweb4/settings/example-local.py
@@ -44,6 +44,8 @@
 #EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'  # real
 EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'  # prints
 
+# GOOGLE_ANALYTICS_KEY = 'UA-XXXX-Y'
+
 #MEDIA_ROOT = '/var/websites/prod/onlineweb_uploads'
 MEDIA_ROOT = os.path.join(PROJECT_ROOT_DIRECTORY, "uploaded_media/")
 


Test patch:
Repository: dotkom/onlineweb4

Issue:
Make offline archive look more like event archive
Same as #481. This is mainly about the filtering section.



Discussion:
I will fix this


Resolving patch:
diff --git a/apps/api/v0/article.py b/apps/api/v0/article.py
--- a/apps/api/v0/article.py
+++ b/apps/api/v0/article.py
@@ -17,7 +17,7 @@
 
 
 class ArticleResource(ModelResource):
-    author = fields.ToOneField(UserResource, 'created_by')
+    author = fields.ToOneField(UserResource, 'created_by', full=True)
     
     def alter_list_data_to_serialize(self, request, data):
         # Renames list data 'object' to 'articles'.


Test patch:
Repository: dotkom/onlineweb4

Issue:
UserResource in API should not display last login date publicly
Somewhat sensitive information...



Discussion:

Resolving patch:
diff --git a/apps/api/v0/authentication.py b/apps/api/v0/authentication.py
--- a/apps/api/v0/authentication.py
+++ b/apps/api/v0/authentication.py
@@ -11,4 +11,4 @@ class UserResource(ModelResource):
     class Meta:
         queryset = User.objects.all()
         resource_name = 'user'
-        fields = ['username', 'first_name', 'last_name', 'last_login', 'email', ]
+        fields = ['username', 'first_name', 'last_name', 'email', ]


Test patch:
Repository: dotkom/onlineweb4

Issue:
Viewing profile when not logging in produces error instead of redirect to login
You should be redirected to login when trying to view a page that requires login.

Use the login_required decorator in django for this.



Discussion:
Something recently must have broken this, I tested this a while ago.


Resolving patch:
diff --git a/apps/profiles/views.py b/apps/profiles/views.py
--- a/apps/profiles/views.py
+++ b/apps/profiles/views.py
@@ -24,6 +24,7 @@
 Index for the entire user profile view
 Methods redirect to this view on save
 """
+@login_required
 def index(request):
 
     """


Test patch: