Skip to content

Commit

Permalink
Add docstrings to all modules
Browse files Browse the repository at this point in the history
  • Loading branch information
kdryja committed Apr 16, 2018
1 parent dc91a9c commit f8d0283
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 33 deletions.
8 changes: 7 additions & 1 deletion app/admin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
from django.contrib import admin
"""
Admin module enabling built-in administrative panel
@TeamAlpha 2018
CodeMarker
admin.py
"""

# Register your models here.

Expand Down
8 changes: 8 additions & 0 deletions app/apps.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""
Auto-generated module by Django registering the app with the service
@TeamAlpha 2018
CodeMarker
apps.py
"""

from django.apps import AppConfig


Expand Down
1 change: 1 addition & 0 deletions app/backup_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
@TeamAlpha 2018
CodeMarker
backup_service.py
"""

import os
Expand Down
17 changes: 13 additions & 4 deletions app/docker_processor.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
"""
Module containing instructions on how to execute submissions in docker containers.
Utilizes docker pip package and created bash scripts (inside 'scripts' folder) that are running submissions
@TeamAlpha 2018
CodeMarker
docker_processor.py
"""

import os
import docker
from codemarker.settings import MEDIA_ROOT
import os


def run_dynamic(submission):
Expand All @@ -22,7 +31,7 @@ def run_dynamic(submission):
{
'bind': '/mnt/vol2',
'mode': 'ro'
}
}
},
command=f"/bin/bash /mnt/vol2/run_dynamic.sh {submission.filename} {submission.assessment_id} {submission.id} {submission.language}")

Expand All @@ -43,7 +52,7 @@ def run_static(submission, assessment):
'mode': 'rw'
},
os.path.join(MEDIA_ROOT, '..', 'scripts'):
{
{
'bind': '/mnt/vol2',
'mode': 'ro'
}
Expand All @@ -69,6 +78,6 @@ def generate_input(submission, resource_language):
{
'bind': '/mnt/vol2',
'mode': 'ro'
}
}
},
command=f"/bin/bash /mnt/vol2/generate.sh {submission.assessment_id} {resource_language}")
40 changes: 32 additions & 8 deletions app/factory.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
import codecs
import csv
"""
Module containing creators for subsequent elements, such as assessments or submissions.
Adheres to 'factory' architectural pattern.
Factories to create new resources with lengthy methods.
@TeamAlpha 2018
CodeMarker
factory.py
"""

import json
import logging
import os
Expand All @@ -9,8 +18,7 @@
from django.core.exceptions import ObjectDoesNotExist
from django.core.files.storage import FileSystemStorage
from django.db import DataError
from django.http import (HttpResponse, HttpResponseBadRequest,
HttpResponseForbidden)
from django.http import (HttpResponseBadRequest, HttpResponseForbidden)
from django.utils.datastructures import MultiValueDictKeyError
from rest_framework.response import Response

Expand All @@ -21,12 +29,16 @@
logger = logging.getLogger(__name__)


"""
Factories to create new resources with lengthy methods.
"""
def assessment_creator(self, serializer):
"""Method responsible for creating new assessments
Raises:
MultiValueDictKeyError -- Raised when not enough arguments have been passed
Returns:
HttpResponse -- Whether resource has been successfully created or not
"""

def assessment_creator(self, serializer):
try:
user = self.request.user
name = self.request.POST.get("name", "")
Expand Down Expand Up @@ -136,10 +148,22 @@ def assessment_creator(self, serializer):


def course_creator(self, serializer):
"""
Dummy method for course creation, for future reference
"""

pass


def submission_creator(self, serializer):
"""Method for creating new submissions
Arguments:
serializer - passed from the views class, contains POST information
Returns:
HttpResponse - whether creation was successful or not
"""

try:
assessment_id = self.request.POST['assessment_id']
Expand Down
8 changes: 8 additions & 0 deletions app/forms.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
"""
Autogenerated module by Django
@TeamAlpha 2018
CodeMarker
forms.py
"""

