Пример #1
0
def explore(request, iddelivery):
    if(len(request.user.teacher_set.all()) > 0): # if an authenticated user "accidentally" access this section, he doesn't get an exception
        if(os.path.exists(os.path.join(managepath.get_instance().get_temporary_files_path(), str(iddelivery)))):
            shutil.rmtree(os.path.join(managepath.get_instance().get_temporary_files_path(), str(iddelivery)))
        return browse(request, iddelivery)
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
Пример #2
0
def explore(request, iddelivery):
    if (
            len(request.user.teacher_set.all()) > 0
    ):  # if an authenticated user "accidentally" access this section, he doesn't get an exception
        if (os.path.exists(
                os.path.join(
                    managepath.get_instance().get_temporary_files_path(),
                    str(iddelivery)))):
            shutil.rmtree(
                os.path.join(
                    managepath.get_instance().get_temporary_files_path(),
                    str(iddelivery)))
        return browse(request, iddelivery)
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
Пример #3
0
class Delivery(models.Model):
    """Delivery class.
    
    It is the object or artifact that the Student presents as his work for a
    given assignment. In this case it is considered required to be a zip 
    package.
     
    """
    file = models.FileField(
        upload_to=managepath.get_instance().get_delivery_path())
    student = models.ForeignKey(Student)
    practice = models.ForeignKey(Practice)
    deliverDate = models.DateField()
    deliverTime = models.TimeField(auto_now=True)
    corrector = models.ForeignKey(Teacher, null=True, blank=True)

    def __str__(self):
        """Stringify the Delivery"""
        return (str(self.practice) + " - " + str(self.student) + " - " +
                str(self.deliverDate))

    def get_correction(self):
        if self.correction_set.exists():
            return self.correction_set.all()[0]
        else:
            return None

    def get_automatic_correction(self):
        if (self.automaticcorrection_set.all().exists()):
            return self.automaticcorrection_set.all()[0]
        else:
            return None

    class Meta:
        ordering = ('-deliverDate', '-deliverTime')
Пример #4
0
def browse(request, iddelivery, file_to_browse=None):
    if (
            len(request.user.teacher_set.all()) > 0
    ):  # if an authenticated user "accidentally" access this section, he doesn't get an exception
        delivery = Delivery.objects.get(pk=iddelivery)
        extraction_dir = os.path.join(
            managepath.get_instance().get_temporary_files_path(),
            str(delivery.pk))
        if (not os.path.exists(extraction_dir)):
            zipfile = ZipFile(delivery.file)
            zipfile.extractall(extraction_dir)

        files_list = []
        walk_directory(files_list, extraction_dir, None)

        if (file_to_browse is None):
            file_content = None
        else:
            file_path = os.path.join(extraction_dir, file_to_browse)
            with open(file_path, 'r') as content_file:
                file_content = content_file.read()
        return render(
            request, 'delivery/browsedelivery.html', {
                'delivery': delivery,
                'files_list': files_list,
                'file_content': file_content
            })
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
Пример #5
0
class Script(models.Model):
    """
    
    This class is the holder for the scripts associated with each practice that
    will be run to check the deliveries in an automatic way.
    
    """
    
    practice = models.ForeignKey(Practice, unique=True)
    file = models.FileField(upload_to=managepath.get_instance().get_script_path(), max_length=128)

    def __str__(self):
        return str(self.practice)
Пример #6
0
def step(context, practice_name, practice_file_id):
    practice_path = managepath.get_instance().get_practice_path()
    if not os.path.exists(practice_path):
        os.makedirs(name=practice_path)
    practice_filename = "practice_no_text_file.pdf"
    practice_filepath = os.path.join(practice_path, practice_filename)
    with open(practice_filepath, 'w') as test_file:
        lines = [
            "first line\n", "second line\n", "third line\n", "fourth line\n",
            "fifth line\n"
        ]
        test_file.writelines(lines)
    practice = Practice.objects.filter(uid=practice_name)[0]
    practice_file = PracticeFile()
    practice_file.pk = practice_file_id
    practice_file.name = "Prueba"
    practice_file.file = practice_filepath
    practice_file.practice = practice
    practice_file.save()
