mirror of
https://git.linux-kernel.at/oliver/ivatar.git
synced 2025-11-11 18:56:23 +00:00
Finish AssignPhotoView
This commit is contained in:
44
ivatar/ivataraccount/templates/assign_photo_email.html
Normal file
44
ivatar/ivataraccount/templates/assign_photo_email.html
Normal file
@@ -0,0 +1,44 @@
|
||||
{% extends 'base.html' %}
|
||||
{% load i18n %}
|
||||
|
||||
{% block title %}{% blocktrans with email.email as email_address %}Choose a photo for {{ email_address }}{% endblocktrans %} - ivatar{% endblock title %}
|
||||
|
||||
{% block content %}
|
||||
|
||||
<h1>{% blocktrans with email.email as email_address %}Choose a photo for {{ email_address }}{% endblocktrans %}</h1>
|
||||
|
||||
{% if not user.photo_set.count %}
|
||||
|
||||
{% url 'upload_photo' as upload_url %}
|
||||
<p>{% blocktrans %}You need to <a href="{{ upload_url }}">upload some photos</a> first!{% endblocktrans %}</p>
|
||||
|
||||
<p><a href="{% url 'profile' %}">{% trans 'Back to your profile' %}</a></p>
|
||||
|
||||
{% else %}
|
||||
|
||||
<p>{% trans 'Here are the pictures you have uploaded, click on the one you wish to associate with this email address:' %}</p>
|
||||
<ul class="horizontal-list avatar-list centered">
|
||||
{% for photo in user.photo_set.all %}
|
||||
<li>
|
||||
<form action="{% url 'assign_photo_email' view.kwargs.email_id %}" method="post">{% csrf_token %}
|
||||
<input type="hidden" name="photo_id" value="{{ photo.id }}">
|
||||
<input type="image" name="photo{{ photo.id }}" src="{% url 'raw_image' photo.id %}" class="thumbnail">
|
||||
{% ifequal email.photo.id photo.id %}
|
||||
<br>{% trans '(current)' %}
|
||||
{% endifequal %}
|
||||
</form></li>
|
||||
{% endfor %}
|
||||
<li>
|
||||
<form action="{% url 'assign_photo_email' view.kwargs.email_id %}" method="post">{% csrf_token %}
|
||||
<input type="submit" name="photoNone" value="{% trans 'None' %}">
|
||||
{% ifequal email.photo.id photo.id %}
|
||||
<br>{% trans '(current)' %}
|
||||
{% endifequal %}
|
||||
</form></li>
|
||||
</ul>
|
||||
|
||||
<p>{% blocktrans %}or <a href="{{custom_upload_url}}">upload a new one</a>.{% endblocktrans %}</p>
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock content %}
|
||||
@@ -142,19 +142,44 @@ class RemoveConfirmedEmailView(SuccessMessageMixin, View):
|
||||
return HttpResponseRedirect(reverse_lazy('profile'))
|
||||
|
||||
|
||||
class AssignPhotoEmailView(SuccessMessageMixin, View):
|
||||
class AssignPhotoEmailView(SuccessMessageMixin, TemplateView):
|
||||
model = Photo
|
||||
template_name = 'assign_photo_email.html'
|
||||
|
||||
def post(self, *args, **kwargs):
|
||||
photo = None
|
||||
if not 'photo_id' in kwargs:
|
||||
mesages.error(self.request, _('Invalid request'))
|
||||
if not 'email_id' in kwargs:
|
||||
messages.error(self.request, _('Invalid request [email_id] missing'))
|
||||
return HttpResponseRedirect(reverse_lazy('profile'))
|
||||
if not 'photo_id' in self.request.POST:
|
||||
messages.error(self.request, _('Invalid request [photo_id] missing'))
|
||||
return HttpResponseRedirect(reverse_lazy('profile'))
|
||||
|
||||
try:
|
||||
photo = Photo.objects.get(
|
||||
id=kwargs['photo_id'], user=request.user)
|
||||
except Photo.DoesNotExist:
|
||||
photo = self.model.objects.get(
|
||||
id=self.request.POST['photo_id'],
|
||||
user=self.request.user)
|
||||
except self.model.DoesNotExist:
|
||||
message.error(self.request, _('Photo does not exist'))
|
||||
return HttpResponseRedirect(reverse_lazy('profile'))
|
||||
|
||||
try:
|
||||
email = ConfirmedEmail.objects.get(user=self.request.user,
|
||||
id=kwargs['email_id'])
|
||||
except ConfirmedEmail.DoesNotExist:
|
||||
message.error(self.request, _('Invalid request'))
|
||||
return HttpResponseRedirect(reverse_lazy('profile'))
|
||||
|
||||
email.photo = photo
|
||||
email.save()
|
||||
|
||||
messages.success(self.request, _('Successfully changed photo'))
|
||||
return HttpResponseRedirect(reverse_lazy('profile'))
|
||||
|
||||
def get_context_data(self, **kwargs):
|
||||
data = super().get_context_data(**kwargs)
|
||||
data['email'] = ConfirmedEmail.objects.get(pk=kwargs['email_id'])
|
||||
return data
|
||||
|
||||
class ImportPhotoView(SuccessMessageMixin, View):
|
||||
def post(self, *args, **kwargs):
|
||||
|
||||
Reference in New Issue
Block a user