__author__="lreqc"
__date__ ="$2009-09-08 14:31:26$"
-from django.core.management.base import BaseCommand
-from django.utils import simplejson as json
-from django.test.client import Client
-from django.core.urlresolvers import reverse
-
-from optparse import make_option
-
-class Command(BaseCommand):
-
- option_list = BaseCommand.option_list + (
- make_option('-u', '--user', action='store', dest='username'),
- make_option('-p', '--password', action='store', dest='password'),
- )
-
+from django.core.management.base import NoArgsCommand
+
+# from optparse import make_option
+
+class Command(NoArgsCommand):
+
def handle(self, *args, **options):
client = Client()
if not options['username'] or not options['password']:
@permission_required('explorer.can_add_files')
@with_repo
def file_upload(request, repo):
- other_errors = []
- if request.method == 'POST':
- form = forms.BookUploadForm(request.POST, request.FILES)
- if form.is_valid():
- try:
- # prepare the data
- f = request.FILES['file']
- decoded = f.read().decode('utf-8')
- fileid = form.cleaned_data['bookname'].lower()
- rpath = file_path(fileid)
-
- if form.cleaned_data['autoxml']:
- decoded = librarian.wrap_text(decoded, unicode(date.today()) )
-
- def upload_action():
- repo._add_file(rpath, decoded.encode('utf-8') )
- repo._commit(message="File %s uploaded by user %s" % \
- (rpath, request.user.username), user=request.user.username)
-
- repo.in_branch(upload_action, 'default')
+ from api.resources import library_resource
+ from api.forms import DocumentUploadForm
+ from django.http import HttpRequest, HttpResponseRedirect
- # if everything is ok, redirect to the editor
- return HttpResponseRedirect( reverse('editor_view',
- kwargs={'path': fileid}) )
+ response = library_resource.handler.create(request)
- except hg.RepositoryException, e:
- other_errors.append(u'Błąd repozytorium: ' + unicode(e) )
- #except UnicodeDecodeError, e:
- # other_errors.append(u'Niepoprawne kodowanie pliku: ' + e.reason \
- # + u'. Żądane kodowanie: ' + e.encoding)
- # invalid form
-
- # get
- form = forms.BookUploadForm()
- return direct_to_template(request, 'explorer/file_upload.html',\
- extra_context = {'form' : form, 'other_errors': other_errors})
-
+ if isinstance(response, HttpResponse):
+ data = json.loads(response.content)
+
+ if response.status_code == 201:
+ return HttpResponseRedirect( \
+ reverse("editor_view", args=[ data['name'] ]) )
+ else:
+ bookform = DocumentUploadForm(request.POST, request.FILES)
+ bookform.is_valid()
+
+ return direct_to_template(request, 'explorer/file_upload.html',
+ extra_context={'bookform': bookform } )
+
+
#
# Edit the file
#
}
a:link, a:visited, a:active {
- color: #395428;
+ color: #860000;
text-decoration: none;
font-weight: bold;
}
a:hover {
text-decoration: underline;
-}
\ No newline at end of file
+}
+
+.toolbar-buttons-container {
+ background-color: #E2CF62;
+}
+
+.toolbar-tabs-container {
+ background-color: #860000;
+}
+
.image-gallery-page-container img {
/* border: 2px solid green; */
margin: 0px;
+}
+
+body#base button {
+ background-color: #DDD;
+ border-width: 1px;
+ padding: 0px 0.5em;
+ font-family: Sans-Serif;
+ color: #000;
+ margin: 2px 4px;
+}
+
+body#base button:hover {
+ background-color: #EEE;
}
\ No newline at end of file
-/* .toolbar {
- overflow: hidden;
- z-index: 100;
- background: #AAA;
- position: absolute;
- top: 0px; left:0px; right: 0px;
- height: auto;
- padding: 2px;
- margin: 0px;
-}
-
-.toolbar p {
- margin: 0px;
-
- padding: 0px;
- padding-left: 0.5em;
-
- border: none;
- background: #AAA;
- font-size: 10px;
- line-height: 12px;
-}
-
-.toolbar div {
- background: green;
- margin: 0px;
- padding: 0px;
-} */
-
-.toolbar-buttons-container {
- background: #DDD;
+.toolbar-buttons-container {
padding-top: 2px;
padding-bottom: 2px;
}
-.toolbar-buttons-container a {
- background: #DDD;
- border: none;
- padding: 2px 0.5em;
- background: #AAA;
- font-family: Sans-Serif;
- color: #000;
- text-decoration: none;
-}
-
-.toolbar-buttons-container a:hover {
- background: #EEE;
-}
-
-.toolbar-buttons-container a:active {
- background: yellow;
-}
-
-.panel-toolbar-extra a {
- background: inherit;
-}
-
-.toolbar-tabs-container a {
- background: #CCC;
-}
-
-.toolbar-tabs-container a.active {
- background: #DDD;
-}
\ No newline at end of file
<div class="buttontoolbarview panel-toolbar">
<div class="buttontoolbarview-tabs toolbar-tabs-container toolbar-buttons-container">
<% for (var i=0; i < buttons.length; i++) { %>
- <a href="#" class="buttontoolbarview-tab" ui:groupindex="<%= i %>"><%= buttons[i].name %></a>
+ <button type="button" class="buttontoolbarview-tab" ui:groupindex="<%= i %>"><%= buttons[i].name %></button>
<% }; %>
</div>
<div class="buttontoolbarview-groups ">
<div class="buttontoolbarview-group toolbar-buttons-container" ui:groupIndex="<%= i %>" style="display: none">
<% for (var j=0; j < buttons[i].buttons.length; j++) { %>
<% if (buttons[i].buttons[j].scriptlet_id) { %>
- <a href="#" class="buttontoolbarview-button" ui:groupindex="<%= i %>" ui:buttonindex="<%= j %>">
+ <button type="button" class="buttontoolbarview-button" ui:groupindex="<%= i %>" ui:buttonindex="<%= j %>">
<%= buttons[i].buttons[j].label %>
- </a>
+ </button>
<% } %>
<% } %>
</div>
<div class="upload-file-widget">
<h2>Dodaj nowy utwór</h2>
-<form action="/api/documents" method="POST" enctype="multipart/form-data">
+<form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
{{ bookform }}
<p><button type="submit">Dodaj książkę</button></p>
</form>
{% extends "base.html" %}
{% block maincontent %}
-
-
-
-
-
<h2>Dodawanie nowego utworu:</h2>
-{% if other_errors %}
+{% if errors %}
<div class="errorlist">
-{% for error in other_errors %}
-<p>{{ error }}</p>
+{% for error in errors %}
+<p>{{ error }}: {{ error.errors }}</p>
{% endfor %}
</div>
{% endif %}
<form action="{% url file_upload %}" method="POST" enctype="multipart/form-data">
- {{ form.as_p }}
+ {{ bookform.as_p }}
<p><button type="submit">Dodaj książkę</button></p>
</form>
{% endblock maincontent %}
+++ /dev/null
-function ScriptletCenter() {
-
- this.scriptlets = {
- {% for scriptlet in scriptlets %}
- "{{scriptlet.name}}": function(context, params) {
- {{scriptlet.code|safe}}
- },
- {% endfor %}
-
- _none: null
- };
-
-}
-
-ScriptletCenter.prototype.XMLEditorSelectedText = function(panel) {
- return panel.contentView.editor.selection();
-}
-
-ScriptletCenter.prototype.XMLEditorReplaceSelectedText = function(panel, replacement)
-{
- panel.contentView.editor.replaceSelection(replacement);
- /* TODO: fire the change event */
-}
-
-ScriptletCenter.prototype.XMLEditorMoveCursorForward = function(panel, n) {
- var pos = panel.contentView.editor.cursorPosition();
- panel.contentView.editor.selectLines(pos.line, pos.character + n);
-}
-
-scriptletCenter = new ScriptletCenter();
\ No newline at end of file