~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/projectservice.py

Created a new view for IVLE, allowing lecturers and tutors to 
administrate projects.

At the moment, this new view can add projectsets, and add projects.
It can also view the details of a project.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# Author: Nick Chadwick
19
19
 
20
20
import ivle.database
21
 
from ivle.data import ProjectSet, Project, Subject, Semester, Offering
 
21
from ivle.database import ProjectSet, Project, Subject, Semester, Offering
22
22
 
23
23
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
24
24
                                   require_permission)
25
25
from ivle.webapp.errors import NotFound
26
26
 
27
 
class ProjectSETRESTView(XHTMLRESTView):
28
 
    """Rest view for a project.
 
27
class ProjectSetRESTView(XHTMLRESTView):
 
28
    """Rest view for a projectset.
29
29
    
30
30
    Add new, delete, edit functionality is given here."""
31
 
    template = "projectset.html"
 
31
    template = "templates/projectset_fragment.html"
32
32
    
33
33
    def __init__(self, req, subject, year, semester, projectset):
34
 
        self.context = req.store.find(Offering,
 
34
        self.context = req.store.find(ProjectSet,
 
35
            ProjectSet.id == int(projectset),
 
36
            ProjectSet.offering_id == Offering.id,
35
37
            Offering.subject_id == Subject.id,
36
38
            Subject.short_name == unicode(subject),
37
39
            Offering.semester_id == Semester.id,
38
40
            Semester.year == unicode(year),
39
 
            Semester.semester == unicode(semester))
 
41
            Semester.semester == unicode(semester)).one()
40
42
        
41
43
        if self.context is None:
42
44
            raise NotFound()
43
 
        
44
 
        self.projectset = req.store.find(ProjectSet,
45
 
            ProjectSet.offering_id == self.context.id,
46
 
            ProjectSet.id == int(projectset))
 
45
 
 
46
    def _project_url(self, project):
 
47
        return "/subjects/" + str(self.context.offering.subject.id) + "/" +\
 
48
               str(self.context.offering.semester.year) + "/" +\
 
49
               self.context.offering.semester.semester + "/+projectsets/" +\
 
50
               str(self.context.id) + "/+projects/+new"
 
51
 
 
52
    @named_operation('edit')
 
53
    def add_project(self, req, name, short_name, synopsis):
 
54
        """Add a Project to this ProjectSet"""
 
55
        new_project = Project()
 
56
        new_project.name = unicode(name)
 
57
        new_project.short_name = unicode(short_name)
 
58
        new_project.synopsis = unicode(synopsis)
 
59
        new_project.project_set = self.context
 
60
 
 
61
        req.store.add(new_project)
 
62
        req.store.flush()
47
63
    
48
 
    @require_permission('edit')
49
 
    def PUT(self, req, max_students):
50
 
        """Add a new ProjectSet"""
51
 
        new_projectset = ProjectSet()
52
 
        new_projectset.max_students = int(max_students)
53
 
        new_projectset.offering = self.context
54
 
        
55
 
        
 
64
        self.template = "templates/project_fragment.html"
 
65
        self.ctx['project'] = new_project
 
66
        self.ctx['project_url'] = self._project_url(new_project)
 
67
 
 
68
        return {'success': True, 'projectset_id': self.context.id}
 
69
 
 
70
class ProjectRESTView(XHTMLRESTView):
 
71
    """Rest view for a project."""