Code Profile template.

This commit is contained in:
Santiago Lamora 2019-11-20 20:07:35 +01:00
parent 902ef7a949
commit d3d87d37c3
5 changed files with 120 additions and 3 deletions

View File

@ -19,6 +19,9 @@ API_PATHS = {
'mailbox-list': 'mailboxes/',
'mailinglist-list': 'lists/',
# ... TODO (@slamora) complete list of backend URLs
# other
'payment-source-list': 'payment-sources/',
}

View File

@ -39,6 +39,46 @@ class OrchestraModel:
return c
class BillingContact(OrchestraModel):
param_defaults = {
'name': None,
'address': None,
'city': None,
'zipcode': None,
'country': None,
'vat': None,
}
class PaymentSource(OrchestraModel):
api_name = 'payment-source'
param_defaults = {
"method": None,
"data": [],
"is_active": False,
}
class UserAccount(OrchestraModel):
api_name = 'accounts'
param_defaults = {
'username': None,
'type': None,
'language': None,
'short_name': None,
'full_name': None,
'billing': {},
}
@classmethod
def new_from_json(cls, data, **kwargs):
billing = None
if 'billcontact' in data:
billing = BillingContact.new_from_json(data['billcontact'])
return super().new_from_json(data=data, billing=billing)
class DatabaseUser(OrchestraModel):
api_name = 'databaseusers'
fields = ('username',)

View File

@ -0,0 +1,51 @@
{% extends "musician/base.html" %}
{% load i18n %}
{% block content %}
<h1>Profile</h1>
<p>Little description of what to be expected...</p>
<div class="card">
<h5 class="card-header text-right">User information</h5>
<div class="card-body row">
<div class="col-md-4">
<div class="m-auto border border-secondary rounded-circle rounded-lg" style="width:125px; height:125px;">
{# <!-- <img class="" src="#" alt="User profile image" /> -->#}
</div>
</div>
<div class="col-md-8">
<p class="card-text">{{ profile.username }}</p>
<p class="card-text">{{ profile.type }}</p>
<p class="card-text">Preferred language: {{ profile.language }}</p>
</div>
</div>
</div>
{% with profile.billing as contact %}
<div class="card mt-4">
<h5 class="card-header text-right">Billing information</h5>
<div class="card-body">
<div class="form-group">{{ contact.name }}</div>
<div class="form-group">{{ contact.address }}</div>
<div class="form-group">
{{ contact.zipcode }}
{{ contact.city }}
{{ contact.country }}
</div>
<div class="form-group">
{{ contact.vat }}
</div>
<!-- payment method -->
<div class="form-group">
payment method: {{ payment.method }}
</div>
<div class="form-group">
{# TODO(@slamora) format payment method details #}
{{ payment.data.data }}
</div>
</div>
</div>
{% endwith %}
{% endblock %}

View File

@ -15,6 +15,7 @@ urlpatterns = [
path('auth/login/', views.LoginView.as_view(), name='login'),
path('auth/logout/', views.LogoutView.as_view(), name='logout'),
path('dashboard/', views.DashboardView.as_view(), name='dashboard'),
path('profile/', views.ProfileView.as_view(), name='profile'),
path('mails/', views.MailView.as_view(), name='mails'),
path('mailing-lists/', views.MailingListsView.as_view(), name='mailing-lists'),
path('databases/', views.DatabasesView.as_view(), name='databases'),

View File

@ -1,4 +1,5 @@
from django.views.generic.detail import DetailView
from itertools import groupby
from django.core.exceptions import ImproperlyConfigured
@ -14,8 +15,9 @@ from . import api, get_version
from .auth import login as auth_login
from .auth import logout as auth_logout
from .forms import LoginForm
from .mixins import (CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin)
from .models import DatabaseService, MailinglistService, MailService
from .mixins import (CustomContextMixin,
ExtendedPaginationMixin, UserTokenRequiredMixin)
from .models import DatabaseService, MailinglistService, MailService, UserAccount, PaymentSource
class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
@ -34,6 +36,25 @@ class DashboardView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
return context
class ProfileView(CustomContextMixin, UserTokenRequiredMixin, TemplateView):
template_name = "musician/profile.html"
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
json_data = self.orchestra.retreve_profile()
try:
pay_source = self.orchestra.retrieve_service_list(
PaymentSource.api_name)[0]
except IndexError:
pay_source = {}
context.update({
'profile': UserAccount.new_from_json(json_data[0]),
'payment': PaymentSource.new_from_json(pay_source)
})
return context
class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequiredMixin, ListView):
"""Base list view to all services"""
service_class = None
@ -44,7 +65,8 @@ class ServiceListView(CustomContextMixin, ExtendedPaginationMixin, UserTokenRequ
raise ImproperlyConfigured(
"ServiceListView requires a definiton of 'service'")
json_qs = self.orchestra.retrieve_service_list(self.service_class.api_name)
json_qs = self.orchestra.retrieve_service_list(
self.service_class.api_name)
return [self.service_class.new_from_json(data) for data in json_qs]
def get_context_data(self, **kwargs):