def add_cal_letter_activity(request, course_slug):
    course = get_object_or_404(CourseOffering, slug=course_slug)
    letter_activities = LetterActivity.objects.filter(offering=course)
    numact_choices = [(na.pk, na.name) for na in NumericActivity.objects.filter(offering=course, deleted=False)]
    examact_choices = [(0, '\u2014')] + [(na.pk, na.name) for na in Activity.objects.filter(offering=course, deleted=False)]

    if request.method == 'POST': # If the form has been submitted...
        form = CalLetterActivityForm(request.POST) # A form bound to the POST data
        form.fields['numeric_activity'].choices = numact_choices
        form.fields['exam_activity'].choices = examact_choices
        form.activate_addform_validation(course_slug)
        if form.is_valid(): # All validation rules pass
            try:
                aggr_dict = Activity.objects.filter(offering=course).aggregate(Max('position'))
                if not aggr_dict['position__max']:
                    position = 1
                else:
                    position = aggr_dict['position__max'] + 1

                if form.cleaned_data['exam_activity'] == '0':
                    exam_activity_id = None
                else:
                    exam_activity = Activity.objects.get(pk=form.cleaned_data['exam_activity'])
                    exam_activity_id = exam_activity.id

                config = {
                        'showstats': form.cleaned_data['showstats'],
                        'showhisto': form.cleaned_data['showhisto'],
                        'url': form.cleaned_data['url'],
                        }
                CalLetterActivity.objects.create(name=form.cleaned_data['name'],
                                                 short_name=form.cleaned_data['short_name'],
                                                 status=form.cleaned_data['status'],
                                                 numeric_activity=NumericActivity.objects.get(pk=form.cleaned_data['numeric_activity']),
                                                 exam_activity_id=exam_activity_id,
                                                 offering=course,
                                                 position=position,
                                                 group=False,
                                                 config=config)
            except NotImplementedError:
                return NotFoundResponse(request)