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

« back to all changes in this revision

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

  • Committer: dcoles
  • Date: 2008-05-09 07:43:37 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:753
Upload: Patch submitted by 'wagrant' to fix file upload of dos formated files 
and prevent corruption of upload files.

wagrant wrote:
> Last night I set up IVLE in my Gutsy schroot, and debugged it further.
> Looking deeper at the code, I noted it was a different error from the one I
> thought it was (an incorrect header, rather than lack of a Content-Type).
> This made the cause and fix obvious.
>
> http://qeuni.net/ivle_bug_1942845.diff fixes it for me in all the
> situations I can think of. It checks for the length of the header section
> obtained by splitting on a double LF then double CRLF, and takes the
> smaller one as the headers. In the old code, any output with a double CRLF
> in the body would have anything before the first CRLF treated as headers,
> which is wrong. Double LFs weren't affected because LFs are used by default
> to terminate the real headers.
>
> I apparently can't attach things (argh! I hate the SourceForge bug
> tracker).


Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# IVLE - Informatics Virtual Learning Environment
2
 
# Copyright (C) 2007-2009 The University of Melbourne
3
 
#
4
 
# This program is free software; you can redistribute it and/or modify
5
 
# it under the terms of the GNU General Public License as published by
6
 
# the Free Software Foundation; either version 2 of the License, or
7
 
# (at your option) any later version.
8
 
#
9
 
# This program is distributed in the hope that it will be useful,
10
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 
# GNU General Public License for more details.
13
 
#
14
 
# You should have received a copy of the GNU General Public License
15
 
# along with this program; if not, write to the Free Software
16
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
 
 
18
 
# Author: Nick Chadwick
19
 
 
20
 
import ivle.database
21
 
from ivle.database import ProjectSet, Project, Subject, Semester, Offering
22
 
 
23
 
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
24
 
                                   require_permission)
25
 
from ivle.webapp.errors import NotFound
26
 
 
27
 
class ProjectSetRESTView(XHTMLRESTView):
28
 
    """Rest view for a projectset.
29
 
    
30
 
    Add new, delete, edit functionality is given here."""
31
 
    template = "templates/projectset_fragment.html"
32
 
    
33
 
    def __init__(self, req, subject, year, semester, projectset):
34
 
        self.context = req.store.find(ProjectSet,
35
 
            ProjectSet.id == int(projectset),
36
 
            ProjectSet.offering_id == Offering.id,
37
 
            Offering.subject_id == Subject.id,
38
 
            Subject.short_name == unicode(subject),
39
 
            Offering.semester_id == Semester.id,
40
 
            Semester.year == unicode(year),
41
 
            Semester.semester == unicode(semester)).one()
42
 
        
43
 
        if self.context is None:
44
 
            raise NotFound()
45
 
 
46
 
    def _project_url(self, project):
47
 
        return "/subjects/%s/%s/%s/+projects/%s" % \
48
 
                (self.context.offering.subject.short_name,
49
 
                 self.context.offering.semester.year,
50
 
                 self.context.offering.semester.semester,
51
 
                 project.short_name)
52
 
 
53
 
    @named_operation('edit')
54
 
    def add_project(self, req, name, short_name, synopsis):
55
 
        """Add a Project to this ProjectSet"""
56
 
        new_project = Project()
57
 
        new_project.name = unicode(name)
58
 
        new_project.short_name = unicode(short_name)
59
 
        new_project.synopsis = unicode(synopsis)
60
 
        new_project.project_set = self.context
61
 
 
62
 
        req.store.add(new_project)
63
 
        req.store.flush()
64
 
    
65
 
        self.template = "templates/project_fragment.html"
66
 
        self.ctx['project'] = new_project
67
 
        self.ctx['project_url'] = self._project_url(new_project)
68
 
 
69
 
        return {'success': True, 'projectset_id': self.context.id}
70
 
 
71
 
class ProjectRESTView(XHTMLRESTView):
72
 
    """Rest view for a project."""