Skip to content

Commit

Permalink
#476 - fix whitespace issues
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlittle committed Nov 3, 2019
1 parent b38d69d commit 76009c4
Show file tree
Hide file tree
Showing 135 changed files with 931 additions and 908 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -19,12 +19,12 @@ Submitting Bug Reports or Feature Requests
Need Help or have Questions?
-----------------------------

If you have a question or need help with any aspect of the OppiaMobile platform, then please join the OppiaMobile Community site at
If you have a question or need help with any aspect of the OppiaMobile platform, then please join the OppiaMobile Community site at
https://community.oppia-mobile.org/

Submitting Code Updates
------------------------
See 'good first issue' tag:
See 'good first issue' tag:
(server) https://github.com/DigitalCampus/django-oppia/labels/good-first-issue
(app) https://github.com/DigitalCampus/oppia-mobile-android/labels/good-first-issue
(block) https://github.com/DigitalCampus/moodle-block_oppia_mobile_export/labels/good-first-issue
Expand Down
7 changes: 5 additions & 2 deletions README.md
Expand Up @@ -5,7 +5,10 @@ django-oppia is the server side component for the OppiaMobile learning platform

For documentation please visit: https://oppiamobile.readthedocs.io

For information on how to contribute, submit bug reports and feature requests, please visit: https://github.com/DigitalCampus/django-oppia/blob/master/CONTRIBUTING.md
For information on how to contribute, submit bug reports and feature requests,
please visit:
https://github.com/DigitalCampus/django-oppia/blob/master/CONTRIBUTING.md

For help and support, please join our OppiaMobile Community site at https://community.oppia-mobile.org/
For help and support, please join our OppiaMobile Community site at
https://community.oppia-mobile.org/

1 change: 1 addition & 0 deletions activitylog/admin.py
Expand Up @@ -7,4 +7,5 @@
class UploadedActivityLogAdmin(admin.ModelAdmin):
list_display = ('id', 'file', 'created_date')


admin.site.register(UploadedActivityLog, UploadedActivityLogAdmin)
16 changes: 11 additions & 5 deletions activitylog/forms.py
Expand Up @@ -12,14 +12,17 @@

class UploadActivityLogForm(forms.Form):
activity_log_file = forms.FileField(
help_text=_(u'File types accepted: %s' % ', '.join(settings.OPPIA_UPLOAD_TRACKER_FILE_TYPES)),
help_text=_(u'File types accepted: %s' % ', '
.join(settings.OPPIA_UPLOAD_TRACKER_FILE_TYPES)),
required=True,
label=_(u'Activity Log'),
error_messages={'required': _(u'Please select an activity log file to upload')},
error_messages={'required':
_(u'Please select an activity log file to \
upload')},
)

def __init__(self, *args, **kwargs):
super(UploadActivityLogForm, self).__init__( * args, ** kwargs)
super(UploadActivityLogForm, self).__init__(* args, ** kwargs)
self.helper = FormHelper()
self.helper.form_action = reverse('oppia_activitylog_upload')
self.helper.form_class = 'form-horizontal'
Expand All @@ -37,5 +40,8 @@ def clean(self):
cleaned_data = super(UploadActivityLogForm, self).clean()
activity_log_file = cleaned_data.get("activity_log_file")

if activity_log_file is not None and activity_log_file.content_type not in settings.OPPIA_UPLOAD_TRACKER_FILE_TYPES:
raise forms.ValidationError(_(u"You may only upload an activity log file which is one of the following types: %s" % ', '.join(settings.OPPIA_UPLOAD_TRACKER_FILE_TYPES)))
if activity_log_file is not None \
and activity_log_file.content_type \
not in settings.OPPIA_UPLOAD_TRACKER_FILE_TYPES:
raise forms.ValidationError(
_(u"You may only upload an activity log file which is one of the following types: %s" % ', '.join(settings.OPPIA_UPLOAD_TRACKER_FILE_TYPES)))
2 changes: 1 addition & 1 deletion activitylog/models.py
Expand Up @@ -27,7 +27,7 @@ def __unicode__(self):

def __str__(self):
return self.file.name

@receiver(post_delete, sender=UploadedActivityLog)
def activity_log_delete_file(sender, instance, **kwargs):
file_to_delete = instance.file.path
Expand Down
2 changes: 1 addition & 1 deletion api/media.py
Expand Up @@ -30,7 +30,7 @@ def upload_view(request):

if len(validation_errors) > 0:
return JsonResponse({'errors': validation_errors}, status=400 )

