Beispiel #1
0
 def save(self, *args, **kwargs):
     if not self.pk:
         words = self.name.split()
         filtered_words = [t for t in words if t.lower() not in STOP_WORDS]
         new_list = ' '.join(filtered_words)
         new_slug = slugify(new_list)[:50]
         new_slug = check_slug(Ballot.objects.all(), new_slug)
         self.slug = slugify(new_slug)[:50]
     super(Ballot, self).save(*args, **kwargs)
Beispiel #2
0
 def save(self, *args, **kwargs):
     words = self.certifying_organisation.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 = '%s-%s' % \
                (self.user.username, unidecode(' '.join(filtered_words)))
     new_slug = slugify(new_list)[:50]
     new_slug = check_slug(CourseConvener.objects.all(), new_slug)
     self.slug = slugify(new_slug)[:50]
     super(CourseConvener, self).save(*args, **kwargs)
Beispiel #3
0
 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 = unidecode(' '.join(filtered_words))
         new_slug = slugify(new_list)[:50]
         new_slug = \
             check_slug(CertifyingOrganisation.objects.all(), new_slug)
         self.slug = slugify(new_slug)[:50]
     super(CertifyingOrganisation, self).save(*args, **kwargs)
Beispiel #4
0
    def get_object(self, queryset=None):
        """Get the object for this view.

        :param queryset: A query set
        :type queryset: QuerySet

        :returns: Queryset which is filtered to only show a course
            within the organisation.
        :rtype: QuerySet
        :raises: Http404
        """

        if queryset is None:
            queryset = self.get_queryset()
            slug = self.kwargs.get('slug', None)
            organisation_slug = self.kwargs.get('organisation_slug', None)
            if slug and organisation_slug:
                try:
                    certifying_organisation = \
                        CertifyingOrganisation.objects.get(
                            slug=organisation_slug)
                except CertifyingOrganisation.DoesNotExist:
                    raise Http404('Sorry! We could not find your '
                                  'certifying organisation!')
                try:
                    obj = queryset.get(
                        certifying_organisation=certifying_organisation,
                        slug=slug)
                    return obj
                except Course.DoesNotExist:
                    raise Http404('Sorry! We could not find your course!')
                except Course.MultipleObjectsReturned:
                    # Update the slug for the latest object when multiple
                    # objects with the same slug are found and raise
                    # Permission Denied
                    new_slug = check_slug(queryset, slug)
                    objects = queryset.filter(
                        certifying_organisation=certifying_organisation,
                        slug=slug)
                    latest_obj = len(objects) - 1
                    objects[latest_obj].slug = new_slug
                    objects[latest_obj].save()
                    raise PermissionDenied
            else:
                raise Http404('Sorry! We could not find your course!')
Beispiel #5
0
 def save(self, *args, **kwargs):
     if not self.pk:
         project_name = self.certifying_organisation.project.name
         course_type_name = self.course_type.name
         self.name = \
             project_name + '_' + course_type_name + '_' + \
             str(self.start_date) + '-' + str(self.end_date)
         registered_course = Course.objects.all()
         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 = unidecode(' '.join(filtered_words))
         new_slug = slugify(new_list)[:100]
         # increment slug when there is duplicate.
         new_slug = check_slug(registered_course, new_slug)
         self.slug = new_slug
     super(Course, self).save(*args, **kwargs)
