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):␊ |