# authenticate user
username = request.POST.get("username")
password = request.POST.get("password")
Expand Down
24 changes: 12 additions & 12 deletions api/publish.py
Expand Up @@ -41,7 +41,7 @@ def check_required_fields(request, validation_errors):
for field in required:
if field not in request.POST or request.POST[field].strip() == '':
validation_errors.append("field '{0}' is missing or empty".format(field))

if api.COURSE_FILE_FIELD not in request.FILES:
validation_errors.append("Course file not found")
else:
Expand All @@ -50,7 +50,7 @@ def check_required_fields(request, validation_errors):
validation_errors.append("You may only upload a zip file")
msg_text = _(u"Invalid zip file")
CoursePublishingLog(action="invalid_zip", data=msg_text).save()

return validation_errors

def check_upload_file_size(file, validation_errors):
Expand Down Expand Up @@ -110,11 +110,11 @@ def publish_view(request):

extract_path = os.path.join(settings.COURSE_UPLOAD_DIR, 'temp', str(user.id))
course, status_code = handle_uploaded_file(request.FILES[api.COURSE_FILE_FIELD], extract_path, request, user)
CoursePublishingLog(course=course if course else None,
new_version=course.version if course else None,
user=user,
action="api_file_uploaded",

CoursePublishingLog(course=course if course else None,
new_version=course.version if course else None,
user=user,
action="api_file_uploaded",
data=request.FILES[api.COURSE_FILE_FIELD].name).save()
if course is False:
status = status_code if status_code is not None else 500
Expand All @@ -135,17 +135,17 @@ def publish_view(request):
add_course_tags(user, course, tags)

msgs = get_messages_array(request)
CoursePublishingLog(course=course,
new_version=course.version,
user=user,
action="api_course_published",
CoursePublishingLog(course=course,
new_version=course.version,
user=user,
action="api_course_published",
data=_(u'Course published via API')).save()
if len(msgs) > 0:
return JsonResponse({'messages': msgs}, status=201)
else:
return HttpResponse(status=201)



def get_messages_array(request):
msgs = messages.get_messages(request)
Expand Down
2 changes: 1 addition & 1 deletion api/resources.py
Expand Up @@ -279,7 +279,7 @@ def obj_create(self, bundle, **kwargs):
subject="Password reset",
fail_silently=False,
recipients=[user.email],
new_password = newpass,
new_password = newpass,
site = prefix + bundle.request.META['SERVER_NAME']
)

Expand Down
2 changes: 1 addition & 1 deletion api/validation.py
Expand Up @@ -17,5 +17,5 @@ def is_valid(self, bundle, request=None):
Media.objects.get(digest=bundle.obj.digest)
except Media.DoesNotExist:
pass

return errors
4 changes: 2 additions & 2 deletions av/forms.py
Expand Up @@ -48,9 +48,9 @@ def clean(self):

'''
check this file hasn't already been uploaded
the media_file might either by a TemporaryUploadedFile or an InMemoryUploadedFile - so need to handle generation of the md5 differently in each case
the media_file might either by a TemporaryUploadedFile or an InMemoryUploadedFile - so need to handle generation of the md5 differently in each case
'''

if isinstance(media_file, TemporaryUploadedFile):
md5 = hashlib.md5(open(media_file.temporary_file_path(), 'rb').read()).hexdigest()
elif isinstance(media_file, InMemoryUploadedFile) or isinstance(media_file, SimpleUploadedFile):
Expand Down
4 changes: 2 additions & 2 deletions av/handler.py
Expand Up @@ -25,7 +25,7 @@ def upload(request, user):
file.close()
uploaded_media.md5 = md5
uploaded_media.save()

try:
media_full_path = os.path.join(settings.MEDIA_ROOT, uploaded_media.file.name)
media_length = get_length(media_full_path)
Expand All @@ -48,7 +48,7 @@ def upload(request, user):
errors.append(e)
return {'result': UploadedMedia.UPLOAD_STATUS_FAILURE, 'form': form, 'errors': errors}


def get_length(filepath):
result = subprocess.Popen([settings.MEDIA_PROCESSOR_PROGRAM, filepath], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, encoding='utf8')
duration_list = [x for x in result.stdout.readlines() if "Duration" in x]
Expand Down
8 changes: 4 additions & 4 deletions av/management/commands/generate_media_images.py
Expand Up @@ -38,16 +38,16 @@ def handle(self, *args, **options):
self.stdout.write(" > Generating miniatures... \r", )
image_generator_command = ("%s %s" % (settings.SCREENSHOT_GENERATOR_PROGRAM, settings.SCREENSHOT_GENERATOR_PROGRAM_PARAMS)) % (m.file.path, content.SCREENSHOT_IMAGE_WIDTH, content.SCREENSHOT_IMAGE_HEIGHT, cache_dir)
ffmpeg = subprocess.Popen(image_generator_command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True)

self.process_ffmpeg_output(ffmpeg)

self.stdout.write(" > Generating miniatures... 100% \r\n", )

# Now get the images generated and add to the db
self.add_images_to_db(cache_dir,m)

self.stdout.write("\n > Process completed.")

def add_images_to_db(self, cache_dir, media):
image_file_list = os.listdir(cache_dir)
for filename in image_file_list:
Expand All @@ -58,7 +58,7 @@ def add_images_to_db(self, cache_dir, media):
data = f.read()
media_image.image.save(filename, ContentFile(data))
media_image.save()

def process_ffmpeg_output(self, ffmpeg):
current_frame = 0
for line in iter(ffmpeg.stdout.readline, ''):
Expand Down
4 changes: 2 additions & 2 deletions av/management/commands/media_url_check.py
@@ -1,7 +1,7 @@
'''
Checks the media download urls to ensure they are valid links
For full instructions, see the documentation at
For full instructions, see the documentation at
https://oppiamobile.readthedocs.org/en/latest/
'''

Expand Down
6 changes: 3 additions & 3 deletions av/models.py
Expand Up @@ -34,10 +34,10 @@ class Meta:

def __unicode__(self):
return self.file.name

def __str__(self):
return self.file.name

def get_embed_code(self, uri):
try:
return EMBED_TEMPLATE % (os.path.basename(self.file.name), uri, self.md5, self.file.size, self.length)
Expand Down Expand Up @@ -73,7 +73,7 @@ def uploaded_media_delete_file(sender, instance, **kwargs):
def image_file_name(instance, filename):
return os.path.join('uploaded/images', filename[0:2], filename[2:4], filename)


class UploadedMediaImage(models.Model):

create_user = models.ForeignKey(User, related_name='media_image_create_user', null=True, on_delete=models.SET_NULL)
Expand Down
2 changes: 1 addition & 1 deletion av/urls.py
Expand Up @@ -7,7 +7,7 @@
url(r'^$', oppia_av_views.home_view, name="oppia_av_home"),
url(r'^view/(?P<id>\d+)$', oppia_av_views.media_view, name="oppia_av_view"),
url(r'^view/set-image-default/(?P<image_id>\d+)$', oppia_av_views.set_default_image_view, name="oppia_av_set_default_image"),

url(r'^upload/$', oppia_av_views.upload_view, name="oppia_av_upload"),
url(r'^upload/success/(?P<id>\d+)$', oppia_av_views.upload_success_view, name="oppia_av_upload_success"),
]
22 changes: 11 additions & 11 deletions content/views.py
Expand Up @@ -41,7 +41,7 @@ def media_embed_helper(request):

