internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: kartoza/prj.app

Issue:
500 on bad certificate number
# Problem

When I try and add a bad certificate number, then I get a 500, I should get a 404.
See:
http://staging.changelog.qgis.org/en/qgis/certificate/0246242/

# Proposed Solution

Return a 404


Discussion:

Resolving patch:
diff --git a/django_project/certification/views/certificate.py b/django_project/certification/views/certificate.py
--- a/django_project/certification/views/certificate.py
+++ b/django_project/certification/views/certificate.py
@@ -93,10 +93,15 @@ def get_context_data(self, **kwargs):
         """
 
         self.certificateID = self.kwargs.get('id', None)
+        self.project_slug = self.kwargs.get('project_slug', None)
         context = super(
             CertificateDetailView, self).get_context_data(**kwargs)
-        context['certificate'] = \
-            Certificate.objects.get(certificateID=self.certificateID)
+        issued_id = \
+            Certificate.objects.all().values_list('certificateID', flat=True)
+        if self.certificateID in issued_id:
+            context['certificate'] = \
+                Certificate.objects.get(certificateID=self.certificateID)
+        context['project_slug'] = self.project_slug
         return context
 
     def get_queryset(self):
@@ -126,8 +131,10 @@ def get_object(self, queryset=None):
             queryset = self.get_queryset()
             certificateID = self.kwargs.get('id', None)
             if certificateID:
-                obj = queryset.get(
-                    certificateID=certificateID)
-                return obj
+                try:
+                    obj = queryset.get(certificateID=certificateID)
+                    return obj
+                except Certificate.DoesNotExist:
+                    return None
             else:
                 raise Http404('Sorry! Certificate by this ID is not exist.')


Test patch:
Repository: kartoza/prj.app

Issue:
who is bob123?
# Problem

It is not easy to know who the user is by username, let's rather use the Human name.

# Proposed Solution 

We should rather display Bob Smith than bob123 when selecting users.


Discussion:
Please see the certificate

Resolving patch:
diff --git a/django_project/certification/forms.py b/django_project/certification/forms.py
--- a/django_project/certification/forms.py
+++ b/django_project/certification/forms.py
@@ -149,6 +149,8 @@ def __init__(self, *args, **kwargs):
         self.helper.layout = layout
         self.helper.html5_required = False
         super(CourseConvenerForm, self).__init__(*args, **kwargs)
+        self.fields['user'].label_from_instance = \
+            lambda obj: "%s <%s>" % (obj.get_full_name(), obj)
         self.helper.add_input(Submit('submit', 'Submit'))
 
     def save(self, commit=True):
@@ -282,6 +284,8 @@ def __init__(self, *args, **kwargs):
         self.fields['course_convener'].queryset = \
             CourseConvener.objects.filter(
                 certifying_organisation=self.certifying_organisation)
+        self.fields['course_convener'].label_from_instance = \
+            lambda obj: "%s <%s>" % (obj.user.get_full_name(), obj)
         self.fields['course_type'].queryset = \
             CourseType.objects.filter(
                 certifying_organisation=self.certifying_organisation)
diff --git a/django_project/certification/views/certificate.py b/django_project/certification/views/certificate.py
--- a/django_project/certification/views/certificate.py
+++ b/django_project/certification/views/certificate.py
@@ -178,7 +178,9 @@ def certificate_pdf_view(request, **kwargs):
     p.drawString(
         290, 250, 'Course Date: %s - %s'
                   % (course.start_date, course.end_date))
-    p.drawString(290, 220, 'Convener: %s' % course.course_convener.user)
+    p.drawString(290, 220, 'Convener: %s %s' % (
+        course.course_convener.user.first_name,
+        course.course_convener.user.last_name))
     p.setFillColorRGB(0.1, 0.1, 0.1)
     p.drawCentredString(
         center, 170, 'Presented by %s at %s' % (


Test patch:
Repository: kartoza/prj.app

Issue:
After creating a new organization it should appear in the pending approval menu
Please make sure if a user adds an organization the Pending Approval menu is updated

http://staging.changelog.qgis.org/en/qgis/pending-certifyingorganisation/list/


Discussion:
@pcav for cc

Resolving patch:
diff --git a/django_project/core/custom_middleware.py b/django_project/core/custom_middleware.py
--- a/django_project/core/custom_middleware.py
+++ b/django_project/core/custom_middleware.py
@@ -5,6 +5,7 @@
 """
 from base.models import Project, Version
 from changes.models import Category, SponsorshipLevel, SponsorshipPeriod, Entry
