From b985271c2233e1cc2a9447dc7b0d4c9b1319a93e Mon Sep 17 00:00:00 2001 From: Ashfaq Ahmed <46718979+ashfaq1934@users.noreply.github.com> Date: Wed, 3 May 2023 20:07:34 +0100 Subject: [PATCH 01/10] Updated feed template and fixed bugs with loading less files - Created a new view to display the feed - Updated feed template to display threads without having to register an account - Bugfixes for less files not being found in about.html and how_it_works.html - Modified new thread button to direct the user to login if they haven't been aurthenticated --- project/core/templates/about.html | 4 +- project/core/templates/base.html | 2 +- project/core/templates/how_it_works.html | 4 +- project/core/templates/landing.html | 1 + project/core/templates/static/less/feed.less | 7 +-- project/core/templates/static/less/utils.less | 4 ++ project/threads/templates/threads/feed.html | 60 +++++++++++++------ project/threads/urls/urls.py | 2 +- project/threads/views.py | 48 +++++++-------- 9 files changed, 80 insertions(+), 52 deletions(-) diff --git a/project/core/templates/about.html b/project/core/templates/about.html index 906234abc..ca3329fa4 100644 --- a/project/core/templates/about.html +++ b/project/core/templates/about.html @@ -2,7 +2,7 @@ {% load static %} {% load i18n %} {% block extra_css %} - + {% endblock extra_css %} {% block page_title %}{% trans "About Us" %}{% endblock page_title %} @@ -186,7 +186,7 @@

{% trans "Sponsors" %}

{% include "static_nav.html" %}
- + diff --git a/project/core/templates/base.html b/project/core/templates/base.html index 10a919710..4102bb9ed 100644 --- a/project/core/templates/base.html +++ b/project/core/templates/base.html @@ -37,8 +37,8 @@ {% include "global_nav.html" %} - {% include "static_footer.html" %} {%block content%}{%endblock content%} + {% include "static_footer.html" %} {% block extra_js %}{% endblock extra_js %} diff --git a/project/core/templates/how_it_works.html b/project/core/templates/how_it_works.html index 36abe6e7c..6e28707bd 100644 --- a/project/core/templates/how_it_works.html +++ b/project/core/templates/how_it_works.html @@ -4,7 +4,7 @@ {% block extra_css %} - + {% endblock extra_css %} {%block content%} + diff --git a/project/core/templates/landing.html b/project/core/templates/landing.html index b08db0b23..9281dd6e5 100644 --- a/project/core/templates/landing.html +++ b/project/core/templates/landing.html @@ -46,6 +46,7 @@

