Browse bookmarks by users

This commit is contained in:
mrashidtufail 2020-11-12 20:47:10 +05:00
parent 4f3de2da63
commit 2162e036cc
4 changed files with 29 additions and 17 deletions

View file

@ -103,6 +103,11 @@ except (ModuleNotFoundError, ImportError):
AUTH_LDAP_BIND_PASSWORD = "" AUTH_LDAP_BIND_PASSWORD = ""
AUTH_LDAP_USER_SEARCH = "" AUTH_LDAP_USER_SEARCH = ""
AUTHENTICATION_BACKENDS = [
"django_auth_ldap.backend.LDAPBackend",
"django.contrib.auth.backends.ModelBackend"
]
SITE_NAME = "an unconfigured site" SITE_NAME = "an unconfigured site"
@ -145,12 +150,6 @@ USE_TZ = True
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static") ] STATICFILES_DIRS = [ os.path.join(BASE_DIR, "static") ]
AUTHENTICATION_BACKENDS = [
"django_auth_ldap.backend.LDAPBackend",
"django.contrib.auth.backends.ModelBackend"
]
AUTH_USER_MODEL = 'ubookmark.User' AUTH_USER_MODEL = 'ubookmark.User'
CRISPY_TEMPLATE_PACK = 'bootstrap4' CRISPY_TEMPLATE_PACK = 'bootstrap4'

View file

@ -19,7 +19,8 @@
<a href="{{ bookmark.url }}">{{ bookmark.comment }} <a href="{{ bookmark.url }}">{{ bookmark.comment }}
({{ bookmark.url }}) </a> ({{ bookmark.url }}) </a>
<div class="text-muted"> <div class="text-muted">
(posted by {{ bookmark.owner }} on {{ bookmark.posted_at }}) (posted by <a href="{% url 'list_user_bookmark' bookmark.owner %}">{{ bookmark.owner }} </a>
on {{ bookmark.posted_at }})
</div> </div>
</li> </li>
{% endfor %} {% endfor %}

View file

@ -23,5 +23,6 @@ urlpatterns = [
path('submit/', views.SubmitView.as_view(), name='submit'), path('submit/', views.SubmitView.as_view(), name='submit'),
path('login/', views.LoginView.as_view(), name='login'), path('login/', views.LoginView.as_view(), name='login'),
path('logout/', views.logout_view, name='logout'), path('logout/', views.logout_view, name='logout'),
path('users/<str:username>/', views.UserBookmarksListView.as_view(), name='list_user_bookmark'),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
] ]

View file

@ -1,12 +1,11 @@
from django.views.generic.list import ListView from django.conf import settings
from django.views.generic.edit import CreateView from django.contrib.auth import logout
from django.contrib.auth import views as auth_views from django.contrib.auth import views as auth_views
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import get_object_or_404, redirect, render
from django.contrib.auth import logout from django.views import View
from django.shortcuts import redirect from django.views.generic.edit import CreateView
from django.views.generic.list import ListView
from django.conf import settings
from ubookmark.models import * from ubookmark.models import *
@ -14,12 +13,11 @@ class IndexView(ListView):
model = BookmarkModel model = BookmarkModel
paginate_by = 5 paginate_by = 5
queryset = BookmarkModel.objects.order_by('-posted_at') queryset = BookmarkModel.objects.order_by('-posted_at')
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(IndexView, self).get_context_data(**kwargs) context = super(IndexView, self).get_context_data(**kwargs)
context['site_name'] = settings.SITE_NAME context['site_name'] = settings.SITE_NAME
context['site_description'] = settings.SITE_DESCRIPTION context['site_description'] = settings.SITE_DESCRIPTION
context['site_description'] = settings.SITE_DESCRIPTION
return context return context
@ -28,7 +26,7 @@ class SubmitView(LoginRequiredMixin, CreateView):
fields = [ 'comment', 'url' ] fields = [ 'comment', 'url' ]
login_url = '/login/' login_url = '/login/'
success_url = '/' success_url = '/'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(CreateView, self).get_context_data(**kwargs) context = super(CreateView, self).get_context_data(**kwargs)
context['site_name'] = settings.SITE_NAME context['site_name'] = settings.SITE_NAME
@ -47,7 +45,20 @@ class LoginView(auth_views.LoginView):
extra_context['site_name'] = settings.SITE_NAME extra_context['site_name'] = settings.SITE_NAME
extra_context['site_description'] = settings.SITE_DESCRIPTION extra_context['site_description'] = settings.SITE_DESCRIPTION
class UserBookmarksListView(ListView):
model = BookmarkModel
paginate_by = 5
def get_queryset(self):
user_id = get_object_or_404(User, username = self.kwargs["username"]).id
return BookmarkModel.objects.filter(owner=user_id)
def get_context_data(self, **kwargs):
context = super(UserBookmarksListView, self).get_context_data(**kwargs)
context['site_name'] = settings.SITE_NAME
context['site_description'] = settings.SITE_DESCRIPTION
return context
def logout_view(request): def logout_view(request):
logout(request) logout(request)
return redirect("/") return redirect("/")