Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #6 #22

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
"una_hora.users.apps.UsersConfig",
"una_hora.comments.apps.CommentsConfig",
"una_hora.meetings.apps.MeetingsConfig",
"una_hora.search",
]

MIDDLEWARE = [
Expand Down
2 changes: 2 additions & 0 deletions config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
urlpatterns = [
path("", TemplateView.as_view(template_name="base.html"), name="home-example"),
path("admin/", admin.site.urls),
path("users/", include("una_hora.users.urls")),
path("search/", include("una_hora.search.urls")),
]

if settings.DEBUG:
Expand Down
63 changes: 63 additions & 0 deletions templates/common/pagination.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<div>
{% for last_users in page_obj.object_list %}
<div>
{{last_users.FullName}}
</div>
{% endfor %}

</div>
<div id="pagination-div"style="
max-width: fit-content;
max-width: -moz-max-content;
max-width: intrinsic;
margin-left: auto;
margin-right: auto;
">
<ul class="pagination" >
{% if page_obj.has_previous %}
<li class="page-item">
<a href="users/?page=1" class="page-link">&laquo;</a>
</li>
<li class="page-item">
<a href="users/?page={{ page_obj.previous_page_number }}" class="page-link"
>Previous</a>
</li>
<a href="users/?page={{ page_obj.previous_page_number }}" class="page-link"
>{{ page_obj.previous_page_number }}</a
>
{% else %}
<li class="page-item disabled">
<a class="page-link" href="">&laquo; </a>
</li>
{% endif %}

<li class="page-item active">
<a class="page-link" href="#">{{ page_obj.number }}</a>
</li>

{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="users/?page={{ page_obj.next_page_number }}"
>{{ page_obj.next_page_number }}</a
>
</li>
<li class="page-item">
<a class="page-link" href="users/?page={{ page_obj.next_page_number }}"
>Next</a
>
</li>
<li class="page-item">
<a class="page-link" href="users/?page={{ page_obj.paginator.num_pages }}">
&raquo;</a
>
</li>
{%else%}
<li class="page-item disabled">
<a class="page-link" href="users/?page={{ page_obj.paginator.num_pages }}">
&raquo;</a
>
</li>

{% endif %}
</ul>
</div>
Empty file added una_hora/search/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions una_hora/search/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions una_hora/search/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class SearchConfig(AppConfig):
name = "una_hora.search"
Empty file.
3 changes: 3 additions & 0 deletions una_hora/search/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# from django.db import models

# Create your models here.
6 changes: 6 additions & 0 deletions una_hora/search/templates/search/search_page.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE html>
<html lang="en">
{% block body %}
Hola mundo desde search.
{% endblock %}
</html>
3 changes: 3 additions & 0 deletions una_hora/search/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# from django.test import TestCase

# Create your tests here.
7 changes: 7 additions & 0 deletions una_hora/search/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path

from . import views

urlpatterns = [
path("", views.search_page, name="search_page"),
]
7 changes: 7 additions & 0 deletions una_hora/search/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.shortcuts import render


# Create your views here.
def search_page(request):
print("hola")
return render(request, "./search/search_page.html")
7 changes: 7 additions & 0 deletions una_hora/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,13 @@ class User(AbstractBaseUser, PermissionsMixin):
USERNAME_FIELD = "email"
REQUIRED_FIELDS = []

def serialize(self):
return {
"id": self.id,
"full_name": self.full_name,
"bio": self.bio,
}

def __str__(self):
return self.email

Expand Down
7 changes: 7 additions & 0 deletions una_hora/users/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.urls import path

from . import views

urlpatterns = [
path("<str:pag>", views.last_twelve, name="last_twelve"),
]
18 changes: 18 additions & 0 deletions una_hora/users/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from django.core.paginator import Paginator
from django.shortcuts import render

from .models import User


def last_twelve(request):
last_users = User.objects.filter(is_active=True)
last_users = last_users.order_by("-date_joined").all()
paginator = Paginator([last_user.serialize() for last_user in last_users], 12)
page_number = request.GET.get("page")
page_obj = paginator.get_page(page_number)
page_items = len(page_obj)
return render(
request,
"common/pagination.html",
{"page_obj": page_obj, "page_items": page_items},
)