+from certification.models import CertifyingOrganisation
 
 
 class NavContextMiddleware(object):
@@ -48,6 +49,9 @@ def process_template_response(request, response):
             context['has_pending_sponsor_period'] = (
                 SponsorshipPeriod.unapproved_objects.filter(
                     project=context.get('project')).exists())
+            context['has_pending_organisations'] = (
+                CertifyingOrganisation.unapproved_objects.filter(
+                    project=context.get('project')).exists())
             if versions:
                 context['has_pending_entries'] = (
                     Entry.unapproved_objects.filter(


Test patch:
Repository: kartoza/prj.app

Issue:
fix add/edit course page style
this issue is fixed in PR #453 


Discussion:

Resolving patch:
diff --git a/django_project/certification/forms.py b/django_project/certification/forms.py
--- a/django_project/certification/forms.py
+++ b/django_project/certification/forms.py
@@ -275,8 +275,8 @@ def __init__(self, *args, **kwargs):
                 Field('course_convener',
                       css_class='form-control chosen-select'),
                 Field('training_center', css_class='form-control'),
-                Field('start_date'),
-                Field('end_date'),
+                Field('start_date', css_class='datepicker-here'),
+                Field('end_date', css_class='datepicker-here'),
             )
         )
         self.helper.layout = layout
diff --git a/django_project/certification/views/certifying_organisation.py b/django_project/certification/views/certifying_organisation.py
--- a/django_project/certification/views/certifying_organisation.py
+++ b/django_project/certification/views/certifying_organisation.py
@@ -20,7 +20,8 @@
     TrainingCenter,
     CourseType,
     CourseConvener,
-    Course)
+    Course,
+    Attendee)
 from ..forms import CertifyingOrganisationForm
 
 
@@ -203,6 +204,9 @@ def get_context_data(self, **kwargs):
             certifying_organisation=certifying_organisation)
         context['num_course'] = context['courses'].count()
         project_slug = self.kwargs.get('project_slug', None)
+        context['attendee'] = Attendee.objects.filter(
+            certifying_organisation=certifying_organisation)
+        context['num_attendees'] = context['attendee'].count()
         context['project_slug'] = project_slug
         if project_slug:
             context['the_project'] = Project.objects.get(slug=project_slug)


Test patch:
Repository: kartoza/prj.app

Issue:
type to search course convener



Discussion:

Resolving patch:
diff --git a/django_project/certification/forms.py b/django_project/certification/forms.py
--- a/django_project/certification/forms.py
+++ b/django_project/certification/forms.py
@@ -144,7 +144,7 @@ def __init__(self, *args, **kwargs):
         layout = Layout(
             Fieldset(
                 form_title,
-                Field('user', css_class='form-control'),)
+                Field('user', css_class='form-control chosen-select'),)
         )
         self.helper.layout = layout
         self.helper.html5_required = False
@@ -270,7 +270,8 @@ def __init__(self, *args, **kwargs):
             Fieldset(
                 form_title,
                 Field('course_type', css_class='form-control'),
-                Field('course_convener', css_class='form-control'),
+                Field('course_convener',
+                      css_class='form-control chosen-select'),
                 Field('training_center', css_class='form-control'),
                 Field('start_date'),
                 Field('end_date'),
@@ -312,7 +313,7 @@ def __init__(self, *args, **kwargs):
         layout = Layout(
             Fieldset(
                 form_title,
-                Field('attendee', css_class='form-control'),
+                Field('attendee', css_class='form-control chosen-select'),
             )
         )
         self.helper.layout = layout


Test patch:
Repository: kartoza/prj.app

Issue:
Certificate URL needs to include domain
See the url below - it is not useful since it does not specify a domain.

<img width="1285" alt="screen shot 2017-07-24 at 10 52 15 pm" src="https://user-images.githubusercontent.com/178003/28544268-e2f26940-70c2-11e7-8d08-d4c39b466600.png">



Discussion:

Resolving patch:
diff --git a/django_project/certification/views/certificate.py b/django_project/certification/views/certificate.py
--- a/django_project/certification/views/certificate.py
+++ b/django_project/certification/views/certificate.py
@@ -153,6 +153,7 @@ def certificate_pdf_view(request, **kwargs):
     course = Course.objects.get(slug=course_slug)
     attendee = Attendee.objects.get(pk=pk)
     certificate = Certificate.objects.get(course=course, attendee=attendee)
+    current_site = request.META['HTTP_HOST']
 
     # Create the HttpResponse object with the appropriate PDF headers.
     response = HttpResponse(content_type='application/pdf')
@@ -278,8 +279,9 @@ def certificate_pdf_view(request, **kwargs):
     page.setFont('Times-Roman', 8)
     page.drawString(
         margin_left, (margin_bottom - 20),
-        'You can verify this certificate by visiting /%s/certificate/%s/.'
-        % (project.slug, certificate.certificateID))
+        'You can verify this certificate by visiting '
+        'http://%s/en/%s/certificate/%s/.'
+        % (current_site, project.slug, certificate.certificateID))
 
     # Close the PDF object cleanly.
     page.showPage()


