From 6e115c1f1d2757ac5d5d520e1447596a9acc84df Mon Sep 17 00:00:00 2001 From: Chibuotu Amadi Date: Thu, 24 Sep 2020 13:53:27 +0100 Subject: [PATCH] feat(profile): delete portfolio item --- app/dashboard/templates/profiles/tab_portfolio.html | 5 +++++ app/dashboard/views.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/app/dashboard/templates/profiles/tab_portfolio.html b/app/dashboard/templates/profiles/tab_portfolio.html index 7c186395e73..6a9d885aa2f 100644 --- a/app/dashboard/templates/profiles/tab_portfolio.html +++ b/app/dashboard/templates/profiles/tab_portfolio.html @@ -97,6 +97,11 @@
{{pi.title}}
  {% if pi.link %} View Work > {% endif %} +
+ {% csrf_token %} + + +
{% endfor %} diff --git a/app/dashboard/views.py b/app/dashboard/views.py index 3716070ac2f..9613835ee20 100644 --- a/app/dashboard/views.py +++ b/app/dashboard/views.py @@ -2821,6 +2821,7 @@ def get_profile_tab(request, profile, tab, prev_context): pass elif tab == 'portfolio': title = request.POST.get('project_title') + pk = request.POST.get('project_pk') if title: if request.POST.get('URL')[0:4] != "http": messages.error(request, 'Invalid link.') @@ -2836,6 +2837,14 @@ def get_profile_tab(request, profile, tab, prev_context): tags=request.POST.get('tags').split(','), ) messages.info(request, 'Portfolio Item added.') + if pk: + # delete portfolio item + if not request.user.is_authenticated or request.user.profile.pk != profile.pk: + messages.error(request, 'Not Authorized') + pi = PortfolioItem.objects.filter(pk=pk).first() + if pi: + pi.delete() + messages.info(request, 'Portfolio Item has been deleted.') elif tab == 'earnings': context['earnings'] = Earning.objects.filter(to_profile=profile, network='mainnet', value_usd__isnull=False).order_by('-created_on') elif tab == 'spent':