<commit_before>"""
This mixin defines handlers and fields to manage uploading assignments.
"""

import datetime
import hashlib
import json
import logging
import mimetypes
import os
import pkg_resources
import pytz

from courseware.models import StudentModule

from xblock.core import XBlock
from xblock.fields import XBlockMixin, Scope, Dict

from webob.response import Response

from django.core.files import File
from django.core.files.storage import default_storage
from django.template import Context, Template

log = logging.getLogger(__name__)

class FileAnnotationMixin(XBlockMixin):
	"""
	Mixin for handling annotations.
	"""
	annotated_files = Dict(
		display_name="Uploaded Files",
		scope=Scope.user_state,
		default=dict(),
		help="Files uploaded by the user. Tuple of filename, mimetype and timestamp"
	)	

	@XBlock.handler
	def staff_upload_annotated(self, request, suffix=''):
		module_id = request.params['module_id']
		state = self.get_student_state(module_id)
		annotated_list = self.annotated_file_list(module_id)

		uploaded = self.upload_file(
			annotated_list, 
			request.params['annotation']
		)

		#need to save state sepratly as user is instructor
		self.set_student_state(
			module_id, 
			annotated_files=filelist.annotated_list(uploaded)
		)

		return {
			"sha1":      uploaded.sha1, 
			"filename":  uploaded.filename,
			"timestamp": uploaded.timestamp
		}

	@XBlock.handler
	def student_download_annotated(self, request, suffix=''):
		return self.download_file(self.annotated_files, suffix)

	@XBlock.handler
	def staff_download_annotated(self, request, suffix=''):
		return self.download_file(
			self.annotated_file_list(request.params['module_id']), 
			suffix
		)
	
	#For downloading the entire assingment for one student.
	@XBlock.handler
	def staff_download_annotated_zipped(self, request, suffix=''):
		assert self.is_course_staff()
		module = StudentModule.objects.get(pk=request.params['module_id'])
		state = json.loads(module.state)
<commit_msg>merging both uploads<commit_after>"""
This mixin defines handlers and fields to manage uploading assignments.
"""

import datetime
import hashlib
import json
import logging
import mimetypes
import os
import pkg_resources
import pytz

from courseware.models import StudentModule

from xblock.core import XBlock
from xblock.fields import XBlockMixin, Scope, Dict

from webob.response import Response

from django.core.files import File
from django.core.files.storage import default_storage
from django.template import Context, Template

log = logging.getLogger(__name__)

class FileAnnotationMixin(XBlockMixin):
	"""
	Mixin for handling annotations.
	"""
	annotated_files = Dict(
		display_name="Uploaded Files",
		scope=Scope.user_state,
		default=dict(),
		help="Files uploaded by the user. Tuple of filename, mimetype and timestamp"
	)	

	@XBlock.handler
	def staff_upload_annotated(self, request, suffix=''):
		module_id = request.params['module_id']
		state = self.get_student_state(module_id)
		annotated_list = self.annotated_file_list(module_id)

		uploaded = self.upload_file(
			annotated_list, 
			request.params['annotation']
		)

		#need to save state sepratly as user is instructor
		self.set_student_state(
			module_id, 
			filelist=annotated_list.annotated_list(uploaded)
		)

		return {
			"sha1":      uploaded.sha1, 
			"filename":  uploaded.filename,
			"timestamp": uploaded.timestamp
		}

	@XBlock.handler
	def student_download_annotated(self, request, suffix=''):
		return self.download_file(self.annotated_files, suffix)

	@XBlock.handler
	def staff_download_annotated(self, request, suffix=''):
		return self.download_file(
			self.annotated_file_list(request.params['module_id']), 
			suffix
		)
	
	#For downloading the entire assingment for one student.
	@XBlock.handler
	def staff_download_annotated_zipped(self, request, suffix=''):
		assert self.is_course_staff()
		module = StudentModule.objects.get(pk=request.params['module_id'])
		state = json.loads(module.state)

{'fraction_non_alphanumeric': 0.09177532597793381, 'fraction_numerical': 0.0010030090270812437, 'mean_word_length': 5.242566510172144, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3723577', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1240, 'n_words': 308}