Test patch:
Repository: kartoza/prj.app

Issue:
Warning the domain name provided is not valid
I am getting lots of errors sent to me from the site like this:


```
Invalid HTTP_HOST header: u':8080'. The domain name provided is not valid according to RFC 1034/1035.

Request repr(): 
<WSGIRequest
path:/,
GET:<QueryDict: {}>,
POST:<QueryDict: {}>,
COOKIES:{},
META:{'CONTENT_LENGTH': '',
'CONTENT_TYPE': '',
'DOCUMENT_ROOT': '/etc/nginx/html',
'PATH_INFO': u'/',
'QUERY_STRING': '',
'REMOTE_ADDR': '200.75.240.139',
'REMOTE_PORT': '3669',
'REQUEST_METHOD': 'GET',
'REQUEST_URI': '/',
u'SCRIPT_NAME': u'',
'SERVER_NAME': '',
'SERVER_PORT': '8080',
'SERVER_PROTOCOL': 'HTTP/1.0',
'uwsgi.node': 'uwsgi',
'uwsgi.version': '2.0.14',
'wsgi.errors': <open file 'wsgi_errors', mode 'w' at 0x7f1228fab660>,
'wsgi.file_wrapper': <built-in function uwsgi_sendfile>,
'wsgi.input': <uwsgi._Input object at 0x7f120fe2a4c8>,
'wsgi.multiprocess': True,
'wsgi.multithread': False,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>

```

