aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--notes/models.py8
-rw-r--r--notes/templates/edit.html13
-rw-r--r--notes/templates/view.html10
-rw-r--r--notes/views.py38
-rw-r--r--opus/settings.py3
-rw-r--r--opus/templates/default.html6
-rw-r--r--opus/urls.py3
7 files changed, 64 insertions, 17 deletions
diff --git a/notes/models.py b/notes/models.py
index 2cd5ca6..25a08cf 100644
--- a/notes/models.py
+++ b/notes/models.py
@@ -14,7 +14,7 @@ class Tag(models.Model):
class Note(models.Model):
user = models.ForeignKey(User)
shared = models.BooleanField(default=True)
- title = models.CharField(max_length=140, null=True)
+ title = models.CharField(max_length=140, null=True, default=u'New Note')
tags = models.ManyToManyField(Tag, null=True, blank=True)
def get_date(self):
@@ -51,11 +51,13 @@ class Attachment(models.Model):
content = models.FileField(upload_to='uploads')
note = models.ForeignKey(Note)
+ def get_name(self):
+ import os.path
+ return os.path.basename(self.content.name)
+
@receiver(post_save, sender=Version)
def version_saved(sender, instance, created, **kwargs):
-
tags = re.findall('#(\w+)', instance.content)
-
for t in tags:
tag = Tag.objects.get_or_create(title=t)[0]
instance.note.tags.add(tag)
diff --git a/notes/templates/edit.html b/notes/templates/edit.html
index 6d2ec1e..51c1e7d 100644
--- a/notes/templates/edit.html
+++ b/notes/templates/edit.html
@@ -3,14 +3,19 @@
{% block content %}
<div data-role="page">
<div data-role="header">
- <a href="/notes/" data-icon="arrow-l">Notes</a>
- <h1>New Note</h1>
- <a href="/notes/" id="done">Done</a>
+ <a href="/notes/" data-icon="arrow-l" data-ajax="false">Notes</a>
+ <h1>{{ note.title }}</h1>
+ <a href="#" id="done">Done</a>
</div>
<div data-role="content">
- <form action="" method="post" id="noteForm" enctype="multipart/form-data">
+ <form action="" method="post" id="noteForm" enctype="multipart/form-data" data-ajax="false">
{% csrf_token %}
{{ form }}
+ <ul data-role="listview" data-inset="true">
+ {% for a in note.attachment_set.all %}
+ <li><a href="/notes/{{ note.id }}/files/{{ a.id }}/delete/">{{ a.get_name }}</a></li>
+ {% endfor %}
+ </ul>
<button type="submit" data-theme="b">Save</button>
{% if form.is_bound %}
<a href="delete/" data-role="button">Delete</a>
diff --git a/notes/templates/view.html b/notes/templates/view.html
index a6d3473..fa2a59d 100644
--- a/notes/templates/view.html
+++ b/notes/templates/view.html
@@ -6,10 +6,18 @@
<div data-role="header">
<a href="/notes/" data-icon="arrow-l">Notes</a>
<h1>{{ note.title }}</h1>
- <a href="{{ note.get_absolute_url }}edit/">Edit</a>
+ <a href="{{ note.get_absolute_url }}edit/" data-ajax="false">Edit</a>
</div>
<div data-role="content">
<p>{{ version.content|restructuredtext }}</p>
+ <ul data-role="listview" data-inset="true">
+ {% for a in note.attachment_set.all %}
+ <li><a href="/notes/{{ note.id }}/file/{{ a.id }}/">{{ a.get_name }}<span class="ui-li-aside ui-li-desc">{{ a.content.size|filesizeformat }}</span></a></li>
+ {% endfor %}
+ </ul>
+ </div>
+ <div data-role="footer" class="ui-bar" data-position="fixed" data-theme="b">
+ <a href="delete" data-icon="delete" data-role="button">Delete</a>
</div>
</div>
{% endblock content %}
diff --git a/notes/views.py b/notes/views.py
index 386b0c0..7542cdb 100644
--- a/notes/views.py
+++ b/notes/views.py
@@ -1,4 +1,6 @@
+import mimetypes
from django import forms
+from django.http import HttpResponse
from django.shortcuts import render, redirect
from notes.models import Note, Attachment, Tag, Version
@@ -12,7 +14,7 @@ class NoteForm(forms.Form):
def edit(request, note_id=None):
note = Note(user_id=1)
-
+
if note_id:
note = Note.objects.get(pk=note_id)
@@ -20,21 +22,30 @@ def edit(request, note_id=None):
form = NoteForm(request.POST, request.FILES)
if not form.is_valid():
- return render(request, 'edit.html', {'form': form})
+ return render(request, 'edit.html', {'form': form, 'note': note})
note.title = form.cleaned_data.get('title')
note.save()
-
+
+ if request.FILES.get('attachment'):
+ a = Attachment(note=note)
+ a.content = request.FILES['attachment']
+ a.save()
+
version = Version(note=note, user_id=1)
version.content = form.cleaned_data.get('content')
version.shared = form.cleaned_data.get('shared')
version.save()
- return render(request, 'view.html', {'note': note, 'version': version})
+ return redirect(note)
- form = NoteForm(initial={'content': note.content, 'shared': note.shared})
+ form = NoteForm(initial={
+ 'content': note.content,
+ 'shared': note.shared,
+ 'title': note.title
+ })
- return render(request, 'edit.html', {'form': form})
+ return render(request, 'edit.html', {'form': form, 'note': note})
def index(request, tag_id=None):
notes = Note.objects.filter(user_id=1)
@@ -49,3 +60,18 @@ def view(request, note_id):
note = Note.objects.get(pk=note_id)
version = note.version_set.latest()
return render(request, 'view.html', {'note': note, 'version': version})
+
+def view_file(request, note_id, file_id):
+ note = Note.objects.get(pk=note_id)
+ f = note.attachment_set.get(pk=file_id)
+
+ mimetypes.init()
+ t, e = mimetypes.guess_type(f.content.name)
+
+ return HttpResponse(f.content.read(), content_type=t)
+
+def delete_file(request, note_id, file_id):
+ note = Note.objects.get(pk=note_id)
+ f = Attachment.objects.get(pk=file_id)
+ f.delete()
+ return HttpResponse('File deleted')
diff --git a/opus/settings.py b/opus/settings.py
index 2567e1b..2a12e4d 100644
--- a/opus/settings.py
+++ b/opus/settings.py
@@ -77,8 +77,7 @@ STATICFILES_FINDERS = (
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
-# Make this unique, and don't share it with anybody.
-SECRET_KEY = 'p3bkcgfs4bv5+0moy8^w^njqxqc#fn9(&amp;s^a7_=2r&amp;f750@0c#'
+
# List of callables that know how to import templates from various sources.
TEMPLATE_LOADERS = (
diff --git a/opus/templates/default.html b/opus/templates/default.html
index c970b6b..3f8c0a3 100644
--- a/opus/templates/default.html
+++ b/opus/templates/default.html
@@ -8,6 +8,12 @@
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<script src="http://code.jquery.com/mobile/1.2.0/jquery.mobile-1.2.0.min.js"></script>
<script type="text/javascript">
+ $(document).on("mobileinit", function(){
+ $.extend( $.mobile , {
+ ajaxEnabled: false
+ });
+ });
+
function getDate(field) {
// 2013-01-30 08:36:48
var splitRex = /^(\d{4})\-(\d{2})\-(\d{2})\s(\d{2}):(\d{2}):(\d{2})$/;
diff --git a/opus/urls.py b/opus/urls.py
index 75e20ee..8e08467 100644
--- a/opus/urls.py
+++ b/opus/urls.py
@@ -25,8 +25,9 @@ urlpatterns = patterns('',
url(r'^notes/$', 'notes.views.index'),
url(r'^notes/tag/(\d+)/$', 'notes.views.index'),
-
+
url(r'^notes/(\d+)/$', 'notes.views.view'),
url(r'^notes/new/$', 'notes.views.edit'),
url(r'^notes/(\d+)/edit/$', 'notes.views.edit'),
+ url(r'^notes/(\d+)/file/(\d+)/$', 'notes.views.view_file'),
)