Added translations and reformatted code

This commit is contained in:
PCoder 2017-09-02 16:50:09 +05:30
parent 2276533185
commit 7d12eff9be
3 changed files with 83 additions and 55 deletions

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-09-02 10:50+0000\n"
"POT-Creation-Date: 2017-09-02 11:16+0000\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -523,6 +523,15 @@ msgstr "Du kannst dich nun"
msgid "Sorry. Your request is invalid."
msgstr "Entschuldigung, deine Anfrage ist ungültig."
msgid "Password has been reset."
msgstr ""
msgid "Password reset has not been successful."
msgstr ""
msgid "The reset password link is no longer valid."
msgstr ""
msgid "Invalid credit card"
msgstr "Ungültige Kreditkarte"

View file

@ -1,40 +1,41 @@
import uuid
from django.core.files.base import ContentFile
from oca.pool import WrongNameError, WrongIdError
from django.shortcuts import render
from django.http import Http404
from django.core.urlresolvers import reverse_lazy, reverse
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views.generic import View, CreateView, FormView, ListView, DetailView, \
DeleteView, TemplateView, UpdateView
from django.http import HttpResponseRedirect
from django.contrib import messages
from django.conf import settings
from django.shortcuts import redirect
from django.utils.http import urlsafe_base64_decode
from django.contrib import messages
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.tokens import default_token_generator
from guardian.mixins import PermissionRequiredMixin
from stored_messages.settings import stored_messages_settings
from stored_messages.models import Message
from stored_messages.api import mark_read
from django.core.files.base import ContentFile
from django.core.urlresolvers import reverse_lazy, reverse
from django.http import Http404
from django.http import HttpResponseRedirect
from django.shortcuts import redirect
from django.shortcuts import render
from django.utils.http import urlsafe_base64_decode
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.generic import View, CreateView, FormView, ListView, \
DetailView, \
DeleteView, TemplateView, UpdateView
from guardian.mixins import PermissionRequiredMixin
from oca.pool import WrongNameError, WrongIdError
from stored_messages.api import mark_read
from stored_messages.models import Message
from stored_messages.settings import stored_messages_settings
from membership.models import CustomUser, StripeCustomer
from utils.stripe_utils import StripeUtils
from utils.forms import BillingAddressForm, PasswordResetRequestForm, UserBillingAddressForm
from utils.views import PasswordResetViewMixin, PasswordResetConfirmViewMixin, LoginViewMixin
from utils.mailer import BaseEmail
from .models import HostingOrder, HostingBill, HostingPlan, UserHostingKey
from .forms import HostingUserSignupForm, HostingUserLoginForm, UserHostingKeyForm, generate_ssh_key_name
from .mixins import ProcessVMSelectionMixin
from opennebula_api.models import OpenNebulaManager
from opennebula_api.serializers import VirtualMachineSerializer, \
VirtualMachineTemplateSerializer
from django.utils.translation import ugettext_lazy as _
from utils.forms import BillingAddressForm, PasswordResetRequestForm, \
UserBillingAddressForm
from utils.mailer import BaseEmail
from utils.stripe_utils import StripeUtils
from utils.views import PasswordResetViewMixin, PasswordResetConfirmViewMixin, \
LoginViewMixin
from .forms import HostingUserSignupForm, HostingUserLoginForm, \
UserHostingKeyForm, generate_ssh_key_name
from .mixins import ProcessVMSelectionMixin
from .models import HostingOrder, HostingBill, HostingPlan, UserHostingKey
CONNECTION_ERROR = "Your VMs cannot be displayed at the moment due to a backend \
connection error. please try again in a few minutes."
@ -296,12 +297,13 @@ class PasswordResetConfirmView(PasswordResetConfirmViewMixin):
form = self.form_class(request.POST)
if user is not None and default_token_generator.check_token(user, token):
if user is not None and default_token_generator.check_token(user,
token):
if form.is_valid():
new_password = form.cleaned_data['new_password2']
user.set_password(new_password)
user.save()
messages.success(request, 'Password has been reset.')
messages.success(request, _('Password has been reset.'))
# Change opennebula password
opennebula_client.change_user_password(new_password)
@ -309,14 +311,15 @@ class PasswordResetConfirmView(PasswordResetConfirmViewMixin):
return self.form_valid(form)
else:
messages.error(
request, 'Password reset has not been successful.')
form.add_error(None, 'Password reset has not been successful.')
request, _('Password reset has not been successful.'))
form.add_error(None,
_('Password reset has not been successful.'))
return self.form_invalid(form)
else:
messages.error(
request, 'The reset password link is no longer valid.')
form.add_error(None, 'The reset password link is no longer valid.')
error_msg = _('The reset password link is no longer valid.')
messages.error(request, _(error_msg))
form.add_error(None, error_msg)
return self.form_invalid(form)
@ -397,7 +400,8 @@ class SSHKeyListView(LoginRequiredMixin, ListView):
def render_to_response(self, context, **response_kwargs):
if not self.queryset:
return HttpResponseRedirect(reverse('hosting:choice_ssh_keys'))
return super(SSHKeyListView, self).render_to_response(context, **response_kwargs)
return super(SSHKeyListView, self).render_to_response(context,
**response_kwargs)
class SSHKeyChoiceView(LoginRequiredMixin, View):
@ -571,8 +575,10 @@ class PaymentVMView(LoginRequiredMixin, FormView):
if not customer:
msg = _("Invalid credit card")
messages.add_message(
self.request, messages.ERROR, msg, extra_tags='make_charge_error')
return HttpResponseRedirect(reverse('hosting:payment') + '#payment_error')
self.request, messages.ERROR, msg,
extra_tags='make_charge_error')
return HttpResponseRedirect(
reverse('hosting:payment') + '#payment_error')
# Create Billing Address
billing_address = form.save()
@ -586,8 +592,10 @@ class PaymentVMView(LoginRequiredMixin, FormView):
if not charge_response.get('response_object'):
msg = charge_response.get('error')
messages.add_message(
self.request, messages.ERROR, msg, extra_tags='make_charge_error')
return HttpResponseRedirect(reverse('hosting:payment') + '#payment_error')
self.request, messages.ERROR, msg,
extra_tags='make_charge_error')
return HttpResponseRedirect(
reverse('hosting:payment') + '#payment_error')
charge = charge_response.get('response_object')
@ -595,7 +603,8 @@ class PaymentVMView(LoginRequiredMixin, FormView):
manager = OpenNebulaManager(email=owner.email,
password=owner.password)
# Get user ssh key
if not UserHostingKey.objects.filter(user=self.request.user).exists():
if not UserHostingKey.objects.filter(
user=self.request.user).exists():
context.update({
'sshError': 'error',
'form': form
@ -647,7 +656,8 @@ class PaymentVMView(LoginRequiredMixin, FormView):
context = {
'vm': vm,
'order': order,
'base_url': "{0}://{1}".format(request.scheme, request.get_host())
'base_url': "{0}://{1}".format(request.scheme,
request.get_host())
}
email_data = {
@ -661,13 +671,15 @@ class PaymentVMView(LoginRequiredMixin, FormView):
email.send()
return HttpResponseRedirect(
"{url}?{query_params}".format(url=reverse('hosting:orders', kwargs={'pk': order.id}),
"{url}?{query_params}".format(
url=reverse('hosting:orders', kwargs={'pk': order.id}),
query_params='page=payment'))
else:
return self.form_invalid(form)
class OrdersHostingDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailView):
class OrdersHostingDetailView(PermissionRequiredMixin, LoginRequiredMixin,
DetailView):
template_name = "hosting/order_detail.html"
context_object_name = "order"
login_url = reverse_lazy('hosting:login')
@ -775,7 +787,8 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
configuration_options = HostingPlan.get_serialized_configs()
context = {
'templates': VirtualMachineTemplateSerializer(templates, many=True).data,
'templates': VirtualMachineTemplateSerializer(templates,
many=True).data,
'configuration_options': configuration_options,
}
except:
@ -846,7 +859,8 @@ class VirtualMachineView(LoginRequiredMixin, View):
serializer = VirtualMachineSerializer(vm)
context = {
'virtual_machine': serializer.data,
'order': HostingOrder.objects.get(vm_id=serializer.data['vm_id'])
'order': HostingOrder.objects.get(
vm_id=serializer.data['vm_id'])
}
except:
pass
@ -877,7 +891,8 @@ class VirtualMachineView(LoginRequiredMixin, View):
context = {
'vm': vm,
'base_url': "{0}://{1}".format(self.request.scheme, self.request.get_host())
'base_url': "{0}://{1}".format(self.request.scheme,
self.request.get_host())
}
email_data = {
'subject': 'Virtual machine plan canceled',
@ -897,7 +912,8 @@ class VirtualMachineView(LoginRequiredMixin, View):
return HttpResponseRedirect(self.get_success_url())
class HostingBillListView(PermissionRequiredMixin, LoginRequiredMixin, ListView):
class HostingBillListView(PermissionRequiredMixin, LoginRequiredMixin,
ListView):
template_name = "hosting/bills.html"
login_url = reverse_lazy('hosting:login')
permission_required = ['view_hostingview']
@ -907,7 +923,8 @@ class HostingBillListView(PermissionRequiredMixin, LoginRequiredMixin, ListView)
ordering = '-id'
class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin, DetailView):
class HostingBillDetailView(PermissionRequiredMixin, LoginRequiredMixin,
DetailView):
template_name = "hosting/bill_detail.html"
login_url = reverse_lazy('hosting:login')
permission_required = ['view_hostingview']

View file

@ -124,16 +124,18 @@ class PasswordResetConfirmViewMixin(FormView):
new_password = form.cleaned_data['new_password2']
user.set_password(new_password)
user.save()
messages.success(request, 'Password has been reset.')
messages.success(request, _('Password has been reset.'))
return self.form_valid(form)
else:
messages.error(request,
'Password reset has not been successful.')
form.add_error(None, 'Password reset has not been successful.')
_('Password reset has not been successful.'))
form.add_error(None,
_('Password reset has not been successful.'))
return self.form_invalid(form)
else:
messages.error(request,
'The reset password link is no longer valid.')
form.add_error(None, 'The reset password link is no longer valid.')
_('The reset password link is no longer valid.'))
form.add_error(None,
_('The reset password link is no longer valid.'))
return self.form_invalid(form)