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

« back to all changes in this revision

Viewing changes to ivle/database.py

  • Committer: David Coles
  • Date: 2010-07-20 07:05:34 UTC
  • Revision ID: coles.david@gmail.com-20100720070534-lf6de6rdszt1rchn
Fix svnremove typo in r1804

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import datetime
28
28
import os
29
29
import urlparse
 
30
import urllib
30
31
 
31
32
from storm.locals import create_database, Store, Int, Unicode, DateTime, \
32
33
                         Reference, ReferenceSet, Bool, Storm, Desc
230
231
        """Find a user in a store by login name."""
231
232
        return store.find(cls, cls.login == unicode(login)).one()
232
233
 
233
 
    def get_svn_url(self, config):
 
234
    def get_svn_url(self, config, req):
234
235
        """Get the subversion repository URL for this user or group."""
 
236
        login = req.user.login
 
237
        url = urlparse.urlsplit(config['urls']['svn_addr'])
 
238
        url = urlparse.urlunsplit(url[:1] + (login+'@'+url[1],) + url[2:])
235
239
        path = 'users/%s' % self.login
236
 
        return urlparse.urljoin(config['urls']['svn_addr'], path)
 
240
        return urlparse.urljoin(url, path)
237
241
 
238
242
    def get_permissions(self, user, config):
239
243
        """Determine privileges held by a user over this object.
731
735
            Semester.id == Offering.semester_id,
732
736
            (not active_only) or (Semester.state == u'current'))
733
737
 
734
 
    def get_svn_url(self, config):
 
738
    def get_svn_url(self, config, req):
735
739
        """Get the subversion repository URL for this user or group."""
 
740
        login = req.user.login
 
741
        url = urlparse.urlsplit(config['urls']['svn_addr'])
 
742
        url = urlparse.urlunsplit(url[:1] + (login+'@'+url[1],) + url[2:])
736
743
        path = 'groups/%s_%s_%s_%s' % (
737
744
                self.project_set.offering.subject.short_name,
738
745
                self.project_set.offering.semester.year,
739
746
                self.project_set.offering.semester.semester,
740
747
                self.name
741
748
                )
742
 
        return urlparse.urljoin(config['urls']['svn_addr'], path)
 
749
        return urlparse.urljoin(url, path)
743
750
 
744
751
    def get_permissions(self, user, config):
745
752
        if user.admin or user in self.members:
905
912
        return "/files/%s/%s/%s?r=%d" % (user.login,
906
913
            self.assessed.checkout_location, submitpath, self.revision)
907
914
 
 
915
    def get_svn_url(self, req):
 
916
        """Get subversion URL for this submission"""
 
917
        princ = self.assessed.principal
 
918
        base = princ.get_svn_url(req.config, req)
 
919
        if self.path.startswith(os.sep):
 
920
            return os.path.join(base,
 
921
                    urllib.quote(self.path[1:].encode('utf-8')))
 
922
        else:
 
923
            return os.path.join(base, urllib.quote(self.path.encode('utf-8')))
 
924
 
 
925
    def get_svn_checkout_command(self, req):
 
926
        svn_url = self.get_svn_url(req)
 
927
        return "svn export -r%d '%s'"%(self.revision, svn_url)
 
928
 
908
929
    @staticmethod
909
930
    def test_and_normalise_path(path):
910
931
        """Test that path is valid, and normalise it. This prevents possible