def handle(self, *args, **options):
     if options['fromstart']:
         update_summaries(0, 0)
     else:
         # get last tracker and points PKs processed
         last_tracker_pk = SettingProperties.get_property('last_tracker_pk', 0)
         last_points_pk = SettingProperties.get_property('last_points_pk', 0)
         update_summaries(last_tracker_pk, last_points_pk)
 def handle(self, *args, **options):
     if options['fromstart']:
         update_summaries(0, 0)
     else:
         # get last tracker and points PKs processed
         last_tracker_pk = SettingProperties.get_property(
             'last_tracker_pk', 0)
         last_points_pk = SettingProperties.get_property(
             'last_points_pk', 0)
         update_summaries(last_tracker_pk, last_points_pk)
def run():
    print('Starting Oppia Summary cron...')
    start = time.time()

    from oppia.settings.models import SettingProperties

    # get last tracker and points PKs processed
    last_tracker_pk = SettingProperties.get_property('last_tracker_pk', 0)
    last_points_pk = SettingProperties.get_property('last_points_pk', 0)

    update_summaries(last_tracker_pk, last_points_pk)

    elapsed_time = time.time() - start
    print('cron completed, took %.2f seconds' % elapsed_time)
def insert_maxuploadsize(apps, schema_editor):
    current = SettingProperties.get_int(constants.MAX_UPLOAD_SIZE, None)
    if current is None and hasattr(settings, 'OPPIA_MAX_UPLOAD_SIZE'):
        settings_prop = SettingProperties()
        settings_prop.key = constants.MAX_UPLOAD_SIZE
        settings_prop.int_value = settings.OPPIA_MAX_UPLOAD_SIZE
        settings_prop.save()
    def clean(self):
        cleaned_data = super(UploadCourseStep1Form, self).clean()
        file = cleaned_data.get("course_file")

        max_upload = SettingProperties.get_int(constants.MAX_UPLOAD_SIZE, settings.OPPIA_MAX_UPLOAD_SIZE)

        if file is not None and file._size > max_upload:
            size = int(math.floor(max_upload / 1024 / 1024))
            raise forms.ValidationError(_("Your file is larger than the maximum allowed (%(size)d Mb). You may want to check your course for large includes, such as images etc.") % {'size': size, })

        if file is not None and file.content_type != 'application/zip' and file.content_type != 'application/x-zip-compressed':
            raise forms.ValidationError(_("You may only upload a zip file"))

        return cleaned_data
Beispiel #6
0
    def clean(self):
        cleaned_data = super(UploadCourseStep1Form, self).clean()
        file = cleaned_data.get("course_file")

        max_upload = SettingProperties.get_int(constants.MAX_UPLOAD_SIZE, settings.OPPIA_MAX_UPLOAD_SIZE)

        if file is not None and file._size > max_upload:
            size = int(math.floor(max_upload / 1024 / 1024))
            raise forms.ValidationError(_("Your file is larger than the maximum allowed (%(size)d Mb). You may want to check your course for large includes, such as images etc.") % {'size':size, })
        
        if file is not None and file.content_type != 'application/zip' and file.content_type != 'application/x-zip-compressed':
            raise forms.ValidationError(_("You may only upload a zip file"))
        
        return cleaned_data
Beispiel #7
0
def check_upload_file_size_type(file, validation_errors):
    max_upload = SettingProperties.get_int(constants.MAX_UPLOAD_SIZE,
                                           settings.OPPIA_MAX_UPLOAD_SIZE)
    if file is not None and file._size > max_upload:
        size = int(math.floor(max_upload / 1024 / 1024))
        validation_errors.append((_(
            "Your file is larger than the maximum allowed (%(size)d Mb). You may want to check your course for large includes, such as images etc."
        ) % {
            'size': size,
        }))

    if file is not None and file.content_type != 'application/zip' and file.content_type != 'application/x-zip-compressed':
        validation_errors.append(_("You may only upload a zip file"))

    return validation_errors
    def __init__(self, *args, **kwargs):
        super(UploadCourseStep1Form, self).__init__( * args, ** kwargs)

        max_upload = SettingProperties.get_int(constants.MAX_UPLOAD_SIZE, settings.OPPIA_MAX_UPLOAD_SIZE)
        self.fields['course_file'].help_text = _('Max size %(size)d Mb') % {'size': int(math.floor(max_upload / 1024 / 1024))}

        self.helper = FormHelper()
        self.helper.form_action = reverse('oppia_upload')
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-lg-2'
        self.helper.field_class = 'col-lg-4'
        self.helper.layout = Layout(
                'course_file',
                Div(
                   Submit('submit', _(u'Upload'), css_class='btn btn-default'),
                   css_class='col-lg-offset-2 col-lg-4',
                ),
            )
