Skip to content

Commit

Permalink
chore: reformat for quality checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian2012 committed Oct 10, 2023
1 parent c852ea1 commit 6bdae62
Show file tree
Hide file tree
Showing 17 changed files with 209 additions and 142 deletions.
4 changes: 3 additions & 1 deletion platform_plugin_turnitin/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ def ready(self) -> None:
Perform application initialization once the Django platform has been initialized.
"""
super().ready()
from platform_plugin_turnitin.turnitin import TurnitinXBlock
from platform_plugin_turnitin.turnitin import ( # no-qa pylint: disable=import-outside-toplevel,unused-import
TurnitinXBlock,
)
6 changes: 1 addition & 5 deletions platform_plugin_turnitin/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ class TurnitinSubmission(models.Model):
- turnitin_submission_pdf_id (str): The unique identifier for the PDF version of the submission in Turnitin.
- created_at (datetime): The date and time when the submission was created.
Methods:
- __str__: Returns a string representation of the submission, showing its ID and creation date.
.. no_pii:
"""

user = models.ForeignKey(
Expand All @@ -28,6 +27,3 @@ class TurnitinSubmission(models.Model):
turnitin_submission_id = models.CharField(max_length=255, blank=True, null=True)
turnitin_submission_pdf_id = models.CharField(max_length=255, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add=True)

def __str__(self):
return f"Submission: {self.turnitin_submission_id or 'Not Set'} - created at: {self.created_at}"
33 changes: 32 additions & 1 deletion platform_plugin_turnitin/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
USE_TZ = True


def plugin_settings(settings): # pylint: disable=unused-argument
def plugin_settings(settings):
"""
Set of plugin settings used by the Open Edx platform.
More info: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/plugins/README.rst
Expand All @@ -41,3 +41,34 @@ def plugin_settings(settings): # pylint: disable=unused-argument
settings.TURNITIN_TCA_INTEGRATION_FAMILY = None
settings.TURNITIN_TCA_INTEGRATION_VERSION = None
settings.TURNITIN_TCA_API_KEY = None
settings.TURNITIN_SIMILARY_REPORT_PAYLOAD = {
"indexing_settings": {"add_to_index": True},
"generation_settings": {
"search_repositories": [
"INTERNET",
"SUBMITTED_WORK",
"PUBLICATION",
"CROSSREF",
"CROSSREF_POSTED_CONTENT",
],
"submission_auto_excludes": [],
"auto_exclude_self_matching_scope": "ALL",
"priority": "HIGH",
},
"view_settings": {
"exclude_quotes": True,
"exclude_bibliography": True,
"exclude_citations": False,
"exclude_abstract": False,
"exclude_methods": False,
"exclude_custom_sections": False,
"exclude_preprints": False,
"exclude_small_matches": 8,
"exclude_internet": False,
"exclude_publications": False,
"exclude_crossref": False,
"exclude_crossref_posted_content": False,
"exclude_submitted_works": False,
},
}
settings.TURNITIN_API_TIMEOUT = 30
10 changes: 9 additions & 1 deletion platform_plugin_turnitin/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""


def plugin_settings(settings): # pylint: disable=unused-argument
def plugin_settings(settings):
"""
Set of plugin settings used by the Open Edx platform.
More info: https://github.com/edx/edx-platform/blob/master/openedx/core/djangoapps/plugins/README.rst
Expand All @@ -23,3 +23,11 @@ def plugin_settings(settings): # pylint: disable=unused-argument
settings.TURNITIN_TCA_API_KEY = getattr(settings, "ENV_TOKENS", {}).get(
"TURNITIN_TCA_API_KEY", settings.TURNITIN_TCA_API_KEY
)

settings.TURNITIN_SIMILARY_REPORT_PAYLOAD = getattr(settings, "ENV_TOKENS", {}).get(
"TURNITIN_SIMILARY_REPORT_PAYLOAD", settings.TURNITIN_SIMILARY_REPORT_PAYLOAD
)

settings.TURNITIN_API_TIMEOUT = getattr(settings, "ENV_TOKENS", {}).get(
"TURNITIN_API_TIMEOUT", settings.TURNITIN_API_TIMEOUT
)
104 changes: 37 additions & 67 deletions platform_plugin_turnitin/turnitin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
from http import HTTPStatus

import pkg_resources
from django.contrib.auth.models import User
from django.conf import settings
from django.contrib.auth import get_user_model
from django.utils import translation
from webob import Response
from xblock.core import XBlock
from xblock.fields import Integer, Scope
from xblock.fragment import Fragment
from xblockutils.resources import ResourceLoader

from platform_plugin_turnitin.models import TurnitinSubmission
from platform_plugin_turnitin.turnitin_client.handlers import (
get_eula_page,
get_similarity_report_info,
Expand All @@ -24,7 +25,7 @@
put_upload_submission_file_content,
)

from .models import TurnitinSubmission
User = get_user_model()


@XBlock.needs("user")
Expand All @@ -44,8 +45,7 @@ def resource_string(self, path):

def studio_view(self, context=None):
"""
The primary view of the TurnitinXBlock, shown to students
when viewing courses.
Show primary view of the TurnitinXBlock, shown to students when viewing courses.
"""
if context:
pass # TO-DO: do something based on the context.
Expand All @@ -67,8 +67,7 @@ def studio_view(self, context=None):
# TO-DO: change this view to display your data your own way.
def student_view(self, context=None):
"""
The primary view of the TurnitinXBlock, shown to students
when viewing courses.
Show primary view of the TurnitinXBlock, shown to students when viewing courses.
"""
if context:
pass # TO-DO: do something based on the context.
Expand All @@ -87,10 +86,9 @@ def student_view(self, context=None):
frag.initialize_js("TurnitinXBlock")
return frag

# ----------------------------------------------------------------------------
def get_user_data(self):
"""
Fetches user-related data, including user ID, email, and name.
Fetch user-related data, including user ID, email, and name.
Returns:
dict: A dictionary containing user ID, email, and name.
Expand All @@ -109,15 +107,15 @@ def get_user_data(self):

def get_django_user(self):
"""
Returns the django user.
Return the django user.
"""
current_user_id = self.get_user_data()["user_id"]
return User.objects.get(id=current_user_id)

@XBlock.json_handler
def get_eula_agreement(self, data, suffix=""):
def get_eula_agreement(self, data, suffix=""): # pylint: disable=unused-argument
"""
Fetches the End User License Agreement (EULA) content.
Fetch the End User License Agreement (EULA) content.
Args:
data (dict): Input data for the request.
Expand All @@ -130,9 +128,9 @@ def get_eula_agreement(self, data, suffix=""):
return {"html": response.text, "status": response.status_code}

@XBlock.json_handler
def accept_eula_agreement(self, data, suffix=""):
def accept_eula_agreement(self, data, suffix=""): # pylint: disable=unused-argument
"""
Submits acceptance of the EULA for the current user.
Submit acceptance of the EULA for the current user.
Args:
data (dict): Input data for the request.
Expand All @@ -153,7 +151,7 @@ def accept_eula_agreement(self, data, suffix=""):

def create_turnitin_submission_object(self):
"""
Constructs a Turnitin submission object based on the user's data.
Create a Turnitin submission object based on the user's data.
Returns:
Response: The response from the Turnitin submission API.
Expand All @@ -163,7 +161,7 @@ def create_turnitin_submission_object(self):

payload = {
"owner": user_data["user_id"],
"title": self.location.block_id,
"title": self.location.block_id, # pylint: disable=no-member
"submitter": user_data["user_id"],
"owner_default_permission_set": "LEARNER",
"submitter_default_permission_set": "INSTRUCTOR",
Expand All @@ -189,9 +187,11 @@ def create_turnitin_submission_object(self):
return post_create_submission(payload)

@XBlock.handler
def upload_turnitin_submission_file(self, data, suffix=""):
def upload_turnitin_submission_file(
self, data, suffix=""
): # pylint: disable=unused-argument
"""
Handles the upload of the user's file to Turnitin.
Handle the upload of the user's file to Turnitin.
Args:
data (WebRequest): Web request containing the file to be uploaded.
Expand Down Expand Up @@ -220,9 +220,9 @@ def upload_turnitin_submission_file(self, data, suffix=""):
)

@XBlock.json_handler
def get_submission_status(self, data, suffix=""):
def get_submission_status(self, data, suffix=""): # pylint: disable=unused-argument
"""
Retrieves the status of the latest Turnitin submission for the user.
Retrieve the status of the latest Turnitin submission for the user.
Args:
data (dict): Input data for the request.
Expand All @@ -242,9 +242,11 @@ def get_submission_status(self, data, suffix=""):
return response.json()

@XBlock.json_handler
def generate_similarity_report(self, data, suffix=""):
def generate_similarity_report(
self, data, suffix=""
): # pylint: disable=unused-argument
"""
Initiates the generation of a similarity report for the user's latest Turnitin submission.
Initialize the generation of a similarity report for the user's latest Turnitin submission.
Args:
data (dict): Input data for the request.
Expand All @@ -253,40 +255,7 @@ def generate_similarity_report(self, data, suffix=""):
Returns:
dict: The status of the similarity report generation process.
"""

payload = {
"indexing_settings": {"add_to_index": True},
"generation_settings": {
"search_repositories": [
"INTERNET",
"SUBMITTED_WORK",
"PUBLICATION",
"CROSSREF",
"CROSSREF_POSTED_CONTENT",
],
"submission_auto_excludes": [
"b84b77d1-da0f-4f45-b002-8aec4f4796d6",
"b86de142-bc44-4f95-8467-84af12b89217",
],
"auto_exclude_self_matching_scope": "ALL",
"priority": "HIGH",
},
"view_settings": {
"exclude_quotes": True,
"exclude_bibliography": True,
"exclude_citations": False,
"exclude_abstract": False,
"exclude_methods": False,
"exclude_custom_sections": False,
"exclude_preprints": False,
"exclude_small_matches": 8,
"exclude_internet": False,
"exclude_publications": False,
"exclude_crossref": False,
"exclude_crossref_posted_content": False,
"exclude_submitted_works": False,
},
}
payload = getattr(settings, "TURNITIN_SIMILARY_REPORT_PAYLOAD") # pylint: disable=literal-used-as-attribute
current_user = self.get_django_user()
try:
last_submission = TurnitinSubmission.objects.filter(
Expand All @@ -300,9 +269,11 @@ def generate_similarity_report(self, data, suffix=""):
return response.json()

@XBlock.json_handler
def get_similarity_report_status(self, data, suffix=""):
def get_similarity_report_status(
self, data, suffix=""
): # pylint: disable=unused-argument
"""
Retrieves the status of the similarity report for the user's latest Turnitin submission.
Retrieve the status of the similarity report for the user's latest Turnitin submission.
Args:
data (dict): Input data for the request.
Expand All @@ -322,9 +293,11 @@ def get_similarity_report_status(self, data, suffix=""):
return response.json()

@XBlock.json_handler
def create_similarity_viewer(self, data, suffix=""):
def create_similarity_viewer(
self, data, suffix=""
): # pylint: disable=unused-argument
"""
Creates a Turnitin similarity viewer for the user's latest submission.
Create a Turnitin similarity viewer for the user's latest submission.
Args:
data (dict): Input data for the request.
Expand Down Expand Up @@ -366,13 +339,9 @@ def create_similarity_viewer(self, data, suffix=""):
)
return response.json()

# ----------------------------------------------------------------------------

# TO-DO: change this to create the scenarios you'd like to see in the
# workbench while developing your XBlock.
@staticmethod
def workbench_scenarios():
"""A canned scenario for display in the workbench."""
"""Define a workbench scenarios."""
return [
(
"TurnitinXBlock",
Expand All @@ -393,7 +362,8 @@ def workbench_scenarios():
@staticmethod
def _get_statici18n_js_url():
"""
Returns the Javascript translation file for the currently selected language, if any.
Return the Javascript translation file for the currently selected language, if any.
Defaults to English if available.
"""
locale_code = translation.get_language()
Expand All @@ -412,6 +382,6 @@ def _get_statici18n_js_url():
@staticmethod
def get_dummy():
"""
Dummy method to generate initial i18n
Return a dummy translation to generate initial i18n.
"""
return translation.gettext_noop("Dummy")
8 changes: 2 additions & 6 deletions platform_plugin_turnitin/turnitin_client/handlers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from .eula import (
get_eula_acceptance_by_user,
get_eula_page,
get_eula_version_info,
post_accept_eula_version,
)
"""Handler module for Turnitin API integration"""
from .eula import get_eula_acceptance_by_user, get_eula_page, get_eula_version_info, post_accept_eula_version
from .similarity_reports import (
get_similarity_report_info,
get_similarity_report_pdf,
Expand Down
10 changes: 6 additions & 4 deletions platform_plugin_turnitin/turnitin_client/handlers/api_handler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""
API handlers for turnitin integration
"""
from typing import Dict, Optional

import requests
from django.conf import settings

from .utils import pretty_print_response

TII_API_URL = getattr(settings, "TURNITIN_TII_API_URL", None)
TCA_INTEGRATION_FAMILY = getattr(settings, "TURNITIN_TCA_INTEGRATION_FAMILY", None)
TCA_INTEGRATION_VERSION = getattr(settings, "TURNITIN_TCA_INTEGRATION_VERSION", None)
Expand Down Expand Up @@ -69,7 +70,8 @@ def turnitin_api_handler(
headers["Content-Type"] = "binary/octet-stream"
headers["Content-Disposition"] = f'inline; filename="{uploaded_file.name}"'
response = requests.put(
f"{TII_API_URL}/api/v1/{url_prefix}", headers=headers, data=uploaded_file
f"{TII_API_URL}/api/v1/{url_prefix}", headers=headers, data=uploaded_file,
timeout=settings.TURNITIN_API_TIMEOUT
)
return response

Expand All @@ -92,4 +94,4 @@ def get_features_enabled():
Returns all the features enabled in the Turnitin account.
"""
response = turnitin_api_handler("get", "features-enabled")
pretty_print_response(response)
return response
Loading

0 comments on commit 6bdae62

Please sign in to comment.