Пример #7
0
def step(context, practice_name, practice_file_id):
    practice_path = managepath.get_instance().get_practice_path()
    if not os.path.exists(practice_path):
        os.makedirs(name=practice_path)
    practice_filename = "practice_no_text_file.pdf"
    practice_filepath = os.path.join(practice_path, practice_filename)
    with open(practice_filepath, 'w') as test_file:
        lines = ["first line\n",
                 "second line\n",
                 "third line\n",
                 "fourth line\n",
                 "fifth line\n"]
        test_file.writelines(lines)
    practice = Practice.objects.filter(uid=practice_name)[0]
    practice_file = PracticeFile()
    practice_file.pk = practice_file_id
    practice_file.name = "Prueba"
    practice_file.file = practice_filepath
    practice_file.practice = practice
    practice_file.save()
Пример #8
0
class PracticeFile(models.Model):
    """
    
    This class is the holder for the practice file associated with each practice.
    
    """
    practice = models.ForeignKey(Practice)
    name = models.CharField(max_length=32)
    file = models.FileField(
        upload_to=managepath.get_instance().get_practice_path())

    def __str__(self):
        """Stringify the Practice or assignment"""
        return (str(self.name))

    def isEditable(self):
        mime = str(mimetypes.guess_type(self.file.name)[0])
        pos = mime.find(TYPEEDITABLE)
        if (pos == 0):
            return True
        return False
Пример #9
0
def browse(request, iddelivery, file_to_browse=None):
    if(len(request.user.teacher_set.all()) > 0): # if an authenticated user "accidentally" access this section, he doesn't get an exception
        delivery = Delivery.objects.get(pk=iddelivery);
        extraction_dir = os.path.join(managepath.get_instance().get_temporary_files_path(), str(delivery.pk))
        if (not os.path.exists(extraction_dir)):
            zipfile = ZipFile(delivery.file)
            zipfile.extractall(extraction_dir)
        
        files_list = []
        walk_directory(files_list, extraction_dir, None)
        
        if (file_to_browse is None):
            file_content = None
        else:
            file_path = os.path.join(extraction_dir, file_to_browse)
            with open(file_path, 'r') as content_file:
                file_content = content_file.read()
        return render(request, 'delivery/browsedelivery.html', 
                      {'delivery': delivery, 'files_list': files_list, 'file_content': file_content})
    else:
        return HTTP_401_UNAUTHORIZED_RESPONSE
Пример #10
0
def step(context, practice_uid, course_name, student_uid, delivery_id):
    student = Student.objects.get(uid=student_uid)
    course = Course.objects.get(name=course_name)
    practice = Practice.objects.get(uid=practice_uid, course=course)
    # delivery = Delivery.objects.get_or_create(pk=delivery_id, student=student, practice=practice)
    delivery = Delivery()
    delivery.pk = delivery_id
    src = "data/delivery.zip"
    delivery_path = managepath.get_instance().get_delivery_path()
    dst = os.path.join(delivery_path, "delivery.zip")
    if (not os.path.exists(delivery_path)):
        makedirs(delivery_path)
    if (not os.path.exists(dst)):
        copyfile(src, dst)
    delivery.file = dst
    delivery.student = student
    delivery.practice = practice
    delivery.deliverDate = '2012-11-22'
    delivery.save()
    automatic_correction = AutomaticCorrection()
    automatic_correction.delivery = delivery
    automatic_correction.save()
Пример #11
0
def step(context, practice_uid, course_name, student_uid, delivery_id):
    student = Student.objects.get(uid=student_uid)
    course = Course.objects.get(name=course_name)
    practice = Practice.objects.get(uid=practice_uid, course=course)
    # delivery = Delivery.objects.get_or_create(pk=delivery_id, student=student, practice=practice)
    delivery = Delivery()
    delivery.pk = delivery_id
    src = "data/delivery.zip"
    delivery_path = managepath.get_instance().get_delivery_path()
    dst = os.path.join(delivery_path, "delivery.zip")
    if(not os.path.exists(delivery_path)):
        makedirs(delivery_path)
    if(not os.path.exists(dst)):
        copyfile(src, dst)
    delivery.file = dst
    delivery.student = student
    delivery.practice = practice
    delivery.deliverDate = '2012-11-22'
    delivery.save()
    automatic_correction = AutomaticCorrection()
    automatic_correction.delivery = delivery
    automatic_correction.save()