from django import forms
from codemarker.models import Submission

Expand Down
19 changes: 13 additions & 6 deletions app/models.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from django_mysql.models import EnumField
from django_mysql.models import ListCharField
from django.utils import timezone
from django.conf import settings
from django.db import models
"""
Models information for all entities used in the system
@TeamAlpha 2018
CodeMarker
models.py
"""

import datetime

from django.conf import settings
from django.db import models
from django.utils import timezone
from django_mysql.models import EnumField, ListCharField
# Create your models here.
from rest_framework.compat import MinValueValidator, MaxValueValidator
from rest_framework.compat import MaxValueValidator, MinValueValidator


class Course(models.Model):
Expand Down
14 changes: 11 additions & 3 deletions app/serializers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
from rest_framework import serializers
from django.contrib.auth.models import User
"""
Autogenerated module by Django used to serialize Data used by the application
@TeamAlpha 2018
CodeMarker
serializers.py
"""

from app.models import Course, Assessment, Submission
from django.contrib.auth.models import User
from rest_framework import serializers
from rest_framework.fields import CurrentUserDefault

from app.models import Assessment, Course, Submission


class SubmissionSerializer(serializers.ModelSerializer):
class Meta:
Expand Down
8 changes: 7 additions & 1 deletion app/signals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# signals.py
"""
Autogenerated module by Django.
@TeamAlpha 2018
CodeMarker
signals.py
"""

from django.db.models.signals import post_save
from django.contrib.auth.models import User
Expand Down
13 changes: 11 additions & 2 deletions app/submission_processor.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
"""
Module responsible for all Business Logic related to marking and assessing the solution.
Uses filecmp to compare desired outputs with actual outputs to assign specific marks.
@TeamAlpha 2018
CodeMarker
submission_processor.py
"""

import filecmp
import json
import os

from django.core import serializers

from app.docker_processor import generate_input, run_dynamic, run_static
from app.models import Assessment, Resource, Submission
from codemarker.settings import MEDIA_ROOT
from app.docker_processor import run_dynamic, run_static, generate_input
from app.models import Submission, Resource, Assessment


def run_submission(submission_id, **kwargs):
Expand Down
10 changes: 8 additions & 2 deletions app/urls.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
"""
Autogenerated module by Django.
@TeamAlpha 2018
CodeMarker
urls.py
"""

import django.conf.urls

from . import views

urlpatterns = [
django.conf.urls.url(r'$', views.index, name='index'),
]


19 changes: 13 additions & 6 deletions app/views.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
"""
Module with all entry points definitions, i.e. what site should be served if
user tries to access any given URL
@TeamAlpha 2018
CodeMarker
views.py
"""

import logging

from django.contrib.auth.models import User
from django.http import (HttpResponse, HttpResponseBadRequest,
HttpResponseForbidden, HttpResponseServerError)
from django.views.decorators.csrf import csrf_exempt
from rest_framework import generics, viewsets
from rest_framework.authtoken.models import Token
from rest_framework.authtoken.views import ObtainAuthToken
Expand Down Expand Up @@ -40,6 +48,10 @@ def post(self, request, *args, **kwargs):


def index(request):
"""
Main entry point, displays Hello World message if user accesses root URL
"""

return HttpResponse("Hello world. You're at the codemarker index.")


Expand Down Expand Up @@ -86,7 +98,6 @@ def post(self, request, *args, **kwargs):
return import_users(request)


# TODO: Add permissions
class UserViewSet(viewsets.ModelViewSet):
permission_classes = (DjangoModelPermissions,)
queryset = User.objects.all()
Expand Down Expand Up @@ -138,10 +149,6 @@ def get_queryset(self):
if user.is_superuser or user.is_staff:
return Course.objects.all()

# TODO: Find a way a attach a teacher to a course
# if user.is_staff:
# return Course.objects.filter(professor=user)

return Course.objects.filter(students=user)


Expand Down

0 comments on commit f8d0283

Please sign in to comment.