def reject_certifying_organisation(request, **kwargs):
    """Function to reject a pending certifying organisation."""

    pattern_name = 'pending-certifyingorganisation-list'

    if request.method == 'GET':
        project_slug = kwargs.pop('project_slug')
        slug = kwargs.pop('slug')

        certifyingorganisation_qs = \
            CertifyingOrganisation.objects.all()

        # Get the object, when there is slug duplicate, get the first object
        certifyingorganisation = \
            get_list_or_404(certifyingorganisation_qs, slug=slug)[0]
        certifyingorganisation.rejected = True
        certifyingorganisation.approved = False

        remarks = request.GET.get('remarks', '')
        certifyingorganisation.remarks = remarks

        # Check if slug have duplicates in rejected objects.
        # If there is duplicate slug, assign new slug.
        rejected_objects = CertifyingOrganisation.objects.filter(rejected=True)
        slug = check_slug(rejected_objects, certifyingorganisation.slug)
        certifyingorganisation.slug = slug

        certifyingorganisation.save()

        schema = request.is_secure() and "https" or "http"
        site = request.get_host()
        for organisation_owner in \
                certifyingorganisation.organisation_owners.all():
            data = {
                'owner_firstname': organisation_owner.first_name,
                'owner_lastname': organisation_owner.last_name,
                'organisation_name': certifyingorganisation.name,
                'project_name': certifyingorganisation.project.name,
                'project_owner_firstname':
                certifyingorganisation.project.owner.first_name,
                'project_owner_lastname':
                certifyingorganisation.project.owner.last_name,
                'site': site,
                'project_slug': project_slug,
                'status': certifyingorganisation.status,
                'schema': schema
            }
            send_mail(
                u'Projecta - Your organisation is not approved',
                u'Dear {owner_firstname} {owner_lastname},\n\n'
                u'We are sorry that your certifying organisation '
                u'has not been approved. \nThe '
                u'following is the details of your organisation:'
                u'\n\n'
                u'Name of organisation: {organisation_name}\n'
                u'Project: {project_name}\n'
                u'Status: {status}\n\n'
                u'For further information please visit: '
                u'{schema}://{site}/en/{project_slug}/about/\n\n'
                u'Sincerely,\n'
                u'{project_owner_firstname} {project_owner_lastname}'.format(
                    **data),
                certifyingorganisation.project.owner.email,
                [organisation_owner.email],
                fail_silently=False,
            )

        url = reverse(pattern_name, kwargs={'project_slug': project_slug})
        return HttpResponseRedirect(url)
    else:
        return HttpResponse('Please use GET method.')
    def get_redirect_url(self, project_slug, slug):
        """Save Certifying Organisation as approved and redirect.

        :param project_slug: The slug of the parent
                            Certifying Organisation's parent Project.
        :type project_slug: str

        :param slug: The slug of the Certifying Organisation.
        :type slug: str

        :returns: URL
        :rtype: str
        """

        certifyingorganisation_qs = \
            CertifyingOrganisation.unapproved_objects.all()
        # Get the object, when there is slug duplicate, get the first object
        certifyingorganisation = \
            get_list_or_404(certifyingorganisation_qs, slug=slug)[0]
        certifyingorganisation.approved = True

        # Check if slug have duplicates in approved objects.
        # If there is duplicate slug, assign new slug.
        approved_objects = CertifyingOrganisation.approved_objects.all()
        slug = check_slug(approved_objects, certifyingorganisation.slug)
        certifyingorganisation.slug = slug

        certifyingorganisation.save()

        site = self.request.get_host()
        for organisation_owner in \
                certifyingorganisation.organisation_owners.all():
            data = {
                'owner_firstname': organisation_owner.first_name,
                'owner_lastname': organisation_owner.last_name,
                'organisation_name': certifyingorganisation.name,
                'project_name': certifyingorganisation.project.name,
                'project_owner_firstname':
                certifyingorganisation.project.owner.first_name,
                'project_owner_lastname':
                certifyingorganisation.project.owner.last_name,
                'site': site,
                'project_slug': project_slug,
            }
            send_mail(
                u'Projecta - Your organisation is approved',
                u'Dear {owner_firstname} {owner_lastname},\n\n'
                u'Congratulations!\n'
                u'Your certifying organisation has been approved. The '
                u'following is the details of the newly approved organisation:'
                u'\n'
                u'Name of organisation: {organisation_name}\n'
                u'Project: {project_name}\n'
                u'You may now start creating your training center, '
                u'course type, course convener and course.\n'
                u'For further information please visit: '
                u'{site}/en/{project_slug}/about/\n\n'
                u'Sincerely,\n'
                u'{project_owner_firstname} {project_owner_lastname}'.format(
                    **data),
                certifyingorganisation.project.owner.email,
                [organisation_owner.email],
                fail_silently=False,
            )

        return reverse(self.pattern_name,
                       kwargs={'project_slug': project_slug})