↓↓クリックして頂けると励みになります。
【47 | 終了した配達ページ】 << 【ホーム】 >> 【49 | 支払いページ】
「crowdsource/urls.py」ファイルを編集します。
記述編集 【Desktop/crowdsource/crowdsource/urls.py】31行目
from django.contrib import admin from django.urls import path, include from django.contrib.auth import views as auth_views from django.conf import settings from django.conf.urls.static import static from core import views from core.customer import views as customer_views from core.courier import views as courier_views, apis as courier_apis customer_urlpatters = [ path('', customer_views.home, name="home"), path('profile/', customer_views.profile_page, name="profile"), path('payment_method/', customer_views.payment_method_page, name="payment_method"), path('create_job/', customer_views.create_job_page, name="create_job"), path('jobs/current/', customer_views.current_jobs_page, name="current_jobs"), path('jobs/archived/', customer_views.archived_jobs_page, name="archived_jobs"), path('jobs/<job_id>/', customer_views.job_page, name="job"), ] courier_urlpatters = [ path('', courier_views.home, name="home"), path('jobs/available/', courier_views.available_jobs_page, name="available_jobs"), path('jobs/available/<id>/', courier_views.available_job_page, name="available_job"), path('jobs/current/', courier_views.current_job_page, name="current_job"), path('jobs/current/<id>/take_photo/', courier_views.current_job_take_photo_page, name="current_job_take_photo"), path('jobs/complete/', courier_views.job_complete_page, name="job_complete"), path('jobs/archived/', courier_views.archived_jobs_page, name="archived_jobs"), path('profile/', courier_views.profile_page, name="profile"), path('api/jobs/available/', courier_apis.available_jobs_api, name="available_jobs_api"), path('api/jobs/current/<id>/update/', courier_apis.current_job_update_api, name="current_job_update_api"), ] urlpatterns = [ path('admin/', admin.site.urls), path('oauth/', include('social_django.urls', namespace='social')), path('', views.home), path('sign-in/', auth_views.LoginView.as_view(template_name="sign_in.html")), path('sign-out/', auth_views.LogoutView.as_view(next_page="/")), path('sign-up/', views.sign_up), path('customer/', include((customer_urlpatters, 'customer'))), path('courier/', include((courier_urlpatters, 'courier'))), ] if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
「core/courier/views.py」ファイルを編集します。
記述編集 【Desktop/crowdsource/core/courier/views.py】
from django.shortcuts import render, redirect from django.contrib.auth.decorators import login_required from django.urls import reverse from django.conf import settings from core.models import * @login_required(login_url="/sign-in/?next=/courier/") def home(request): return redirect(reverse('courier:available_jobs')) @login_required(login_url="/sign-in/?next=/courier/") def available_jobs_page(request): return render(request, 'courier/available_jobs.html', { "GOOGLE_MAP_API_KEY": settings.GOOGLE_MAP_API_KEY }) @login_required(login_url="/sign-in/?next=/courier/") def available_job_page(request, id): job = Job.objects.filter(id=id, status=Job.PROCESSING_STATUS).last() if not job: return redirect(reverse('courier:available_jobs')) if request.method == 'POST': job.courier = request.user.courier job.status = Job.PICKING_STATUS job.save() return redirect(reverse('courier:available_jobs')) return render(request, 'courier/available_job.html', { "job": job }) @login_required(login_url="/sign-in/?next=/courier/") def current_job_page(request): job = Job.objects.filter( courier=request.user.courier, status__in = [ Job.PICKING_STATUS, Job.DELIVERING_STATUS ] ).last() return render(request, 'courier/current_job.html', { "job": job, "GOOGLE_MAP_API_KEY": settings.GOOGLE_MAP_API_KEY }) @login_required(login_url="/sign-in/?next=/courier/") def current_job_take_photo_page(request, id): job = Job.objects.filter( id=id, courier=request.user.courier, status__in=[ Job.PICKING_STATUS, Job.DELIVERING_STATUS ] ).last() if not job: return redirect(reverse('courier:current_job')) return render(request, 'courier/current_job_take_photo.html', { "job": job }) @login_required(login_url="/sign-in/?next=/courier/") def job_complete_page(request): return render(request, 'courier/job_complete.html') @login_required(login_url="/sign-in/?next=/courier/") def archived_jobs_page(request): jobs = Job.objects.filter( courier=request.user.courier, status=Job.COMPLETED_STATUS ) return render(request, 'courier/archived_jobs.html', { "jobs": jobs }) @login_required(login_url="/sign-in/?next=/courier/") def profile_page(request): jobs = Job.objects.filter( courier=request.user.courier, status=Job.COMPLETED_STATUS ) total_earnings = round(sum(job.price for job in jobs) * 0.8) #配送業者の収入は総額の8割 total_jobs = len(jobs) total_km = sum(job.distance for job in jobs) return render(request, 'courier/profile.html', { "total_earnings": total_earnings, "total_jobs": total_jobs, "total_km": total_km })
「core/templates/courier」フォルダに「profile.html」ファイルを新規作成します。
新規作成 【Desktop/crowdsource/core/templates/courier/profile.html】
{% extends 'courier/base.html' %} {% load static %} {% block content %} <div class="media align-items-center bg-info text-light p-3"> <img src="{% static 'img/avatar.png' %}" class="rounded-circle" width="60" height="60"> <div class="media-body ml-4"> <h4 class="mb-0">{{ request.user.get_full_name }}</h4> </div> </div> <div class="mt-2 p-2"> <b class="text-secondary">配達記録</b> <hr /> <div class="d-flex text-center"> <div class="flex-grow-1"> <h4 class="text-success">{{ total_earnings }}円</h4> <span class="text-secondary">総収入</span> </div> <div class="flex-grow-1"> <h4 class="text-success">{{ total_jobs }} 件</h4> <span class="text-secondary">配送完了</span> </div> <div class="flex-grow-1"> <h4 class="text-danger">{{ total_km }} Km</h4> <span class="text-secondary">総配送距離</span> </div> </div> <hr /> </div> <div class="p-2"> <a href="/sign-out/" class="btn btn-block btn-danger btn-md mt-2"> <i class="fas fa-sign-out-alt mr-1"></i> ログアウト </a> </div> {% include 'courier/bottom_tabs.html' %} {% endblock %}
「core/templates/courier/bottom_tabs.html」ファイルを編集します。
記述編集 【Desktop/crowdsource/core/templates/courier/bottom_tabs.html】
<style> .bottom-tabs { position: fixed; bottom: 0; left: 0; right: 0; height: 60px; display: flex; background-color: white; box-shadow: 0 1px 5px rgba(0, 0, 0, 0.2); text-align: center; } .bottom-tabs>a { flex: 1; padding: 5px; color: #BFBFBF; text-decoration: none; } .bottom-tabs>a>span { font-size: 13px; font-weight: bold; display: block; } .bottom-tabs>a>i { font-size: 20px; } .bottom-tabs>a.active { color: #8216ce; } </style> {% url 'courier:available_jobs' as available_jobs_url %} {% url 'courier:current_job' as current_job_url %} {% url 'courier:archived_jobs' as archived_jobs_url %} {% url 'courier:profile' as profile_url %} <div class="bottom-tabs d-flex"> <a href="{% url 'courier:available_jobs' %}" class="{% if request.path == available_jobs_url %}active{% endif %}"> <i class="fas fa-map-marked-alt"></i> <span>利用可能な配達依頼</span> </a> <a href="{% url 'courier:current_job' %}" class="{% if request.path == current_job_url or request.path == archived_jobs_url %}active{% endif %}"> <i class="fas fa-archive"></i> <span>引き受けた配達依頼</span> </a> <a href="{% url 'courier:profile' %}" class="{% if request.path == profile_url %}active{% endif %}"> <i class="fas fa-user"></i> <span>プロフィール</span> </a> </div>
ブラウザを確認します。
http://127.0.0.1:8000/courier/profile/
↓↓クリックして頂けると励みになります。
【47 | 終了した配達ページ】 << 【ホーム】 >> 【49 | 支払いページ】