Beispiel #1
0
 def new(self, **kw):
     project = DBSession.query(Project).filter_by(id=kw['project_id']).one()
     file = File(project=project, filename='%s.latex' % kw['filename'])
     DBSession.add(FileRevision(file=file,
                                user=request.identity['user']))
     DBSession.flush()
     flash(_('The file "%s.latex" has been added to the project.' % kw['filename']))
     
     return dict(_status=u'ok', _redirect=url('/editor/edit/%s' % file.id))
Beispiel #2
0
 def add_do(self, title, **kw):
     project = Project(title=title, description=kw.get('description', u''),
                       creator=request.identity['user'])
     project.members.append(ProjectMembership(user=request.identity['user']))
     DBSession.add(project)
     DBSession.flush()
     
     flash(_('Project "%s" has been created' % title))
     return dict(_status=u'ok',
                 _redirect=url('/projects/view/%d' % project.id))
Beispiel #3
0
 def setup(self):
     try:
         new_attrs = {}
         new_attrs.update(self.attrs)
         new_attrs.update(self.do_get_dependencies())
         self.obj = self.klass(**new_attrs)
         DBSession.add(self.obj)
         DBSession.flush()
         return self.obj
     except:
         DBSession.rollback()
         raise
Beispiel #4
0
    def compile(self, file_id, content):
        file = DBSession.query(File).filter_by(id=file_id).one()
        run = LaTeXCompileRun(file=file, content=content)

        if run.compile():
            DBSession.add(run)
            DBSession.flush()
            return dict(
                _msg=_("The file compiled successfully."),
                _status=u"ok",
                run_id=run.id,
                pdf_url=url("/files/download/%s" % run.id),
                ps_url=url("/files/download/%s/ps" % run.id),
                dvi_url=url("/files/download/%s/dvi" % run.id),
                latex_log=run.latex_log,
            )
        else:
            return dict(
                _msg=_("The file could not be compiled. Check the log for further details."),
                _status="error",
                latex_log=run.latex_log,
            )
Beispiel #5
0
    def upload(self, **kw):
        project = DBSession.query(Project).filter_by(id=kw['project_id']).one()

        content_type = kw['file'].type
        
        # XXX: We assume files ending in .latex or .tex are LaTeX files
        if kw['file'].filename.lower().endswith('.tex') or \
           kw['file'].filename.lower().endswith('.latex'):
            content_type = u'text/x-latex'
                    
        rev = FileRevision(file=File(project=project, filename=kw['file'].filename,
                                     content_type=content_type),
                           user=request.identity['user'])
        
        if rev.file.content_type in (config.get('vertex_text_types') + config.get('vertex_latex_types')):
            rev.content = kw['file'].value
        else:
            rev.content_binary = kw['file'].value
    
        DBSession.add(rev)
        DBSession.flush()

        flash(_('The file "%s" has been added to the project.' % (kw['file'].filename)))
        redirect(url('/editor/edit/%s' % rev.file.id))