Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
Added option to delete account without orders
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiphoseer committed Jun 21, 2018
1 parent 57f1916 commit 0e35170
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pyBuchaktion/templates/pyBuchaktion/account.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ <h4 class="panel-title">
<a href="{% url "pyTUID:logout" %}?next={% url "pyBuchaktion:books" %}&amp;cas_logout=True" class="btn btn-danger">
{% trans "Logout &amp; CAS Logout" %}
</a>
<a href="{% url 'pyBuchaktion:account_delete' %}" class="btn btn-danger pull-right">
{% trans "Delete Account" %}
</a>
</div>
</div>

Expand Down
29 changes: 29 additions & 0 deletions pyBuchaktion/templates/pyBuchaktion/account_delete.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{% extends "page.html" %} {% load cms_tags view_tools i18n bootstrap_tags sekizai_tags bootstrap3 %}

{% block content %}
{% if error %}
<div class="alert alert-danger">
<b>{% trans "The following orders are still pending!" %}</b>
<ul>
{% for protected in error.protected_objects %}
<li>{{ protected }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
<div class="panel panel-default">
<div class="panel-heading">
<h4 class="panel-title">
{% trans "Delete Account" %}
</h4>
</div>
<div class="panel-body">
{% trans "Are you certain you want to delete the account for" %}: <b>{{ request.TUIDUser }}</b>
{% url 'pyBuchaktion:account_delete' as url_delete_account %}
<form method="POST" action="{{url_delete_account}}" class="pull-right">
{% csrf_token %}
<button type="submit" class="btn btn-danger">{% trans "Delete Account" %}</button>
</form>
</div>
</div>
{% endblock content %}
3 changes: 3 additions & 0 deletions pyBuchaktion/templates/pyBuchaktion/book_base.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ <h4 class="panel-title">
<div class="panel-body">
{% include "pyBuchaktion/tags/dlist_book.html" %}
</div>
<div class="panel-footer">
<a href="https://books.google.de/books?isbn={{book.isbn_13}}">https://books.google.de/books?isbn={{book.isbn_13}}</a>
</div>
{% block panel_content %}{% endblock panel_content %}
{% block panel_footer %}{% endblock panel_footer %}
</div>
Expand Down
2 changes: 0 additions & 2 deletions pyBuchaktion/templates/pyBuchaktion/tags/dlist_book.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@
<dd>{{ book.isbn_13|isbn }}</dd>
<dt>{% trans "Publication year" %}</dt>
<dd>{{ book.year }}</dd>
<dt>{% trans "links" as tr_links %}{{tr_links|capfirst}}</dt>
<dd><a href="https://books.google.de/books?isbn={{book.isbn_13}}">https://books.google.de/books?isbn={{book.isbn_13}}</a></dd>
</dl>
1 change: 1 addition & 0 deletions pyBuchaktion/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
url(r'^account/', include([
url(r'^$', AccountView.as_view(), name = 'account'),
url(r'^create/$', AccountCreateView.as_view(), name = 'account_create'),
url(r'^delete/$', AccountDeleteView.as_view(), name = 'account_delete'),
])),
url(r'^order/', include([
url(r'^(?P<pk>\d*)/', include([
Expand Down
14 changes: 12 additions & 2 deletions pyBuchaktion/views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from django.views.generic import ListView, DetailView
from django.views.generic import ListView, DetailView, TemplateView
from django.views.generic.edit import UpdateView, CreateView, BaseCreateView, DeleteView
from django.core.urlresolvers import reverse
from django.core.exceptions import ValidationError
from django.utils.translation import get_language
from django.http import HttpResponseRedirect
from django.db.models import F, Count, ExpressionWrapper, Prefetch
from django.shortcuts import render
from django.db.models import F, Count, ExpressionWrapper, Prefetch, ProtectedError

from .forms import BookSearchForm, ModuleSearchForm, AccountEditForm, BookOrderForm, BookProposeForm, LiteratureCreateForm
from .models import Book, Module, Order, Student, OrderTimeframe, ModuleCategory, Literature
Expand Down Expand Up @@ -289,6 +290,15 @@ def get_form_kwargs(self):
kwargs['initial'] = {'email': tuid_user.email}
return kwargs

class AccountDeleteView(StudentRequiredMixin, NeverCacheMixin, TemplateView):
template_name = 'pyBuchaktion/account_delete.html'

def post(self, request):
try:
request.TUIDUser.delete()
except ProtectedError as e:
return render(request, self.template_name, {'error': e})
return HttpResponseRedirect(reverse('pyBuchaktion:books'))

class BookProposeView(StudentRequiredMixin, CreateView):
model = Book
Expand Down

0 comments on commit 0e35170

Please sign in to comment.