Mercurial > kallithea
changeset 1485:269905fac50a beta
added uploading of files from web interface directly into repo
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 23 Sep 2011 01:52:48 +0300 |
parents | 1db451a44504 |
children | 92f0065ba238 |
files | rhodecode/controllers/files.py rhodecode/model/scm.py rhodecode/public/css/codemirror.css rhodecode/public/css/style.css rhodecode/templates/files/files_add.html rhodecode/templates/files/files_edit.html |
diffstat | 6 files changed, 83 insertions(+), 31 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/controllers/files.py Thu Sep 22 15:03:12 2011 +0300 +++ b/rhodecode/controllers/files.py Fri Sep 23 01:52:48 2011 +0300 @@ -36,7 +36,7 @@ from vcs.conf import settings from vcs.exceptions import RepositoryError, ChangesetDoesNotExistError, \ - EmptyRepositoryError, ImproperArchiveTypeError, VCSError + EmptyRepositoryError, ImproperArchiveTypeError, VCSError, NodeAlreadyExistsError from vcs.nodes import FileNode, NodeKind from vcs.utils import diffs as differ @@ -73,9 +73,9 @@ return None url_ = url('files_add_home', repo_name=c.repo_name, - revision=0,f_path='') - add_new = '<a href="%s">[%s]</a>' % (url_,_('add new')) - h.flash(h.literal(_('There are no files yet %s' % add_new)), + revision=0, f_path='') + add_new = '<a href="%s">[%s]</a>' % (url_, _('add new')) + h.flash(h.literal(_('There are no files yet %s' % add_new)), category='warning') redirect(h.url('summary_home', repo_name=repo_name)) @@ -295,7 +295,7 @@ @HasRepoPermissionAnyDecorator('repository.write', 'repository.admin') def add(self, repo_name, revision, f_path): r_post = request.POST - c.cs = self.__get_cs_or_redirect(revision, repo_name, + c.cs = self.__get_cs_or_redirect(revision, repo_name, redirect_after=False) if c.cs is None: c.cs = EmptyChangeset(alias=c.rhodecode_repo.alias) @@ -310,6 +310,12 @@ % (f_path)) location = r_post.get('location') filename = r_post.get('filename') + file_obj = r_post.get('upload_file', None) + + if file_obj is not None and hasattr(file_obj, 'filename'): + filename = file_obj.filename + content = file_obj.file + node_path = os.path.join(location, filename) author = self.rhodecode_user.full_contact @@ -320,7 +326,7 @@ if not filename: h.flash(_('No filename'), category='warning') return redirect(url('changeset_home', repo_name=c.repo_name, - revision='tip')) + revision='tip')) try: self.scm_model.create_node(repo=c.rhodecode_repo, @@ -330,7 +336,8 @@ content=content, f_path=node_path) h.flash(_('Successfully committed to %s' % node_path), category='success') - + except NodeAlreadyExistsError, e: + h.flash(_(e), category='error') except Exception: log.error(traceback.format_exc()) h.flash(_('Error occurred during commit'), category='error')
--- a/rhodecode/model/scm.py Thu Sep 22 15:03:12 2011 +0300 +++ b/rhodecode/model/scm.py Fri Sep 23 01:52:48 2011 +0300 @@ -360,7 +360,12 @@ from vcs.backends.git import GitInMemoryChangeset as IMC # decoding here will force that we have proper encoded values # in any other case this will throw exceptions and deny commit - content = safe_str(content) + + if isinstance(content,(basestring,)): + content = safe_str(content) + elif isinstance(content,file): + content = content.read() + message = safe_str(message) path = safe_str(f_path) author = safe_str(author)
--- a/rhodecode/public/css/codemirror.css Thu Sep 22 15:03:12 2011 +0300 +++ b/rhodecode/public/css/codemirror.css Fri Sep 23 01:52:48 2011 +0300 @@ -4,6 +4,7 @@ line-height: 1em; font-family: monospace; _position: relative; /* IE6 hack */ + margin:20px; } .CodeMirror-gutter {
--- a/rhodecode/public/css/style.css Thu Sep 22 15:03:12 2011 +0300 +++ b/rhodecode/public/css/style.css Fri Sep 23 01:52:48 2011 +0300 @@ -928,6 +928,9 @@ #content div.box div.form div.fields div.field div.input { margin:0 0 0 200px; } +#content div.box div.form div.fields div.field div.file { +margin:0 0 0 200px; +} #content div.box-left div.form div.fields div.field div.input,#content div.box-right div.form div.fields div.field div.input { margin:0 0 0 0px; } @@ -945,6 +948,17 @@ padding:7px 7px 6px; } +#content div.box div.form div.fields div.field div.file input { + background: none repeat scroll 0 0 #FFFFFF; + border-color: #B3B3B3 #EAEAEA #EAEAEA #B3B3B3; + border-style: solid; + border-width: 1px; + color: #000000; + font-family: Lucida Grande,Verdana,Lucida Sans Regular,Lucida Sans Unicode,Arial,sans-serif; + font-size: 11px; + margin: 0; + padding: 7px 7px 6px; +} #content div.box div.form div.fields div.field div.input input.small { @@ -2359,20 +2373,20 @@ input.ui-button-small { -background:#e5e3e3 url("../images/button.png") repeat-x; -border-top:1px solid #DDD; -border-left:1px solid #c6c6c6; -border-right:1px solid #DDD; -border-bottom:1px solid #c6c6c6; -color:#515151; -outline:none; -margin:0; --webkit-border-radius: 4px 4px 4px 4px; --khtml-border-radius: 4px 4px 4px 4px; --moz-border-radius: 4px 4px 4px 4px; -border-radius: 4px 4px 4px 4px; -box-shadow: 0 1px 0 #ececec; -cursor: pointer; +background:#e5e3e3 url("../images/button.png") repeat-x !important; +border-top:1px solid #DDD !important; +border-left:1px solid #c6c6c6 !important; +border-right:1px solid #DDD !important; +border-bottom:1px solid #c6c6c6 !important; +color:#515151 !important; +outline:none !important; +margin:0 !important; +-webkit-border-radius: 4px 4px 4px 4px !important; +-khtml-border-radius: 4px 4px 4px 4px !important; +-moz-border-radius: 4px 4px 4px 4px !important; +border-radius: 4px 4px 4px 4px !important; +box-shadow: 0 1px 0 #ececec !important; +cursor: pointer !important; } input.ui-button-small:hover {
--- a/rhodecode/templates/files/files_add.html Thu Sep 22 15:03:12 2011 +0300 +++ b/rhodecode/templates/files/files_add.html Fri Sep 23 01:52:48 2011 +0300 @@ -36,7 +36,7 @@ </div> <div class="table"> <div id="files_data"> - ${h.form(h.url.current(),method='post',id='eform')} + ${h.form(h.url.current(),method='post',id='eform',enctype="multipart/form-data")} <h3>${_('Add new file')}</h3> <div class="form"> <div class="fields"> @@ -50,21 +50,33 @@ </div> </div> - <div class="field"> + <div id="filename_container" class="field file"> <div class="label"> <label for="filename">${_('File Name')}:</label> </div> <div class="input"> <input type="text" value="" size="30" name="filename" id="filename"> + <input type="button" class="ui-button-small" value="upload file" id="upload_file_enable"> </div> - </div> + </div> + <div id="upload_file_container" class="field" style="display:none"> + <div class="label"> + <label for="location">${_('Upload file')}</label> + </div> + <div class="file"> + <input type="file" size="30" name="upload_file" id="upload_file"> + <input type="button" class="ui-button-small" value="create file" id="file_enable"> + </div> + </div> </div> </div> <div id="body" class="codeblock"> - <pre id="editor_pre"></pre> - <textarea id="editor" name="content" style="display:none"></textarea> + <div id="editor_container"> + <pre id="editor_pre"></pre> + <textarea id="editor" name="content" style="display:none"></textarea> + </div> <div style="padding: 10px;color:#666666">${_('commit message')}</div> - <textarea id="commit" name="message" style="height: 100px;width: 99%"></textarea> + <textarea id="commit" name="message" style="height: 100px;width: 99%;margin-left:4px"></textarea> </div> <div style="text-align: right;padding-top: 5px"> <input id="reset" type="button" value="${_('Reset')}" class="ui-button-small" /> @@ -76,9 +88,22 @@ mode: "null", lineNumbers:true }); - YUE.on('reset','click',function(){ + YUE.on('reset','click',function(e){ window.location="${h.url('files_home',repo_name=c.repo_name,revision=c.cs.revision,f_path=c.f_path)}"; - }) + }); + + YUE.on('file_enable','click',function(){ + YUD.setStyle('editor_container','display',''); + YUD.setStyle('upload_file_container','display','none'); + YUD.setStyle('filename_container','display',''); + }); + + YUE.on('upload_file_enable','click',function(){ + YUD.setStyle('editor_container','display','none'); + YUD.setStyle('upload_file_container','display',''); + YUD.setStyle('filename_container','display','none'); + }); + </script> </div> </div>
--- a/rhodecode/templates/files/files_edit.html Thu Sep 22 15:03:12 2011 +0300 +++ b/rhodecode/templates/files/files_edit.html Fri Sep 23 01:52:48 2011 +0300 @@ -42,7 +42,7 @@ <pre id="editor_pre"></pre> <textarea id="editor" name="content" style="display:none">${c.file.content|n}</textarea> <div style="padding: 10px;color:#666666">${_('commit message')}</div> - <textarea id="commit" name="message" style="height: 100px;width: 99%"></textarea> + <textarea id="commit" name="message" style="height: 60px;width: 99%;margin-left:4px"></textarea> </div> <div style="text-align: right;padding-top: 5px"> <input id="reset" type="button" value="${_('Reset')}" class="ui-button-small" />