Пример #12
0
from behave import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from seal.model import Course, Student, Practice, Delivery, Suscription

import ConfigParser
from seal.model.automatic_correction import AutomaticCorrection
import time
from seal.utils import managepath
from seal.model.shift import Shift

pathproject = managepath.get_instance().get_web_path()
filePath = pathproject + "feature_test/data/pdftest.pdf"
deliveryPath = pathproject + "feature_test/data/delivery.zip"
scriptPath = pathproject + "feature_test/data/"

base_url = 'http://*****:*****@when('I am in the index page')
def step(context):
    context.browser.get(base_url)
Пример #13
0
from behave import *
from parse import *
from selenium import webdriver
from django.core.files import File
import shutil

# The next few steps are required to load the configuration and include the application model for the behavioural tests.
import os, sys
from django.contrib.auth import login
from seal.utils import managepath

sys.path.append(managepath.get_instance().get_web_path())         # Required to use the app model
sys.path.append(managepath.get_instance().get_daemon_path())
sys.path.append(managepath.get_instance().get_model_path()) # Fixes 'No module named model'
os.environ['DJANGO_SETTINGS_MODULE'] = 'seal.settings'

practicePath = managepath.get_instance().get_practice_path()
deliveryPath = managepath.get_instance().get_delivery_path()
scriptPath = managepath.get_instance().get_script_path()

# Now we can load our model
from seal.model import Course, Student, Practice, Delivery, Teacher, Correction, Suscription, Mail
from django.contrib.auth.models import User

def before_all(context):
    Suscription.objects.all().delete()
    Correction.objects.all().delete()
    Delivery.objects.all().delete()
    Practice.objects.all().delete()
    Course.objects.all().delete()
    Student.objects.all().delete() # Given Students are authenticated users, can't delete them without deleting the users
Пример #14
0
from behave import *
from selenium import webdriver
from selenium.webdriver.common.by import By
from seal.model import Course, Student, Practice, Delivery, Suscription

import ConfigParser
from seal.model.automatic_correction import AutomaticCorrection
import time
from seal.utils import managepath
from seal.model.shift import Shift

pathproject = managepath.get_instance().get_web_path()
filePath = pathproject + "feature_test/data/pdftest.pdf"
deliveryPath = pathproject + "feature_test/data/delivery.zip"
scriptPath = pathproject + "feature_test/data/"

base_url = 'http://*****:*****@when('I am in the index page')
def step(context):
    context.browser.get(base_url)

@when('I log in as "{usr}" "{passwd}"')
def step(context, usr, passwd):
Пример #15
0
from behave import *
from parse import *
from selenium import webdriver
from django.core.files import File
import shutil

# The next few steps are required to load the configuration and include the application model for the behavioural tests.
import os, sys
from django.contrib.auth import login
from seal.utils import managepath

sys.path.append(
    managepath.get_instance().get_web_path())  # Required to use the app model
sys.path.append(managepath.get_instance().get_daemon_path())
sys.path.append(managepath.get_instance().get_model_path()
                )  # Fixes 'No module named model'
os.environ['DJANGO_SETTINGS_MODULE'] = 'seal.settings'

practicePath = managepath.get_instance().get_practice_path()
deliveryPath = managepath.get_instance().get_delivery_path()
scriptPath = managepath.get_instance().get_script_path()

# Now we can load our model
from seal.model import Course, Student, Practice, Delivery, Teacher, Correction, Suscription, Mail
from django.contrib.auth.models import User


def before_all(context):
    Suscription.objects.all().delete()
    Correction.objects.all().delete()
    Delivery.objects.all().delete()