70. Manage store and add address frontend

Add Address

We will update the add_address.html file

add_address.html
{% extends 'base.html' %}
{% load static %}

{% block body %}

<main class="principal">
    <title>Add Address | Reserva</title>
  
      <section class="conta">
  
        <div class="conta__container">
          <div class="checkout__titulos">
            <p class="checkout__titulo">Add a new address</p>
          </div>
  
          <form
            class="conta__form"
            action="{% url 'add_address' %}"
            method="post"
          >
          {% csrf_token %}
            
          <div class="conta__item">
            <label for="street">Street</label>
            <input name="street" type="text" placeholder="Street"/>
          </div>
          <div class="conta__item">
              <label for="number">Number</label>
              <input name="number" type="number" placeholder="Number"/>
          </div>
          <div class="conta__item">
              <label for="apartment">Apartment</label>
              <input name="apartment" type="text" placeholder="Apartment"/>
          </div>
          <div class="conta__item">
              <label for="zip_code">Zip Code</label>
              <input name="zip_code" type="number" placeholder="Zip Code"/>
          </div>
          <div class="conta__item">
              <label for="city">City</label>
              <input name="city" type="text" placeholder="City"/>
          </div>
          <div class="conta__item">
              <label for="state">State</label>
              <input name="state" type="text" placeholder="State"/>
          </div>
  
            <button class="subtotal__botao" type="submit">
              Add address
            </button>
            <a class="esquecer_senha" href="{% url 'checkout' %}">Return to checkout</a>
          </form>
        </div>
      </section>
  </main>

{% endblock %}

Manage store

Next, we will update the manage_store.html file located in the 'internal' folder, following a structure similar to the one implemented in the login frontend.

Obs: To ensure the "Manage Store" option appears in the profile dropdown on the navigation bar (and grants access to the page), the logged-in user must belong to the "Team" group in the admin page.

Current user located in the 'Team' group
manage_store.html
{% extends 'base.html' %}
{% load static %}

{% block body %}

<main class="principal">
    <title>Manage Store | Reserva</title>
  
      <section class="conta">
  
        <div class="conta__container">
          <div class="checkout__titulos">
            <p class="checkout__titulo">Main Indicators</p>
          </div>
            <p>Sales: R$ {{ sales }}</p>
            <p>Products Sold: {{ products_sold }}</p>
            <p>Total Orders: {{ total_orders }}</p>
        </div>
        
        
        <div class="conta__container">
          <div class="checkout__titulos">
            <p class="checkout__titulo">Export Reports</p>
          </div>

          <div class="conta__form">
            <a class="subtotal__botao" href="{% url 'export_report' 'orders' %}">Export Orders</a>
          </div>
          <div class="conta__form">
            <a class="subtotal__botao" href="{% url 'export_report' 'client' %}">Export Clients</a>
          </div>
          <div class="conta__form">
            <a class="subtotal__botao" href="{% url 'export_report' 'address' %}">Export Addresses</a>
          </div>
        </div>
      </section>
  </main>


{% endblock %}
Desktop view
Mobile view

We will also update the export_report view function and the export_csv utility function to ensure that downloaded reports include their respective type names in the file names. This will make it easier to identify and organize the reports.

views.py
def export_report(request, report):
    if request.user.groups.filter(name="Team").exists(): #? verify again if the user is part of a management Team
        if report == "orders" :
            data = Order.objects.filter(finished=True) #? queryset that searches the whole database
            title = "orders"
        elif report == "client" :
            data = Client.objects.all()
            title = "clients"
        elif report == "address" :
            data = Adres.objects.all()
            title = "addresses"
        return export_csv(data, title) #? returns a http response
    else :
        return redirect('manage_store')
utility.py
def export_report(request, report):
    if request.user.groups.filter(name="Team").exists(): #? verify again if the user is part of a management Team
        if report == "orders" :
            data = Order.objects.filter(finished=True) #? queryset that searches the whole database
            title = "orders"
        elif report == "client" :
            data = Client.objects.all()
            title = "clients"
        elif report == "address" :
            data = Adres.objects.all()
            title = "addresses"
        return export_csv(data, title) #? returns a http response
    else :
        return redirect('manage_store')

Last updated