How OpenCiviWiki Works About Us Support Us + Visit The Discussion diff --git a/project/core/templates/static/less/feed.less b/project/core/templates/static/less/feed.less index 4e809b315..b0a2f38bc 100644 --- a/project/core/templates/static/less/feed.less +++ b/project/core/templates/static/less/feed.less @@ -1,8 +1,4 @@ @import 'base'; - -html { - overflow: hidden; -} body { background-color: #f7f6f8; @@ -163,6 +159,9 @@ body { .col { padding-top: 8px; } + .stats .col { + padding-top: unset; + } } .issue-item { box-shadow: 0 1px 0px 1px rgba(0, 0, 0, 0.02); diff --git a/project/core/templates/static/less/utils.less b/project/core/templates/static/less/utils.less index f92278bcd..b91f8cd0f 100644 --- a/project/core/templates/static/less/utils.less +++ b/project/core/templates/static/less/utils.less @@ -331,6 +331,10 @@ @box-shadow-z1: 0 2px 2px 0 rgba(0,0,0,0.14), 0 1px 5px 0 rgba(0,0,0,0.12), 0 3px 1px -2px rgba(0,0,0,0.2); +.nowrap{ + white-space: nowrap; +} + .dropdown-menu-wrapper{ display: block; margin-top: -12px; diff --git a/project/threads/templates/threads/feed.html b/project/threads/templates/threads/feed.html index c4c1e9a34..0512b52e2 100644 --- a/project/threads/templates/threads/feed.html +++ b/project/threads/templates/threads/feed.html @@ -40,12 +40,16 @@
-
+
Can't find the issue that you're interested in?
+ {% if user.is_authenticated %} + {% else %} + note_addNew Thread + {% endif %}
@@ -56,8 +60,8 @@
- {% for thread in trending_issues %} - + {% for thread in trending %} + {% endfor %}
@@ -65,26 +69,46 @@
- {% if threads %} - {% for thread in threads %} -
THREAD CARD PLACEHOLDER
- {% endfor %} - {% else %} -
-
-
-
NO THREADS
-
-
Be the first to start a discussion in this category!
- +
+
+
+ {% if threads %} +
+
    + {% for thread in threads %} +
  • +
    +
    +
    + +
    +
    +
    + {{ thread.thread.title }} +

    {{ thread.thread.summary }}

    +
    +
    +
    + remove_red_eye + {{ thread.stats.num_views }} Views +
    +
    + question_answer + {{ thread.stats.num_civis }} Civis +
    +
    + emoji_objects + {{ thread.stats.num_solutions }} Solutions
    - {% endif %} -
    -
+
+ + {% endfor %} +
+ {% endif %}
diff --git a/project/threads/urls/urls.py b/project/threads/urls/urls.py index 2eac22382..0dd31d6a2 100644 --- a/project/threads/urls/urls.py +++ b/project/threads/urls/urls.py @@ -1,7 +1,6 @@ from django.urls import path from threads import views - urlpatterns = [ path("thread//csv/", views.civi2csv, name="civi2csv"), path("thread//", views.ThreadDetailView.as_view(), name="thread-detail"), @@ -10,5 +9,6 @@ path("howitworks/", views.HowItWorksView.as_view(), name="how-it-works"), path("declaration/", views.DeclarationView.as_view(), name="declaration"), path("create-group/", views.create_group, name="create-group"), + path("feeds/", views.feeds, name="feeds"), path("", views.base_view, name="base"), ] diff --git a/project/threads/views.py b/project/threads/views.py index bfbc292d2..ac3c24472 100644 --- a/project/threads/views.py +++ b/project/threads/views.py @@ -1,10 +1,7 @@ -import json - from accounts.models import Profile from accounts.utils import get_account from categories.models import Category from core.custom_decorators import login_required -from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponse from django.template.response import TemplateResponse from django.views.decorators.csrf import csrf_exempt @@ -24,14 +21,14 @@ ) -class ThreadDetailView(LoginRequiredMixin, DetailView): +class ThreadDetailView(DetailView): model = Thread context_object_name = "thread" template_name = "thread.html" login_url = "accounts_login" def get_context_data(self, **kwargs): - context = super(ThreadDetailView, self).get_context_data(**kwargs) + context = super().get_context_data(**kwargs) context["categories"] = Category.objects.all() return context @@ -130,35 +127,38 @@ def images(self, request, pk=None): def base_view(request): - if not request.user.is_authenticated: - return TemplateResponse(request, "landing.html", {}) - - Profile_filter = Profile.objects.get(user=request.user) - if "login_user_image" not in request.session.keys(): - request.session["login_user_image"] = Profile_filter.profile_image_thumb_url + return TemplateResponse(request, "landing.html", {}) - categories = [{"id": c.id, "name": c.name} for c in Category.objects.all()] +def feeds(request): all_categories = list(Category.objects.values_list("id", flat=True)) - user_categories = ( - list(Profile_filter.categories.values_list("id", flat=True)) or all_categories - ) - + categories = [{"id": c.id, "name": c.name} for c in Category.objects.all()] feed_threads = [ Thread.objects.summarize(t) - for t in Thread.objects.exclude(is_draft=True).order_by("-created") + for t in Thread.objects.exclude(is_draft=False).order_by("-created") ] top5_threads = list( Thread.objects.filter(is_draft=False) .order_by("-num_views")[:5] .values("id", "title") ) - my_draft_threads = [ - Thread.objects.summarize(t) - for t in Thread.objects.filter(author_id=Profile_filter.id) - .exclude(is_draft=False) - .order_by("-created") - ] + if request.user.is_authenticated: + Profile_filter = Profile.objects.get(user=request.user) + if "login_user_image" not in request.session.keys(): + request.session["login_user_image"] = Profile_filter.profile_image_thumb_url + my_draft_threads = [ + Thread.objects.summarize(t) + for t in Thread.objects.filter(author_id=Profile_filter.id) + .exclude(is_draft=False) + .order_by("-created") + ] + user_categories = ( + list(Profile_filter.categories.values_list("id", flat=True)) + or all_categories + ) + else: + my_draft_threads = [] + user_categories = [] data = { "categories": categories, @@ -168,7 +168,7 @@ def base_view(request): "draft_threads": my_draft_threads, } - return TemplateResponse(request, "feed.html", {"data": json.dumps(data)}) + return TemplateResponse(request, "feed.html", data) @csrf_exempt From 934a0ef158d2f6712f72f4d706e48859e3e45d2b Mon Sep 17 00:00:00 2001 From: Ashfaq Ahmed <46718979+ashfaq1934@users.noreply.github.com> Date: Thu, 4 May 2023 21:07:56 +0100 Subject: [PATCH 02/10] Update test_views.py --- project/threads/tests/test_views.py | 32 ++++++++++++----------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/project/threads/tests/test_views.py b/project/threads/tests/test_views.py index ada334007..dd6b7ccda 100644 --- a/project/threads/tests/test_views.py +++ b/project/threads/tests/test_views.py @@ -1,9 +1,10 @@ import json + +from categories.models import Category from django.contrib.auth import get_user_model from django.test import TestCase -from rest_framework.test import APIClient from django.urls import reverse -from categories.models import Category +from rest_framework.test import APIClient from threads.models import Civi, Thread @@ -53,7 +54,7 @@ class ThreadViewSetTests(BaseTestCase): """A class to test ThreadViewSet""" def setUp(self) -> None: - super(ThreadViewSetTests, self).setUp() + super().setUp() self.client = APIClient() def test_anonymous_user_can_list_threads(self): @@ -111,41 +112,34 @@ class BaseViewTests(BaseTestCase): """A class to test base_view function""" def setUp(self) -> None: - super(BaseViewTests, self).setUp() + super().setUp() self.client.login(username=self.user.username, password="password123") - self.url = reverse("base") - self.response = self.client.get(self.url) - - def test_anonymous_users_are_redirected_to_landing_page(self): - """Whether unauthenticated users are redirected to the landing page""" + def test_landing_page(self): self.client.logout() - self.response = self.client.get(self.url) + self.response = self.client.get(reverse("base")) self.assertEqual(self.response.status_code, 200) - self.assertTemplateUsed(self.response, "base.html") self.assertTemplateUsed(self.response, "landing.html") - self.assertTemplateUsed(self.response, "static_nav.html") - self.assertTemplateUsed(self.response, "static_footer.html") self.assertContains(self.response, "Why CiviWiki?") self.assertNotContains(self.response, "Wrong Content!") - def test_authenticated_users_are_redirected_to_feed_page(self): - """Whether authenticated users are redirected to the feed page""" - + def test_anonymous_users_can_access_feed(self): + """Whether unauthenticated users can access feeds""" + self.client.logout() + self.response = self.client.get(reverse("feeds")) self.assertEqual(self.response.status_code, 200) self.assertTemplateUsed(self.response, "base.html") self.assertTemplateUsed(self.response, "feed.html") self.assertTemplateUsed(self.response, "global_nav.html") self.assertTemplateUsed(self.response, "static_footer.html") - self.assertContains(self.response, "Trending Issues") - self.assertNotContains(self.response, "Wrong Content!") + self.assertContains(self.response, "New Thread") class IssueThreadTests(BaseTestCase): """A class to test issue_thread function""" def setUp(self) -> None: - super(IssueThreadTests, self).setUp() + super().setUp() self.client.login(username=self.user.username, password="password123") def test_nonexistent_threads_redirect_to_404_page(self): From bd1b49260ce50e965ff8dd752c78d5f117ca278e Mon Sep 17 00:00:00 2001 From: Ashfaq Ahmed <46718979+ashfaq1934@users.noreply.github.com> Date: Sun, 4 Jun 2023 22:52:41 +0100 Subject: [PATCH 03/10] completed create and delete views for civis --- .../templates/accounts/register/login.html | 1 + project/core/settings.py | 1 - .../core/templates/static/less/thread.less | 13 +- project/threads/forms.py | 15 + project/threads/models.py | 5 +- project/threads/templates/threads/feed.html | 6 +- project/threads/templates/threads/thread.html | 1538 +++++++---------- project/threads/urls/urls.py | 10 + project/threads/views.py | 43 +- 9 files changed, 701 insertions(+), 931 deletions(-) create mode 100644 project/threads/forms.py diff --git a/project/accounts/templates/accounts/register/login.html b/project/accounts/templates/accounts/register/login.html index de08c3858..d42b38eba 100644 --- a/project/accounts/templates/accounts/register/login.html +++ b/project/accounts/templates/accounts/register/login.html @@ -40,6 +40,7 @@ +
Forgot your username or password? Click Here diff --git a/project/core/settings.py b/project/core/settings.py index 5bcb65124..76da8a4df 100644 --- a/project/core/settings.py +++ b/project/core/settings.py @@ -176,7 +176,6 @@ # Login Logout URLS LOGIN_URL = "login/" -LOGIN_REDIRECT_URL = "/" LOGOUT_REDIRECT_URL = "/" AUTH_PASSWORD_VALIDATORS = [ diff --git a/project/core/templates/static/less/thread.less b/project/core/templates/static/less/thread.less index bb639e66c..3d1104ce1 100644 --- a/project/core/templates/static/less/thread.less +++ b/project/core/templates/static/less/thread.less @@ -40,6 +40,11 @@ body { } #thread { + [type="radio"]:not(:checked), [type="radio"]:checked { + position: relative; + opacity: 1; + } + .thread-wiki-holder { display: none; } @@ -200,7 +205,7 @@ body { } } .civi-type-button { - background-color: @dark-white !important; + background-color: @dark-white; color: @purple; margin-right: 4px; padding: 0 1rem; @@ -406,9 +411,9 @@ body { margin-left: auto !important; margin-right: auto !important; - .btn { - background-color: @purple; - } + // .btn { + // background-color: @purple; + // } .body-banner { display: inline-block; diff --git a/project/threads/forms.py b/project/threads/forms.py new file mode 100644 index 000000000..849878703 --- /dev/null +++ b/project/threads/forms.py @@ -0,0 +1,15 @@ +from django import forms + +from .models import Civi + + +class CiviForm(forms.ModelForm): + class Meta: + model = Civi + fields = ["author", "thread", "title", "body", "c_type"] + widgets = { + "body": forms.Textarea( + attrs={"class": "materialize-textarea", "length": "1000"} + ), + "c_type": forms.HiddenInput(), + } diff --git a/project/threads/models.py b/project/threads/models.py index a4a396725..6f273e453 100644 --- a/project/threads/models.py +++ b/project/threads/models.py @@ -177,7 +177,6 @@ def serialize(self, civi, filter=None): return json.dumps(data, cls=DjangoJSONEncoder) def serialize_s(self, civi, filter=None): - data = { "type": civi.c_type, "title": civi.title, @@ -231,7 +230,9 @@ class Civi(models.Model): tags = TaggableManager() - linked_civis = models.ManyToManyField("self", related_name="links", symmetrical=False, blank=True) + linked_civis = models.ManyToManyField( + "self", related_name="links", symmetrical=False, blank=True + ) title = models.CharField(max_length=255, blank=False, null=False) body = models.CharField(max_length=1023, blank=False, null=False) diff --git a/project/threads/templates/threads/feed.html b/project/threads/templates/threads/feed.html index 0512b52e2..06b6654c7 100644 --- a/project/threads/templates/threads/feed.html +++ b/project/threads/templates/threads/feed.html @@ -48,7 +48,7 @@ {% if user.is_authenticated %} {% else %} - note_addNew Thread + note_addNew Thread {% endif %}
@@ -61,7 +61,9 @@
{% for thread in trending %} - + {% endfor %}
diff --git a/project/threads/templates/threads/thread.html b/project/threads/templates/threads/thread.html index bc1c7ef20..021322761 100644 --- a/project/threads/templates/threads/thread.html +++ b/project/threads/templates/threads/thread.html @@ -2,21 +2,9 @@ {% load static %} {% load i18n %} {% block extra_css%} - - - + + + {% endblock extra_css %} {% block content %}
@@ -37,11 +25,7 @@
- +
@@ -49,16 +33,12 @@
-
+
+
@@ -82,11 +62,9 @@
- Category:{{ thread.category.name }} + + Category: + {{ thread.category.name }}
@@ -112,259 +90,193 @@
{% for contributor in thread.contributors %} - {% if forloop.counter0 <= 7 %} -
+ {% if forloop.counter0 <= 7 %}
- + style="background-image: url('{{ contributor.profile.profile_image_url }}'); background-size: 40px;">
-
- {% endif %} {% endfor %} - {% if thread.contributors.count > 8 %} -
- +{{ thread.contributors.count|add:"-8" }} more -
- {% endif %}
+ {% endif %} {% endfor %} + {% if thread.contributors.count > 8 %} +
+ +{{ thread.contributors.count|add:"-8" }} + more +
+ {% endif %}
-
-
-
-
- Facts related to this thread: -
-
- {% for fact in thread.facts.all %} -
— {{ fact }}
- {% endfor %} -
+
+
+
+
+
+ Facts related to this thread: +
+
+ {% for fact in thread.facts.all %} +
— {{ fact }}
+ {% endfor %}
-
-
-
- -
+
+
+
+
+
-