Beispiel #9
0
    def __init__(self, *args, **kwargs):
        super(UploadCourseStep1Form, self).__init__(*args, **kwargs)

        max_upload = SettingProperties.get_int(constants.MAX_UPLOAD_SIZE, settings.OPPIA_MAX_UPLOAD_SIZE)
        self.fields['course_file'].help_text = _('Max size %(size)d Mb') % {'size':int(math.floor(max_upload / 1024 / 1024))}

        self.helper = FormHelper()
        self.helper.form_action = reverse('oppia_upload')
        self.helper.form_class = 'form-horizontal'
        self.helper.label_class = 'col-lg-2'
        self.helper.field_class = 'col-lg-4'
        self.helper.layout = Layout(
                'course_file',
                Div(
                   Submit('submit', _(u'Upload'), css_class='btn btn-default'),
                   css_class='col-lg-offset-2 col-lg-4',
                ),
            )  
Beispiel #10
0
def publish_view(request):

    # get the messages to clear possible previous unprocessed messages
    get_messages_array(request)

    if request.method != 'POST':
        return HttpResponse(status=405)

    required = ['username', 'password', 'tags', 'is_draft']

    validationErrors = []

    for field in required:
        if field not in request.POST:
            print field + " not found"
            validationErrors.append("field '{0}' missing".format(field))

    if COURSE_FILE_FIELD not in request.FILES:
        print "Course file not found"
        validationErrors.append("file '{0}' missing".format(COURSE_FILE_FIELD))
    else:
        # check the file size of the course doesnt exceed the max
        file = request.FILES[COURSE_FILE_FIELD]
        max_upload = SettingProperties.get_int(constants.MAX_UPLOAD_SIZE,
                                               settings.OPPIA_MAX_UPLOAD_SIZE)
        if file is not None and file._size > max_upload:
            size = int(math.floor(max_upload / 1024 / 1024))
            validationErrors.append((_(
                "Your file is larger than the maximum allowed (%(size)d Mb). You may want to check your course for large includes, such as images etc."
            ) % {
                'size': size,
            }))

        if file is not None and file.content_type != 'application/zip' and file.content_type != 'application/x-zip-compressed':
            validationErrors.append(_("You may only upload a zip file"))

    if validationErrors:
        return JsonResponse(
            {'errors': validationErrors},
            status=400,
        )

    # authenticate user
    username = request.POST['username']
    password = request.POST['password']
    user = authenticate(username=username, password=password)
    if user is None or not user.is_active:
        messages.error(request, "Invalid username/password")
        response_data = {
            'message': _('Authentication errors'),
            'messages': get_messages_array(request)
        }
        return JsonResponse(response_data, status=401)

    # check user has permissions to publish course
    if settings.OPPIA_STAFF_ONLY_UPLOAD is True \
            and not user.is_staff \
            and user.userprofile.can_upload is False:
        return HttpResponse(status=401)

    extract_path = os.path.join(settings.COURSE_UPLOAD_DIR, 'temp',
                                str(user.id))
    course, response = handle_uploaded_file(request.FILES['course_file'],
                                            extract_path, request, user)

    if course is False:
        resp_code = response if response is not None else 500
        response_data = {'messages': get_messages_array(request)}
        return JsonResponse(response_data, status=resp_code)

    else:
        course.is_draft = (request.POST['is_draft'] == "True"
                           or request.POST['is_draft'] == "true")
        course.save()

        # remove any existing tags
        CourseTag.objects.filter(course=course).delete()

        # add tags
        tags = request.POST['tags'].strip().split(",")
        for t in tags:
            try:
                tag = Tag.objects.get(name__iexact=t.strip())
            except Tag.DoesNotExist:
                tag = Tag()
                tag.name = t.strip()
                tag.created_by = user
                tag.save()
            # add tag to course
            try:
                ct = CourseTag.objects.get(course=course, tag=tag)
            except CourseTag.DoesNotExist:
                ct = CourseTag()
                ct.course = course
                ct.tag = tag
                ct.save()

        msgs = get_messages_array(request)
        if len(msgs) > 0:
            return JsonResponse({'messages': msgs}, status=201)
        else:
            return HttpResponse(status=201)