Skip to content

Commit

Permalink
Page & form to create author card
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Feb 20, 2024
1 parent 7cc9069 commit 4210f12
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 9 deletions.
3 changes: 3 additions & 0 deletions templates/profile/info_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
<li class="nav-item">
<a class="nav-link {% if 'card' in request.path %}active fw-bold{% endif %}" href="{% url 'profile:info_card_view' %}">
{% translate "My author card" %}
{% if not user.user_card %}
({% translate "missing" %})
{% endif %}
</a>
</li>
</ul>
Expand Down
50 changes: 50 additions & 0 deletions templates/profile/info_card_create.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% extends "layouts/base.html" %}
{% load render_table from django_tables2 %}
{% load i18n django_bootstrap5 %}

{% block title %}{% translate "Add" %} - {% translate "My author card" %}{{ block.super }}{% endblock %}

{% block breadcrumbs %}
<div class="container">
<div class="row">
<div class="col-12 my-auto">
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'pages:home' %}">{% translate "Home" %}</a></li>
<li class="breadcrumb-item"><a href="{% url 'profile:home' %}">{% translate "My space" %}</a></li>
<li class="breadcrumb-item"><a href="{% url 'profile:info_card_view' %}">{% translate "My author card" %}</a></li>
<li class="breadcrumb-item active" aria-current="page">{% translate "Add" %}</li>
</ol>
</nav>
</div>
</div>
</div>
{% endblock %}

{% block content %}
<div class="container">
<form id="profile_info_card_create_form" method="POST" action="">
{% csrf_token %}

<div class="row">
<div class="col-md-8">
{% bootstrap_form form alert_error_type="all" %}
</div>
<!-- Sidebar -->
<div class="col-md-4 d-none d-md-block">

</div>
</div>

<hr />

<div class="row">
<div class="col">
{% bootstrap_button button_type="submit" button_class="btn-primary" content=_("Add") %}
{# {% bootstrap_button button_type="reset" button_class="btn-secondary" content=_("Cancel") %} #}
<a class="btn btn-secondary" href="{% url 'profile:info_card_view' %}">{% translate "Cancel" %}</a>
</div>
</div>
</form>
</div>
{% endblock %}
7 changes: 6 additions & 1 deletion templates/profile/info_card_view.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
{% block profile_info_content %}
<div class="row">
<div class="col-9">
<h1>{% translate "My author card" %}</h1>
<h1>
{% translate "My author card" %}
{% if not user.user_card %}
<a class="btn btn-success btn-sm" href="{% url 'profile:info_card_create' %}">{% translate "Add" %}</a>
{% endif %}
</h1>
</div>
</div>
<div class="row">
Expand Down
24 changes: 19 additions & 5 deletions templates/users/_author_card.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,30 @@ <h5 class="card-title">{{ user.full_name }}</h5>
<hr />

<p title="{% translate "Short biography" %}">
💬&nbsp;{{ user.user_card.short_biography | strip_html }}
💬&nbsp;<strong>{% translate "Short biography" %}</strong>
<br />
{% if user.user_card.short_biography %}
{{ user.user_card.short_biography | strip_html }}
{% else %}
<i>{% translate "missing" %}</i>
{% endif %}
</p>
<p title="{% translate "Relationship with the Anthropocene Quiz" %}">
🚀&nbsp;{{ user.user_card.quiz_relationship | strip_html }}
🚀&nbsp;<strong>{% translate "Relationship with the Anthropocene Quiz" %}</strong>
<br />
{% if user.user_card.quiz_relationship %}
{{ user.user_card.quiz_relationship | strip_html }}
{% else %}
<i>{% translate "missing" %}</i>
{% endif %}
</p>
<p class="mb-0">
<p class="mb-0" title="{% translate "Website" %}">
💻&nbsp;<strong>{% translate "Website" %}</strong>
<br />
{% if user.user_card.website_url %}
💻&nbsp;<a href="{{ user.user_card.website_url }}" target="_blank">{% translate "Website" %}</a>
<a href="{{ user.user_card.website_url }}" target="_blank">{% translate "Website" %}</a>
{% else %}
💻&nbsp;<i>{% translate "No website provided" %}</i>
<i>{% translate "No website provided" %}</i>
{% endif %}
</p>
</div>
Expand Down
8 changes: 7 additions & 1 deletion users/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
from django import forms

from users.models import User
from users.models import User, UserCard


class ProfileInfoCardCreateForm(forms.ModelForm):
class Meta:
model = UserCard
fields = ["short_biography", "quiz_relationship", "website_url"]


class ContributorCreateForm(forms.ModelForm):
Expand Down
4 changes: 3 additions & 1 deletion www/profile/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

PROFILE_DETAIL_URLS = [
# "profile:home",
"profile:info",
"profile:info_view",
"profile:info_card_view",
"profile:info_card_create",
"profile:questions_view",
"profile:questions_stats",
"profile:quizs_view",
Expand Down
2 changes: 2 additions & 0 deletions www/profile/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ProfileCommentNewListView,
ProfileHistoryListView,
ProfileHomeView,
ProfileInfoCardCreateView,
ProfileInfoCardView,
ProfileInfoView,
ProfileQuestionListStatsView,
Expand All @@ -27,6 +28,7 @@
]
),
),
path("info/card/create", ProfileInfoCardCreateView.as_view(), name="info_card_create"),
path(
"questions/",
include(
Expand Down
27 changes: 26 additions & 1 deletion www/profile/views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from itertools import chain

from django.contrib import messages
from django.contrib.messages.views import SuccessMessageMixin
from django.db.models import Value
from django.http import HttpResponseRedirect
from django.urls import reverse_lazy
from django.utils import timezone
from django.views.generic import DetailView, TemplateView
from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, DetailView, TemplateView
from django_filters.views import FilterView
from django_tables2.views import SingleTableMixin, SingleTableView

Expand All @@ -20,6 +25,7 @@
from quizs.tables import QuizTable
from stats.models import QuestionAggStat, QuizAggStat
from stats.tables import QuestionStatsTable, QuizStatsTable
from users.forms import ProfileInfoCardCreateForm
from users.models import User


Expand Down Expand Up @@ -57,6 +63,25 @@ def get_object(self):
return self.request.user


class ProfileInfoCardCreateView(ContributorUserRequiredMixin, SuccessMessageMixin, CreateView):
form_class = ProfileInfoCardCreateForm
template_name = "profile/info_card_create.html"
success_url = reverse_lazy("profile:info_card_view")
success_message = _("Author card created!")

def form_valid(self, form):
self.object = form.save(commit=False)
self.object.user = self.request.user
self.object.save()

messages.add_message(
self.request,
messages.SUCCESS,
self.get_success_message(form.cleaned_data),
)
return HttpResponseRedirect(self.get_success_url())


class ProfileQuestionListView(ContributorUserRequiredMixin, SingleTableMixin, FilterView):
model = Question
template_name = "profile/questions_view.html"
Expand Down

0 comments on commit 4210f12

Please sign in to comment.