Dénote

Dénote Commit Details

Date:2016-06-14 11:09:11 (6 years 11 months ago)
Author:Grégory Soutadé
Branch:master
Commit:72c3a97ffaa582038c4856291f2c8667f1a6a6bf
Parents: 38be8017a0ec71133b7cbfc6d421d348692b697f
Message:Add visibility management

Changes:
Adenote/templates/public_note.html (full)
Adenote/templates/public_notes.html (full)
Mdenote/forms.py (3 diffs)
Mdenote/models.py (4 diffs)
Mdenote/static/css/denote.css (1 diff)
Mdenote/static/js/denote.js (1 diff)
Mdenote/templates/base.html (2 diffs)
Mdenote/templates/base_user.html (1 diff)
Mdenote/templates/user_index.html (1 diff)
Mdenote/templates/user_note.html (4 diffs)
Mdenote/urls.py (1 diff)
Mdenote/views.py (7 diffs)

File differences

denote/forms.py
2121
2222
2323
24
2425
2526
2627
......
2829
2930
3031
31
32
3233
3334
3435
36
37
38
3539
3640
3741
......
3943
4044
4145
42
46
from django.forms import ModelForm
from django import forms
from denote.models import *
from datetime import datetime
class NoteForm(ModelForm):
text = forms.CharField(widget=forms.Textarea(attrs={'rows':'20', 'cols':'150'}))
class Meta:
model = Note
exclude = ('author', 'transformed_text', 'long_summary', 'short_summary', 'created_date', 'modified_date', 'category', 'visibility')
exclude = ('author', 'transformed_text', 'long_summary', 'short_summary', 'created_date', 'modified_date', 'category')
class UserForm(ModelForm):
password = forms.CharField(required=False)
def __init__(self, *args, **kwargs):
super(UserForm, self).__init__(*args, **kwargs)
self.fields['first_name'].label = 'Name'
class Meta:
model = User
fields = ('first_name', 'username', 'password')
fields = ('first_name', 'username', 'password', 'home_notes_visibility')
denote/models.py
3333
3434
3535
36
3637
3738
3839
......
5859
5960
6061
62
63
64
65
66
67
68
69
70
71
6172
6273
6374
......
6677
6778
6879
69
80
7081
7182
7283
......
124135
125136
126137
127
138
139
140
141
128142
129143
130144
class User(AbstractUser):
hidden_categories = models.TextField(blank=True)
home_notes_visibility = models.IntegerField(default=0, choices=[(0, 'private'), (1, 'registered'), (2, 'public')])
def getPreference(self, name):
if name == 'hidden_categories':
name = models.CharField(max_length=50, unique=True, blank=False)
class Note(models.Model):
PRIVATE = 0
REGISTERED = 1
PUBLIC = 2
VISIBILITY = ((PRIVATE, 'Private'),
(REGISTERED, 'Registered'),
(PUBLIC, 'Public')
)
author = models.ForeignKey(User, null=False, on_delete=models.CASCADE)
title = models.CharField(max_length=100, blank=False)
long_summary = models.CharField(max_length=255)
transformed_text = models.TextField()
created_date = models.DateTimeField()
modified_date = models.DateTimeField()
visibility = models.IntegerField(default=0)
visibility = models.IntegerField(default=PRIVATE, choices=VISIBILITY)
category = models.ForeignKey(Category, null=True, on_delete=models.SET_NULL)
def _wrap(self, text, limit, max_limit):
@receiver(post_save, sender=Note)
def post_save_note_signal(sender, **kwargs):
s = Search()
s.edit_note(kwargs['instance'].id)
if kwargs['created']:
s.index_note(kwargs['instance'].id)
else:
s.edit_note(kwargs['instance'].id)
@receiver(pre_delete, sender=Note)
def pre_delete_note_signal(sender, **kwargs):
denote/static/css/denote.css
111111
112112
113113
114
114
115115
116116
117117
margin : 1em;
}
#main_panel .note .title a
.note .title a
{
color: black;
text-decoration: none;
denote/static/js/denote.js
9696
9797
9898
99
99100
100101
101102
category = categories.childNodes[i];
if (category.nodeType != Node.ELEMENT_NODE) continue;
categoryId = category.getAttribute("category_id");
if (categoryId == null) continue;
hide = false;
for(a=0; a<hidden_categories.length;a++)
{
denote/templates/base.html
22
33
44
5
6
7
8
59
610
711
......
913
1014
1115
12
13
16
17
18
1419
1520
1621
<head>
<title>Dénote{% if user.get_full_name|length != 0 %} - {{ user.get_full_name }}{% endif %}</title>
<link rel="icon" type="image/png" href="{{ STATIC_URL }}images/favicon.png" />
<script type="text/javascript">
var hidden_categories = null;
function get_csrf_token() { return '{{ csrf_token }}';}
</script>
{% block head %} {% endblock %}
<link href="{{ STATIC_URL }}css/denote.css" rel="stylesheet" type="text/css"/>
<link href="{{ STATIC_URL }}css/pygments.css" rel="stylesheet" type="text/css"/>
</head>
<body onload="startup();">
<!-- Header -->
<div class="settings"><a href="/user/edit">Settings</a> <a href="/disconnect">Disconnect</a><br/>
<form action="/search">{% csrf_token %}<input name="text"/><input type="button" value="Search"/></form></div>
<div class="settings">{% if authenticated %}<a href="/user/edit">Settings</a> <a href="/disconnect">Disconnect</a><br/>
{% endif %}
<form action="/search" method="post">{% csrf_token %}<input name="text"/><input type="submit" value="Search"/></form></div>
<!-- Left panel -->
<div id="left_panel">
<a id="home_icon" href="/" alt="Home"><img src="{{ STATIC_URL }}images/home.png"/></a><br/><br/>
denote/templates/base_user.html
11
22
33
4
4
55
6
76
87
98
{% extends "base.html" %}
{% block head %}
<script type="text/javascript">
var hidden_categories = "{{ user.hidden_categories }}";
hidden_categories = "{{ user.hidden_categories }}";
hidden_categories = hidden_categories.split(",");
function get_csrf_token() { return '{{ csrf_token }}';}
</script>
{% endblock %}
{% block left %}
denote/templates/public_note.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{% extends "base.html" %}
{% block left %}
{% for note in public_notes %}
<div id="categories">
<div class="note">
<a href="/note/{{ note.author.id}}/{{ note.id }}"><div class="title">{{ note.title }}</div></a>
<div class="date">{{ note.created_date }}</div>
<div class="summary">{{ note.short_summary }}</div>
</div>
</div>
{% endfor %}
{% endblock %}
{% block content %}
<div class="note">
<div id="title" class="title">{{ note.title }}</div>
<div id="transformed_content">{{ note.transformed_text|safe }}</div>
</div>
{% endblock %}
denote/templates/public_notes.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{% extends "base.html" %}
{% block left %}
{% for note in public_notes %}
<div id="categories">
<div class="note">
<a href="/note/{{ note.author.id}}/{{ note.id }}"><div class="title">{{ note.title }}</div></a>
<div class="date">{{ note.created_date }}</div>
<div class="summary">{{ note.short_summary }}</div>
</div>
</div>
{% endfor %}
{% endblock %}
{% block content %}
{% for note in notes %}
<div class="note">
<div class="title"><a href="/note/{{ note.author.id }}/{{ note.id }}">{{ note.title }}</a></div>
<div class="date">{{ note.modified_date }}</div>
<div class="summary">{{ note.long_summary }}</div>
</div>
{% endfor %}
{% if notes|length == 0 %}
<b>Any note</b>
{% endif %}
{% endblock %}
denote/templates/user_index.html
1212
1313
1414
15
16
17
1518
<div class="summary">{{ note.long_summary }}</div>
</div>
{% endfor %}
{% if notes|length == 0 %}
<b>Any note</b>
{% endif %}
{% endblock %}
denote/templates/user_note.html
22
33
44
5
5
66
7
7
8
9
10
811
912
1013
14
1115
1216
1317
......
2125
2226
2327
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
28
7229
7330
7431
......
8138
8239
8340
84
41
8542
8643
8744
......
13188
13289
13390
134
91
13592
13693
{% block content %}
<div class="note">
{% if note != None %}
{% if note and note_form != None %}
<div id="title" class="title" ondblclick="edit_note();">{{ note.title }}</div>
{% if note.category != None %}
{% else %}
<div id="title" class="title">{{ note.title }}</div>
{% endif %}
{% if note and note.category != None %}
<div class="category">{{ note.category.name }}</div>
{% endif %}
<div id="transformed_content">{{ note.transformed_text|safe }}</div>
{% if note and note_form != None %}
<div class="edit_button"><input id="edit_button" type="button" value="Edit" onclick="edit_note();"/> <form id="form_delete" action="/note/{{ note.id }}" method="post">{% csrf_token %}<input type="submit" name="delete" value="Delete" onclick="return confirm('Do you really want to delete this note ?')"/></form></div>
<div id="div_edit">
<form id="form_edit" action="/note/{{ note.id }}" method="post">{% csrf_token %}
<input type="submit" name="edit" value="Edit" />
<input type="button" value="Cancel" onclick="cancel_edit_note();"/>
</form>
<b>Markdown syntax</b><br /><br />
<table>
<tr>
<td class="markdown_help">
<pre style="display:inline">_italic_</pre> <span style="font-style:italic">italic</span><br/>
<pre style="display:inline">**bold**</pre> <span style="font-weight:bold">bold</span><br/>
<pre style="display:inline">~~line through~~</pre> <span style="text-decoration:line-through">line through</span><br/>
<pre style="display:inline">~underline~</pre> <span style="text-decoration:underline">underline</span><br/>
<pre style="display:inline">>Citation</pre><br/>
<pre>
* Unordered list
* Second element
</pre>
<ul>
<li>Unordered list
<li>Second element
</ul>
<pre>
1. Ordered list
1. Second element
</pre>
<ol>
<li>Ordered list
<li>Second element
</ol>
<pre style="display:inline">![Picture](https://bits.wikimedia.org/images/wikimedia-button.png)</pre><img src="https://bits.wikimedia.org/images/wikimedia-button.png" alt="Picture"/><br/>
<pre style="display:inline">#[Inline Picture](https://bits.wikimedia.org/images/wikimedia-button.png)</pre><img src="https://bits.wikimedia.org/images/wikimedia-button.png" alt="Picture"/><br/>
<pre style="display:inline">[Link](http://www.wikipedia.org)</pre> <a href="http://www.wikipedia.org">Link</a><br/><br/>
<pre>
Code : 4 whitespaces ahead
</pre>
</td>
<td>
<pre># Title # or
Title
=====</pre>
<h1>Title</h1>
<pre>## Sub title ## or
Sub title
---------</pre>
<h2>Sub title</h2>
<pre>### Sub sub title ###</pre>
<h3>Sub sub title</h3>
</td>
</tr>
</table>
</div>
{% else %}
{% else %}
<div class="form_add">
<form action="/note/add" method="post">{% csrf_token %}
{{ note_form.as_p }}
<input type="submit" name="add" value="Add" />
<input type="submit" name="cancel" value="Cancel" />
</form>
</div>
{% endif %}
<b>Markdown syntax</b><br /><br />
<table>
<tr>
</td>
</tr>
</table>
{% endif %}
</div>
</div>
{% endblock %}
denote/urls.py
2828
2929
3030
31
3132
3233
3334
url(r'^user/edit$','denote.views.edit_user', name='edit_user'),
url(r'^note/add$', 'denote.views.add_note', name='add_note'),
url(r'^note/(\d+)$', 'denote.views.note', name='note'),
url(r'^note/(\d+)/(\d+)$', 'denote.views.public_note', name='public_note'),
url(r'^category/edit/(\d)$','denote.views.edit_category', name='edit_category'),
url(r'^preferences$', 'denote.views.preferences', name='preferences'),
url(r'^search$', 'denote.views.search', name='search'),
denote/views.py
2121
2222
2323
24
24
2525
2626
2727
......
115115
116116
117117
118
119
120
121
122
118123
119124
120125
......
134139
135140
136141
142
137143
138144
139145
......
167173
168174
169175
170
176
177
171178
172179
173180
......
201208
202209
203210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
204241
205242
206243
......
237274
238275
239276
240
241277
242278
243279
......
251287
252288
253289
254
255
256
290
291
257292
258
293
294
295
296
297
298
299
300
259301
260302
261303
import os
from datetime import datetime
from django.http import HttpResponseRedirect, HttpResponse, Http404
from django.http import HttpResponseRedirect, HttpResponse, Http404, HttpResponseForbidden
from django.contrib.auth.decorators import login_required
from django.contrib.auth import authenticate, login, logout
from django.shortcuts import render
return render(request, 'edit_user.html', c)
def _prepare_note_context(user):
if not user.is_authenticated():
return {
'authenticated' : False,
}
categories = Category.objects.filter(author=user.id).order_by('name')
notes_by_category = []
need_refresh = False
context = {
'user': user,
'authenticated' : True,
'notes_by_category': notes_by_category,
'categories': categories,
'notes_without_category': notes_without_category,
if 'cancel' in request.POST:
return HttpResponseRedirect('/')
else:
form = NoteForm()
note = Note(visibility=user.home_notes_visibility)
form = NoteForm(instance=note)
context = _prepare_note_context(user)
context['note_form'] = form
return render(request, 'user_note.html', context)
def public_note(request, user_id, note_id):
user = request.user
try:
note = Note.objects.get(pk=note_id, author=user_id)
except:
raise Http404
if note is None:
raise Http404
if not user or not user.is_authenticated():
if note.visibility != Note.PUBLIC:
return HttpResponseForbidden()
else:
if note.visibility == Note.PRIVATE and\
user_id != user.id:
return HttpResponseForbidden()
if user.is_authenticated():
public_notes = Note.objects.filter(author=user_id, visibility__gte=Note.REGISTERED).order_by('-modified_date')
else:
public_notes = Note.objects.filter(author=user_id, visibility__gte=Note.PUBLIC).order_by('-modified_date')
context = _prepare_note_context(user)
context['note'] = note
context['public_notes'] = public_notes
return render(request, 'public_note.html', context)
@login_required
def edit_category(request, category_id):
user = request.user
else:
raise Http404
@login_required
def search(request):
context = _prepare_note_context(request.user)
s = Search()
note_list = s.search(text)
notes = Note.objects.filter(pk__in=note_list, author=request.user)
context['notes'] = notes
context['note_form'] = NoteForm()
if request.user.is_authenticated():
notes = Note.objects.filter(pk__in=note_list, author=request.user)
return render(request, 'user_index.html', context)
context['notes'] = notes
context['note_form'] = NoteForm()
return render(request, 'user_index.html', context)
else:
notes = Note.objects.filter(pk__in=note_list, visibility__gte=Note.PUBLIC)
context['notes'] = notes
return render(request, 'public_notes.html', context)
@login_required
def generate_search_index(request):

Archive Download the corresponding diff file

Branches

Tags