aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorluxagraf <sng@luxagraf.net>2019-01-09 13:29:17 -0600
committerluxagraf <sng@luxagraf.net>2019-01-09 13:29:17 -0600
commitbe0bb4e123240ac3ce02431b974c82f8f05d843b (patch)
treee2da7ac44be955ad5cbf32c0a35dc507ba63e844 /apps
parentd5f430d3e1e2b274d8d8f744251e8b6b4b72ebd9 (diff)
latest changes
Diffstat (limited to 'apps')
-rw-r--r--apps/accounts/forms.py11
-rw-r--r--apps/accounts/migrations/0002_auto_20190108_2115.py35
-rw-r--r--apps/accounts/models.py12
-rw-r--r--apps/accounts/urls.py6
-rw-r--r--apps/accounts/views.py2
-rw-r--r--apps/notes/models.py4
-rw-r--r--apps/notes/notebook_urls.py2
-rw-r--r--apps/notes/views.py48
-rw-r--r--apps/utils/views.py2
9 files changed, 105 insertions, 17 deletions
diff --git a/apps/accounts/forms.py b/apps/accounts/forms.py
index d53e754..2da08cb 100644
--- a/apps/accounts/forms.py
+++ b/apps/accounts/forms.py
@@ -1,4 +1,5 @@
from django import forms
+from django.utils.translation import ugettext_lazy as _
from django_registration.forms import RegistrationForm
from .models import User, UserProfile
@@ -12,7 +13,15 @@ class UserForm(RegistrationForm):
class ProfileForm(forms.ModelForm):
class Meta:
model = UserProfile
- fields = '__all__'
+ fields = ['bio', 'photo', 'website']
+ labels = {
+ "photo": _("Profile photo"),
+ "bio": _("Bio. A little about you. links are fine, line breaks are not. Keep it short and sweet, 350 characters max"),
+ "website": _("If you have a personal website, plug it in here."),
+ }
+ widgets = {
+ 'bio': forms.Textarea(attrs={'cols': 104, 'rows': 10, 'class': 'textarea-rounded'}),
+ }
def __init__(self, *args, **kwargs):
self.user = kwargs.pop("user", None)
diff --git a/apps/accounts/migrations/0002_auto_20190108_2115.py b/apps/accounts/migrations/0002_auto_20190108_2115.py
new file mode 100644
index 0000000..1ebb280
--- /dev/null
+++ b/apps/accounts/migrations/0002_auto_20190108_2115.py
@@ -0,0 +1,35 @@
+# Generated by Django 2.1.2 on 2019-01-09 03:15
+
+from django.conf import settings
+from django.db import migrations, models
+import django.db.models.deletion
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('accounts', '0001_initial'),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name='userprofile',
+ name='bio',
+ field=models.CharField(blank=True, default='', max_length=350),
+ ),
+ migrations.AlterField(
+ model_name='userprofile',
+ name='location',
+ field=models.CharField(blank=True, default='', max_length=300),
+ ),
+ migrations.AlterField(
+ model_name='userprofile',
+ name='user',
+ field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='profile', to=settings.AUTH_USER_MODEL),
+ ),
+ migrations.AlterField(
+ model_name='userprofile',
+ name='website',
+ field=models.CharField(blank=True, default='', max_length=300),
+ ),
+ ]
diff --git a/apps/accounts/models.py b/apps/accounts/models.py
index 1b62ffd..feb20bf 100644
--- a/apps/accounts/models.py
+++ b/apps/accounts/models.py
@@ -1,4 +1,5 @@
from django.db import models
+from django.urls import reverse
from django.contrib.auth.models import AbstractUser
from django.utils.functional import cached_property
@@ -15,15 +16,18 @@ class User(AbstractUser):
class UserProfile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
photo = models.ImageField(upload_to='profile', null=True, blank=True)
- website = models.CharField(max_length=300, null=True, blank=True, default='')
- location = models.CharField(max_length=300, null=True, blank=True, default='')
- bio = models.TextField(null=True, blank=True, default='')
+ website = models.CharField(max_length=300, blank=True, default='')
+ location = models.CharField(max_length=300, blank=True, default='')
+ bio = models.CharField(max_length=350, blank=True, default='')
+ #default_note_folder = models.ForeignKey('notes.Notebook', null=True, on_delete=models.SET_NULL)
#default_note_public = models.BooleanField(default=False)
- #default_note_folder = models.ForeignKey('notes.Folder', null=True, on_delete=models.SET_NULL)
def __str__(self):
return self.user.username
+ def get_absolute_url(self):
+ return reverse("accounts:settings")
+
@cached_property
def get_notebook_list(self):
return Notebook.objects.filter(owner=self.user).select_related().annotate(note_count=models.Count('note'))[:8]
diff --git a/apps/accounts/urls.py b/apps/accounts/urls.py
index d9ee327..5cad311 100644
--- a/apps/accounts/urls.py
+++ b/apps/accounts/urls.py
@@ -2,9 +2,15 @@ from django.urls import path
from . import views
+app_name = "accounts"
urlpatterns = [
path(
+ r'change-profile/',
+ views.ProfileView.as_view(),
+ name="change-profile"
+ ),
+ path(
r'',
views.SettingsListView.as_view(),
name="settings"
diff --git a/apps/accounts/views.py b/apps/accounts/views.py
index d463522..75bb933 100644
--- a/apps/accounts/views.py
+++ b/apps/accounts/views.py
@@ -18,7 +18,7 @@ class UpdateViewWithUser(UpdateView):
class ProfileView(UpdateViewWithUser):
model = UserProfile
form_class = ProfileForm
- template_name = "accounts/profile.html"
+ template_name = "accounts/change-settings.html"
def get_object(self):
return self.request.user.profile
diff --git a/apps/notes/models.py b/apps/notes/models.py
index bfcb8ba..c4b1df6 100644
--- a/apps/notes/models.py
+++ b/apps/notes/models.py
@@ -54,13 +54,13 @@ class Notebook(models.Model):
class Meta:
unique_together = ("owner", "name")
+ ordering = ("name", "date_created", "date_updated")
def __str__(self):
return self.name
def save(self, **kwargs):
- if self._state.adding:
- self.slug = unique_slug_generator(self)
+ self.slug = unique_slug_generator(self)
super(Notebook, self).save()
@cached_property
diff --git a/apps/notes/notebook_urls.py b/apps/notes/notebook_urls.py
index b433d15..8e3133e 100644
--- a/apps/notes/notebook_urls.py
+++ b/apps/notes/notebook_urls.py
@@ -3,11 +3,13 @@ from django.urls import path
from .views import (
NotebookListView,
NotebookDetailView,
+ NotebookUpdateView,
)
app_name = "notebooks"
urlpatterns = [
+ path(r'<slug>/update', NotebookUpdateView.as_view(), name='update',),
path(r'<slug>', NotebookDetailView.as_view(), name='detail',),
path(r'', NotebookListView.as_view(), name='list',),
]
diff --git a/apps/notes/views.py b/apps/notes/views.py
index 245e2ab..280020a 100644
--- a/apps/notes/views.py
+++ b/apps/notes/views.py
@@ -90,6 +90,7 @@ class NoteDetailView(LoggedInViewWithUser, AjaxableResponseMixin, UpdateView):
return context
def form_valid(self, form):
+ print(self.request.META)
if "trash" in self.request.POST:
form.instance.notebook = Notebook.include_trash.get(owner=self.request.user, name="Trash")
self.object = form.save()
@@ -155,6 +156,8 @@ class NoteTagView(BaseListView):
context = super().get_context_data(**kwargs)
#context['notes_list'] = Note.objects.filter(owner=self.request.user)
context['tags'] = LuxTag.objects.filter(slug__in=self.tag_list)
+ context['tag_list'] = LuxTag.objects.filter(note__owner=self.request.user).annotate(note_count=Count('note'))
+ context['notebook_list'] = Notebook.objects.filter(owner=self.request.user).annotate(note_count=Count('note'))
return context
@@ -174,23 +177,48 @@ class NotebookListView(LoggedInViewWithUser, CreateView):
def form_valid(self, form):
form.instance.owner = self.request.user
- self.object = form.save()
+ if "create" in self.request.POST:
+ self.object = form.save()
+ messages.info(self.request, 'The notebook %s has been created, you may edit it below.' % (self.object.name))
+ return redirect('notebooks:list')
return super(NotebookListView, self).form_valid(form)
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
- NotebookFormSet = modelformset_factory(Notebook, form=NotebookForm, extra=0)
- context['notebook_form_list'] = NotebookFormSet(queryset=Notebook.objects.filter(owner=self.request.user).select_related().annotate(note_count=Count('note')))
- #context['notebook_list'] = Notebook.objects.filter(owner=self.request.user).exclude(name="Trash").select_related().annotate(note_count=Count('note'))
- #context['notes_list'] = Note.objects.filter(owner=self.request.user).select_related()
+ forms = []
+ for n in Notebook.objects.filter(owner=self.request.user).prefetch_related('note_set').prefetch_related('note_set__tags').annotate(note_count=Count('note')):
+ #notes = []
+ #tags = set(tag for tag in notes.tags_set.all().distinct() for notes in n.note_set.all())
+ #n.tag_list = tags
+ n.tag_list = LuxTag.objects.filter(note__in=n.note_set.all()).distinct()[:3]
+ forms.append(NotebookForm(instance=n))
+ context['notebook_form_list'] = forms
+ #context['notebook_list'] = Notebook.objects.filter(owner=self.request.user).select_related().annotate(note_count=Count('note'))
return context
- def get_success_url(self):
- return reverse_lazy('notebooks:detail', kwargs={'slug': self.object.slug})
+class NotebookUpdateView(LoggedInViewWithUser, UpdateView):
+ model = Notebook
+ form_class = NotebookForm
+ template_name = 'notes/notebook_list.html'
-class NotebookDetailView(BaseDetailView):
+ def get_queryset(self):
+ if not self.request.user.is_anonymous:
+ return Notebook.objects.filter(owner=self.request.user)
+
+ def form_valid(self, form):
+ form.instance.owner = self.request.user
+ self.object = form.save()
+ data = {
+ 'notebook': {'name': self.object.name, 'color': self.object.color_rgb, 'permalink': self.object.slug}
+ }
+ return JsonResponse(data, safe=True)
+
+
+class NotebookDetailView(LoggedInViewWithUser, AjaxableResponseMixin, UpdateView):
model = Notebook
+ form_class = NotebookForm
+ template_name = 'notes/notebook_detail.html'
def get_queryset(self):
if not self.request.user.is_anonymous:
@@ -200,7 +228,7 @@ class NotebookDetailView(BaseDetailView):
return Notebook.objects.filter(owner=self.request.user)
def get_object(self):
- notebook = get_object_or_404(self.get_queryset().select_related(), owner=self.request.user, slug=self.kwargs["slug"])
+ notebook = get_object_or_404(self.get_queryset().prefetch_related('note_set').prefetch_related('note_set__tags'), owner=self.request.user, slug=self.kwargs["slug"])
self.form = NotebookForm(instance=notebook)
return notebook
@@ -208,6 +236,8 @@ class NotebookDetailView(BaseDetailView):
context = super().get_context_data(**kwargs)
#context['notes_list'] = Note.objects.filter(owner=self.request.user).select_related()
context['form'] = self.form
+ context['tag_list'] = LuxTag.objects.filter(note__owner=self.request.user).annotate(note_count=Count('note'))
+ context['notebook_list'] = Notebook.objects.filter(owner=self.request.user).annotate(note_count=Count('note'))
return context
diff --git a/apps/utils/views.py b/apps/utils/views.py
index ec3a902..c752706 100644
--- a/apps/utils/views.py
+++ b/apps/utils/views.py
@@ -59,6 +59,8 @@ class AjaxableResponseMixin:
# We make sure to call the parent's form_valid() method because
# it might do some processing (in the case of CreateView, it will
# call form.save() for example).
+ print(self.request.META)
+ print('x request header', self.request.META['HTTP_X_REQUESTED_WITH'])
response = super().form_valid(form)
if self.request.is_ajax():
data = {