Merge branch 'task3577' of https://github.com/siarheipuhach/dynamicweb into siarheipuhach-task3577

This commit is contained in:
PCoder 2017-07-26 01:30:24 +05:30
commit fff468f95f
2 changed files with 64 additions and 3 deletions

View file

@ -22,7 +22,15 @@
<span> Core</span> <span> Core</span>
<i class="fa fa-plus-circle right" data-plus="cpu" aria-hidden="true"></i> <i class="fa fa-plus-circle right" data-plus="cpu" aria-hidden="true"></i>
</div> </div>
<div class="help-block with-errors"></div> <div class="help-block with-errors">
{% for message in messages %}
{% if 'cores' in message.tags %}
<ul class="list-unstyled"><li>
{{ message|safe }}
</li></ul>
{% endif %}
{% endfor %}
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="description input"> <div class="description input">
@ -31,7 +39,15 @@
<span> GB RAM</span> <span> GB RAM</span>
<i class="fa fa-plus-circle right" data-plus="ram" aria-hidden="true"></i> <i class="fa fa-plus-circle right" data-plus="ram" aria-hidden="true"></i>
</div> </div>
<div class="help-block with-errors"></div> <div class="help-block with-errors">
{% for message in messages %}
{% if 'memory' in message.tags %}
<ul class="list-unstyled"><li>
{{ message|safe }}
</li></ul>
{% endif %}
{% endfor %}
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<div class="description input"> <div class="description input">
@ -40,7 +56,15 @@
<span>{% trans "GB Storage (SSD)" %}</span> <span>{% trans "GB Storage (SSD)" %}</span>
<i class="fa fa-plus-circle right" data-plus="storage" aria-hidden="true"></i> <i class="fa fa-plus-circle right" data-plus="storage" aria-hidden="true"></i>
</div> </div>
<div class="help-block with-errors"></div> <div class="help-block with-errors">
{% for message in messages %}
{% if 'storage' in message.tags %}
<ul class="list-unstyled"><li>
{{ message|safe }}
</li></ul>
{% endif %}
{% endfor %}
</div>
</div> </div>
<div class="description select-configuration input form-group justify-center"> <div class="description select-configuration input form-group justify-center">
<label for="config">OS</label> <label for="config">OS</label>

View file

@ -194,6 +194,18 @@ class IndexView(CreateView):
success_url = "/datacenterlight#requestform" success_url = "/datacenterlight#requestform"
success_message = "Thank you, we will contact you as soon as possible" success_message = "Thank you, we will contact you as soon as possible"
def validate_cores(self, value):
if (value > 48) or (value < 1):
raise ValidationError(_('Not a proper cores number'))
def validate_memory(self, value):
if (value > 200) or (value < 2):
raise ValidationError(_('Not a proper ram number'))
def validate_storage(self, value):
if (value > 2000) or (value < 10):
raise ValidationError(_('Not a proper storage number'))
@cache_control(no_cache=True, must_revalidate=True, no_store=True) @cache_control(no_cache=True, must_revalidate=True, no_store=True)
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
for session_var in ['specs', 'user', 'billing_address_data']: for session_var in ['specs', 'user', 'billing_address_data']:
@ -217,8 +229,11 @@ class IndexView(CreateView):
def post(self, request): def post(self, request):
cores = request.POST.get('cpu') cores = request.POST.get('cpu')
cores_field = forms.IntegerField(validators=[self.validate_cores])
memory = request.POST.get('ram') memory = request.POST.get('ram')
memory_field = forms.IntegerField(validators=[self.validate_memory])
storage = request.POST.get('storage') storage = request.POST.get('storage')
storage_field = forms.IntegerField(validators=[self.validate_storage])
price = request.POST.get('total') price = request.POST.get('total')
template_id = int(request.POST.get('config')) template_id = int(request.POST.get('config'))
manager = OpenNebulaManager() manager = OpenNebulaManager()
@ -229,6 +244,28 @@ class IndexView(CreateView):
email = request.POST.get('email') email = request.POST.get('email')
name_field = forms.CharField() name_field = forms.CharField()
email_field = forms.EmailField() email_field = forms.EmailField()
try:
cores = cores_field.clean(cores)
except ValidationError as err:
msg = '{} {}.'.format(cores, _('is not a proper cores number'))
messages.add_message(self.request, messages.ERROR, msg, extra_tags='cores')
return HttpResponseRedirect(reverse('datacenterlight:index') + "#order_form")
try:
memory = memory_field.clean(memory)
except ValidationError as err:
msg = '{} {}.'.format(memory, _('is not a proper memory number'))
messages.add_message(self.request, messages.ERROR, msg, extra_tags='memory')
return HttpResponseRedirect(reverse('datacenterlight:index') + "#order_form")
try:
storage = storage_field.clean(storage)
except ValidationError as err:
msg = '{} {}.'.format(storage, _('is not a proper storage number'))
messages.add_message(self.request, messages.ERROR, msg, extra_tags='storage')
return HttpResponseRedirect(reverse('datacenterlight:index') + "#order_form")
try: try:
name = name_field.clean(name) name = name_field.clean(name)
except ValidationError as err: except ValidationError as err: