Skip to content

Commit

Permalink
Added latest_news card for user dashboards
Browse files Browse the repository at this point in the history
  • Loading branch information
jjoseba committed Mar 11, 2024
1 parent 810df6e commit ca9a457
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 5 deletions.
22 changes: 19 additions & 3 deletions market/views/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

from market.mixins.current_market import MarketMixin
from market.models import Account, Provider
from news.models import News
from offers.models import Offer


Expand All @@ -26,21 +27,36 @@ class AdminDashboard(TemplateView):
class MarketDashboard(MarketMixin, TemplateView):
template_name = 'dashboard/market.html'


def get_context_data(self, **kwargs):
context = super().get_context_data()
context['last_news'] = News.objects.filter(node=self.node).order_by('-published_date')[:3]
return context
class UserDashboard(LoginRequiredMixin, TemplateView):
template_name = 'dashboard/user.html'

def get_account(self):
return Account.objects.filter(owner=self.request.user).first()

def get_template_names(self):
account = self.get_account()
if isinstance(account, Provider):
return 'dashboard/provider.html'
else:
return 'dashboard/consumer.html'

def get_context_data(self, **kwargs):
context = super().get_context_data()
account = Account.objects.filter(owner=self.request.user).first()
account = self.get_account()
context['account'] = account

if isinstance(account, Provider):
context['num_offers'] = Offer.objects.current(provider=account).count()

context['last_news'] = News.objects.filter(node=account.node).order_by('-published_date')[:3]

return context

class UserAccountDetail(RedirectView):
def get_redirect_url(self, *args, **kwargs):
account = Account.objects.filter(owner=self.request.user).first()
return reverse(account.detail_url, kwargs={'market':account.node.pk, 'pk':account.pk })
return reverse(account.detail_url, kwargs={'market':account.node.pk, 'pk': account.pk })
Binary file added static/imgs/mes_app.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
63 changes: 63 additions & 0 deletions templates/dashboard/consumer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{% extends "base.html" %}
{% load static %}
{% load market_url %}

{% block title %}Principal{% endblock%}
{% block bodyattrs %} class="main-bg"{% endblock%}
{% block content %}
<div class="container mt-3">
<div class="row">
<div class="col-md-4">
<div class="card mb-4">
<div class="bg-warning py-4 text-center">
<div class="d-inline-block m-auto">
{% include "account/profile_circle.html" with account=object %}
</div>

</div>
<div class="card-body">
<div class="card-title primary-title mb-0"><h3 class="mb-0"><i class="ic ic-entity"></i> Mi perfil</h3></div>
<div class="card-text text-dark">
<p class="lead my-0"> {{ account.display_name }}</p>
{{account.address}}
</div>
</div>

<div class="list-group list-group-flush">
<a class="list-group-item list-group-item-action" href="{% url 'market:user_account' %}"><i class="material-icons mr-2">store</i> Ver perfil</a>
<a class="list-group-item list-group-item-action" href="{% url 'market:member_card' %}"><i class="material-icons-outlined mr-2">perm_contact_calendar</i> Mi carnet de socia</a>
<a class="list-group-item list-group-item-action disabled" href="#"><i class="material-icons mr-2">bar_chart</i> Ver estadísticas de favoritos</a>
</div>
</div>
</div>

<div class="col-md-4">

<div class="card mb-3">
<div class="header-img"> <img class="img-fluid" src="{% static 'imgs/mes_app.png' %}"> </div>
<div class="card-body">

<p class="lead text-primary mb-0">
¿Tienes ya la app del Mercado Social?
</p>
<div class="d-flex align-items-center flex-column">
<a href='https://play.google.com/store/apps/details?id=net.mercadosocial.moneda&gl=US&pcampaignid=pcampaignidMKT-Other-global-all-co-prtnr-py-PartBadge-Mar2515-1'>
<img width="250px" alt='Disponible en Google Play' src={% static '/imgs/google-play.png' %}/>
</a>

<a href="https://apps.apple.com/es/app/mercado-social/id1458549528?itsct=apps_box_badge&amp;itscg=30200" style="display: inline-block; overflow: hidden; border-radius: 13px; width: 250px; height: 83px;">
<img src="{% static '/imgs/app-store.svg' %}" alt="Download on the App Store" style="border-radius: 13px; width: 250px; height: 83px;">
</a>

</div>
</div>
</div>
</div>

<div class="col-md-4">
{% include 'dashboard/last_news.html' %}
</div>

</div>
</div>
{% endblock content %}
13 changes: 13 additions & 0 deletions templates/dashboard/last_news.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<div class="card mb-4">
<div class="bg-brand text-light p-2 px-3">
<h3 class="card-title">Últimas noticias</h3>
</div>
<div class="card-body">
{% for item in last_news %}
{% include 'news/card.html' with news=item %}

{% empty %}
No hay noticias publicadas en este mercado...
{% endfor %}
</div>
</div>
12 changes: 10 additions & 2 deletions templates/dashboard/market.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
{% block title %}Principal{% endblock%}
{% block bodyattrs %} class="main-bg"{% endblock%}
{% block content %}
<div class="container-fluid">
Dashboard mercado {{current_market.name}}
<div class="container-fluid py-4">

<div class="row">
<div class="col-md-5">

</div>
<div class="col-md-4">
{% include 'dashboard/last_news.html' %}
</div>
</div>
</div>

{% endblock content %}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@
</div>
</div>

</div>

<div class="col-md-4">
{% include 'dashboard/last_news.html' %}
</div>

</div>
Expand Down
20 changes: 20 additions & 0 deletions templates/news/card.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{% load static %}

<div class="d-flex">
<div class="img mr-3">
<img class="img-fluid" style="width:200px;" src="{% if news.banner_image %}{{ news.banner_image.url }}{% else %}{% static 'imgs/default-news.png' %}{% endif %}" alt="{{news.title}}">
</div>
<div class="flex-grow-1">
<h4 class="mb-0"> {{news.title}}</h4>
<div class="small"> {{news.published_date|date:'d/m/Y'}}</div>

<div class="text-primary text-truncate"><strong>{{news.short_description|striptags|safe}}</strong></div>
</div>
</div>
<div class="bg-light p-2 text-right my-3">

{% if news.more_info_url %}
<a class="btn btn-action btn-primary" href="{{news.more_info_url}}">{% if news.more_info_text %} {{news.more_info_text}} {% else %} Saber más {% endif %} </a>
{% endif %}
<a class="btn btn-action btn-secondary text-light" href="{{news.more_info_url}}">ver noticia</a>
</div>

0 comments on commit ca9a457

Please sign in to comment.