def upload_view(request): if not request.user.userprofile.get_can_upload_activitylog(): raise exceptions.PermissionDenied if request.method == 'POST': form = UploadActivityLogForm(request.POST, request.FILES) if form.is_valid(): activity_log_file = request.FILES["activity_log_file"] # save activity_log_file uploaded_activity_log = UploadedActivityLog( create_user=request.user, file=activity_log_file) uploaded_activity_log.save() # open file and process file_data = open(uploaded_activity_log.file.path, 'rb').read() success = process_activitylog(request, file_data) if success: return HttpResponseRedirect( reverse('oppia_activitylog_upload_success')) form = UploadActivityLogForm() return render(request, 'oppia/activitylog/upload.html', { 'form': form, 'title': _(u'Upload Activity Log') })
def upload_view(request): if not request.user.userprofile.get_can_upload_activitylog(): raise exceptions.PermissionDenied if request.method == 'POST': form = UploadActivityLogForm(request.POST, request.FILES) if form.is_valid(): activity_log_file = request.FILES["activity_log_file"] # save activity_log_file uploaded_activity_log = UploadedActivityLog(create_user=request.user, file=activity_log_file) uploaded_activity_log.save() # open file and process file_data = open(uploaded_activity_log.file.path, 'rb').read() success = process_activitylog(request, file_data) if success: return HttpResponseRedirect(reverse('oppia_activitylog_upload_success')) form = UploadActivityLogForm() return render(request, 'oppia/activitylog/upload.html', {'form': form, 'title': _(u'Upload Activity Log')})
def post(self, request): form = UploadActivityLogForm(request.POST, request.FILES) if form.is_valid(): activity_log_file = request.FILES["activity_log_file"] # save activity_log_file uploaded_activity_log = \ UploadedActivityLog(create_user=request.user, file=activity_log_file) uploaded_activity_log.save() # open file and process with open(uploaded_activity_log.file.path, 'rb') as file: file_data = file.read() success = process_activitylog(request, file_data) if success: return HttpResponseRedirect( reverse('activitylog:upload_success')) return render(request, 'common/upload.html', {'form': form, 'title': _(u'Upload Activity Log')})
def get(self, request): form = UploadActivityLogForm() return render(request, 'common/upload.html', {'form': form, 'title': _(u'Upload Activity Log')})