download_error, processed_media = process_media_file(
media_guid, media_url, media_local_file, download_error, processed_media)

# try to delete the temp media file
try:
os.remove(media_local_file)
Expand All @@ -57,7 +57,7 @@ def media_embed_helper(request):


def process_media_file(media_guid, media_url, media_local_file, download_error, processed_media):

if download_error is None and can_execute(settings.SCREENSHOT_GENERATOR_PROGRAM) and can_execute(settings.MEDIA_PROCESSOR_PROGRAM):

# get the basic meta info
Expand Down Expand Up @@ -87,7 +87,7 @@ def process_media_file(media_guid, media_url, media_local_file, download_error,
processed_media['error'] = download_error.strerror
else:
processed_media['error'] = _("ffmpeg_missing")

return download_error, processed_media


Expand All @@ -102,16 +102,16 @@ def check_media_link(media_url, media_local_file, download_error, processed_medi


def get_length(filename):
result = subprocess.Popen([settings.MEDIA_PROCESSOR_PROGRAM,
filename,
'-print_format',
'json',
'-show_streams',
'-loglevel',
result = subprocess.Popen([settings.MEDIA_PROCESSOR_PROGRAM,
filename,
'-print_format',
'json',
'-show_streams',
'-loglevel',
'quiet'],
stdout = subprocess.PIPE,
stdout = subprocess.PIPE,
stderr = subprocess.STDOUT)

duration = float(json.loads(result.stdout.read())['streams'][0]['duration'])
if duration != 0:
return True, duration
Expand Down
2 changes: 1 addition & 1 deletion gamification/admin.py
Expand Up @@ -15,7 +15,7 @@ class ActivityGamificationEventAdmin(admin.ModelAdmin):

class MediaGamificationEventAdmin(admin.ModelAdmin):
list_display = ('media', 'event', 'points')

class DefaultGamificationEventAdmin(admin.ModelAdmin):
list_display = ('event', 'points', 'level')

Expand Down

0 comments on commit 76009c4

Please sign in to comment.