diff options
author | luxagraf <sng@luxagraf.net> | 2018-12-06 07:03:24 -0600 |
---|---|---|
committer | luxagraf <sng@luxagraf.net> | 2018-12-06 07:03:24 -0600 |
commit | 4eaaa999c89293677dade99568a279c934e0b8d9 (patch) | |
tree | c543451d3ca149681460f45ab6161a813cf4ed29 /apps | |
parent | cb21e59587ab328e9a3e06c9d57c2bafce281715 (diff) |
redid scripts to use just npm
Diffstat (limited to 'apps')
-rw-r--r-- | apps/utils/util.py | 12 | ||||
-rw-r--r-- | apps/utils/views.py | 48 |
2 files changed, 41 insertions, 19 deletions
diff --git a/apps/utils/util.py b/apps/utils/util.py index 415704c..287205a 100644 --- a/apps/utils/util.py +++ b/apps/utils/util.py @@ -96,9 +96,9 @@ def unique_slug_generator(instance, new_slug=None): slug = new_slug else: try: - slug = slugify(instance.title) + slug = slugify(instance.title)[:45] except AttributeError: - slug = slugify(instance.name) + slug = slugify(instance.name)[:45] Klass = instance.__class__ qs_exists = Klass.objects.filter(slug=slug).exists() if qs_exists: @@ -108,3 +108,11 @@ def unique_slug_generator(instance, new_slug=None): ) return unique_slug_generator(instance, new_slug=new_slug) return slug + + +def comma_splitter(tag_string): + return [t.strip().lower() for t in tag_string.split(',') if t.strip()] + + +def comma_joiner(tags): + return ', '.join(t.name for t in tags) diff --git a/apps/utils/views.py b/apps/utils/views.py index dcb16a8..595e102 100644 --- a/apps/utils/views.py +++ b/apps/utils/views.py @@ -1,11 +1,18 @@ from itertools import chain import json from django.http import Http404, HttpResponse +from django.apps import apps from django.views.generic import ListView -from photos.models import LuxImage, LuxVideo +from django.views.generic.base import View, RedirectView +from django.utils.decorators import method_decorator +from django.contrib.auth.decorators import login_required +#from photos.models import LuxImage, LuxVideo from django.shortcuts import render_to_response from django.shortcuts import render from django.template import RequestContext +from taggit.models import Tag +#from dal import autocomplete + class PaginatedListView(ListView): """ @@ -26,24 +33,16 @@ class PaginatedListView(ListView): return super(PaginatedListView, self).dispatch(request, *args, **kwargs) -def insert_image(request): - """ - The view that handles the admin insert image/video feature - """ - images = LuxImage.objects.all()[:80] - videos = LuxVideo.objects.all()[:10] - object_list = sorted( - chain(images, videos), - key=lambda instance: instance.pub_date, - reverse=True - ) - return render(request, 'admin/insert_images.html', {'object_list': object_list, 'textarea_id': request.GET['textarea']}) - +@method_decorator(login_required, name='dispatch') +class LoggedInViewWithUser(View): -from taggit.models import Tag + def get_form_kwargs(self, **kwargs): + kwargs = super().get_form_kwargs(**kwargs) + kwargs.update({'user': self.request.user}) + return kwargs -from dal import autocomplete +''' class TagAutocomplete(autocomplete.Select2QuerySetView): def get_queryset(self): # Don't forget to filter out results depending on the visitor ! @@ -57,7 +56,6 @@ class TagAutocomplete(autocomplete.Select2QuerySetView): return qs -from django.apps import apps def nav_json(request, app, model, pk): model = apps.get_model(app_label=app, model_name=model) @@ -67,3 +65,19 @@ def nav_json(request, app, model, pk): data['next'] = p.get_next_admin_url data = json.dumps(data) return HttpResponse(data) + + +def insert_image(request): + """ + The view that handles the admin insert image/video feature + """ + images = LuxImage.objects.all()[:80] + videos = LuxVideo.objects.all()[:10] + object_list = sorted( + chain(images, videos), + key=lambda instance: instance.pub_date, + reverse=True + ) + return render(request, 'admin/insert_images.html', {'object_list': object_list, 'textarea_id': request.GET['textarea']}) +''' + |