We need to fix it so it stop spamming me :-(


Discussion:

Resolving patch:
diff --git a/django_project/core/settings/dev_docker.py b/django_project/core/settings/dev_docker.py
--- a/django_project/core/settings/dev_docker.py
+++ b/django_project/core/settings/dev_docker.py
@@ -4,6 +4,9 @@
 import os
 print os.environ
 
+ALLOWED_HOSTS = ['*',
+                 u'0.0.0.0']
+
 DATABASES = {
     'default': {
         'ENGINE': 'django.contrib.gis.db.backends.postgis',


Test patch:
Repository: kartoza/prj.app

Issue:
Certificate logos need to be rendered larger
<img width="1651" alt="screen shot 2017-07-31 at 9 02 22 am" src="https://user-images.githubusercontent.com/178003/28766753-3d9d6c24-75d1-11e7-8222-5c26ac826c7a.png">


Can you make the project and certifying organization logos bigger in the layout please? Maybe 2x vertical and horizontal?


Discussion:
@timlinux will do

Resolving patch:
diff --git a/django_project/certification/views/certificate.py b/django_project/certification/views/certificate.py
--- a/django_project/certification/views/certificate.py
+++ b/django_project/certification/views/certificate.py
@@ -193,7 +193,7 @@ def certificate_pdf_view(request, **kwargs):
     margin_right = height - 50
     margin_left = 50
     margin_bottom = 50
-    max_left = margin_right - 50
+    max_left = margin_right - 100
 
     # Draw things on the PDF. Here's where the PDF generation happens.
     # See the ReportLab documentation for the full list of functionality.
@@ -209,12 +209,12 @@ def certificate_pdf_view(request, **kwargs):
 
     if project_logo is not None:
         page.drawImage(
-            project_logo, 50, 500, width=50, height=50,
+            project_logo, 50, 450, width=100, height=100,
             preserveAspectRatio=True, mask='auto')
 
     if organisation_logo is not None:
         page.drawImage(
-            organisation_logo, max_left, 500, height=50, width=50,
+            organisation_logo, max_left, 450, height=100, width=100,
             preserveAspectRatio=True, anchor='c', mask='auto')
 
     page.setFont('Times-Bold', 26)


Test patch:
Repository: kartoza/prj.app

Issue:
organisation owner who is not staff cannot add new attendees
# Problem
The user who is an organisation owner cannot see the add new attendees button and edit course.

# Solution
Update the page so the organisation owner can see the them.


Discussion:

Resolving patch:
diff --git a/django_project/certification/views/certifying_organisation.py b/django_project/certification/views/certifying_organisation.py
--- a/django_project/certification/views/certifying_organisation.py
+++ b/django_project/certification/views/certifying_organisation.py
@@ -473,7 +473,7 @@ def get_queryset(self):
         if self.request.user.is_staff:
             return qs
         else:
-            return qs.filter(creator=self.request.user)
+            return qs.filter(organisation_owners=self.request.user)
 
     def get_success_url(self):
         """Define the redirect URL.
diff --git a/django_project/certification/views/course.py b/django_project/certification/views/course.py
--- a/django_project/certification/views/course.py
+++ b/django_project/certification/views/course.py
@@ -120,16 +120,15 @@ def get_context_data(self, **kwargs):
 
     def get_queryset(self):
         """Get the queryset for this view.
+            In front end, only staff, organisation owners and course convener
+            can see the edit button.
 
         :returns: All Course objects
         :rtype: QuerySet
         """
 
         qs = Course.objects.all()
-        if self.request.user.is_staff:
-            return qs
-        else:
-            return qs.filter(creator=self.request.user)
+        return qs
 
     def get_success_url(self):
         """Define the redirect URL.


Test patch:
Repository: kartoza/prj.app

Issue:
Course name
Currently the course name is quite long, i.e. XProject_QGIS Introduction_2017-07-05-2017-07-19 

Would it be better if we can have a shorter course name, i.e. QGIS Introduction 101?
What do you think @timlinux ?


Discussion:

Resolving patch:
diff --git a/django_project/certification/models/certifying_organisation.py b/django_project/certification/models/certifying_organisation.py
--- a/django_project/certification/models/certifying_organisation.py
+++ b/django_project/certification/models/certifying_organisation.py
@@ -74,7 +74,7 @@ def validate_email_address(value):
         return False
 
 
-class CertifyingOrganisation(SlugifyingMixin, models.Model):
+class CertifyingOrganisation(models.Model):
     """Certifying organisation model."""
 
     name = models.CharField(
@@ -145,6 +145,15 @@ class Meta:
         unique_together = ['name', 'project']
 
     def save(self, *args, **kwargs):
+        if not self.pk:
+            words = self.name.split()
+            filtered_words = [word for word in words if
+                              word.lower() not in STOP_WORDS]
+            # unidecode() represents special characters (unicode data) in ASCII
+            new_list = \
+                self.project.slug + ' ' + \
+                unidecode(' '.join(filtered_words))
+            self.slug = slugify(new_list)[:50]
         super(CertifyingOrganisation, self).save(*args, **kwargs)
 
     def __unicode__(self):


Test patch:
Repository: kartoza/prj.app

Issue:
Incorect links generated by http://changelog.inasafe.org/en/
## Issue

Certificate links generated incorrectly
Example: http://changelog.kartoza.com/en/inasafe/certificate/InaSAFE-14/

## Solution
Certificate links should be generated as http://changelog.inasafe.org/en/inasafe/certifyingorganisation/kartoza/course/inasafe_inasafe-for-drr_2017-07-03-2017-07-07/print/2/


Discussion:

Resolving patch:
diff --git a/django_project/certification/views/certificate.py b/django_project/certification/views/certificate.py
--- a/django_project/certification/views/certificate.py
+++ b/django_project/certification/views/certificate.py
@@ -4,7 +4,6 @@
 import zipfile
 from django.http import Http404, HttpResponse, HttpResponseRedirect
 from django.views.generic import CreateView, DetailView
-from django.contrib.sites.models import Site
 from django.core.mail import send_mail
 from django.core.urlresolvers import reverse
 from django.db import IntegrityError
@@ -98,12 +97,10 @@ def form_valid(self, form):
 
         try:
             super(CertificateCreateView, self).form_valid(form)
-            certificate_id = form.instance.certificateID
+            pk = self.attendee.pk
+            site = self.request.get_host()
 
             # Send email to the attendee when the certificate is issued.
-            if Site._meta.installed:
-                site = Site.objects.get_current().domain
-
             send_mail(
                 'Certificate from %s Course' % self.course.course_type,
                 'Dear %s %s,\n\n' % (
@@ -117,13 +114,16 @@ def form_valid(self, form):
                     self.course.end_date.strftime('%d %B %Y')) +
                 'Training center: %s\n' % self.course.training_center +
                 'Certifying organisation: %s\n\n'
-                % self.course.certifying_organisation +
-                'You may check the full details of the certificate '
+                % self.course.certifying_organisation.name +
+                'You may print the certificate '
                 'by visiting:\n'
-                'http://%s/en/%s/certificate/%s/\n\n' % (
+                'http://%s/en/%s/certifyingorganisation/%s/course/'
+                '%s/print/%s/\n\n' % (
                     site,
                     self.course.certifying_organisation.project.slug,
-                    certificate_id
+                    self.course.certifying_organisation.slug,
+                    self.course.slug,
+                    pk
                 ) +
                 'Sincerely,\n%s %s' % (
                     self.course.course_convener.user.first_name,


Test patch:
Repository: kartoza/prj.app

Issue:
Print certificate using cache does not work
# Problem
From a user: he tried to print the certificate, but it does not work.
Here's his screenshot:
![sc1](https://user-images.githubusercontent.com/26101337/30580046-64f3192c-9d45-11e7-844f-931d06b45a45.png)
![sc2](https://user-images.githubusercontent.com/26101337/30580047-65c67c2c-9d45-11e7-81d7-c3af66c2edc6.png)


# Solution
fix it


Discussion:

Resolving patch:
diff --git a/django_project/certification/views/certificate.py b/django_project/certification/views/certificate.py
--- a/django_project/certification/views/certificate.py
+++ b/django_project/certification/views/certificate.py
@@ -218,10 +218,7 @@ def get_object(self, queryset=None):
 
 
 def certificate_pdf_view(request, **kwargs):
-    # 1. look for file
-    # 2. if found -> yes - open up the pdf and create response
-    # 3  if found -> no - generate the pdf and store under
-    # /media/certificate.certificateID.pdf
+
     project_slug = kwargs.pop('project_slug')
     course_slug = kwargs.pop('course_slug')
     pk = kwargs.pop('pk')
@@ -236,7 +233,10 @@ def certificate_pdf_view(request, **kwargs):
     response['Content-Disposition'] = \
         'filename=%s.pdf' % certificate.certificateID
     filename = "{}.{}".format(certificate.certificateID, "pdf")
-    pathname = os.path.join('/home/web/media', 'pdf/{}'.format(filename))
+    project_folder = (project.name.lower()).replace(' ', '_')
+    pathname = \
+        os.path.join(
+            '/home/web/media', 'pdf/%s/{}'.format(filename) % project_folder)
     found = os.path.exists(pathname)
     if found:
         with open(pathname, 'r') as pdf:
@@ -245,6 +245,10 @@ def certificate_pdf_view(request, **kwargs):
                 'filename=%s' % pdf
             return response
     else:
+        makepath = '/home/web/media/pdf/%s/' % project_folder
+        if not os.path.exists(makepath):
+            os.makedirs(makepath)
+
         # Create the PDF object, using the response object as its "file."
         page = canvas.Canvas(pathname, pagesize=landscape(A4))
         width, height = A4
@@ -384,9 +388,6 @@ def certificate_pdf_view(request, **kwargs):
         # Close the PDF object cleanly.
         page.showPage()
         page.save()
-        makepath = '/home/web/media/pdf/'
-        if not os.path.exists(makepath):
-            os.makedirs(makepath)
         with open(pathname, 'r') as pdf:
             response = HttpResponse(pdf.read(), content_type='application/pdf')
             response['Content-Disposition'] = \


Test patch: