improveded mobile responsiveness

This commit is contained in:
Henry Bravo 2017-06-03 21:19:13 -05:00
commit 9b121cc702
17 changed files with 466 additions and 383 deletions

View file

@ -4,6 +4,7 @@ from django import forms
from membership.models import CustomUser
from django.contrib.auth import authenticate
from django.utils.translation import ugettext_lazy as _
from utils.stripe_utils import StripeUtils
@ -57,21 +58,19 @@ class HostingUserSignupForm(forms.ModelForm):
class UserHostingKeyForm(forms.ModelForm):
private_key = forms.CharField(widget=forms.PasswordInput(), required=False)
public_key = forms.CharField(widget=forms.PasswordInput(), required=False)
user = forms.models.ModelChoiceField(queryset=CustomUser.objects.all(), required=False)
name = forms.CharField(required=False)
private_key = forms.CharField(widget=forms.HiddenInput(), required=False)
public_key = forms.CharField(widget=forms.Textarea(), required=False,
help_text=_('Paste here your public key'))
user = forms.models.ModelChoiceField(queryset=CustomUser.objects.all(),
required=False, widget=forms.HiddenInput())
name = forms.CharField(required=True)
def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request")
super(UserHostingKeyForm, self).__init__(*args, **kwargs)
# self.initial['user'].initial = self.request.user.id
# print(self.fields)
def clean_name(self):
return "dcl-priv-key-%s" % (
''.join(random.choice(string.ascii_lowercase) for i in range(7))
)
return self.data.get('name')
def clean_user(self):
return self.request.user
@ -90,4 +89,4 @@ class UserHostingKeyForm(forms.ModelForm):
class Meta:
model = UserHostingKey
fields = ['user', 'public_key', 'name']
fields = ['user', 'name', 'public_key']

View file

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-06-01 11:20-0500\n"
"POT-Creation-Date: 2017-06-01 21:03+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"
@ -18,55 +18,64 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: templates/hosting/base_short.html:68 templates/hosting/base_short.html:139
#: hosting/forms.py:63
msgid "Paste here your public key"
msgstr "Fügen Sie Ihren public key ein"
#: hosting/templates/hosting/base_short.html:68
#: hosting/templates/hosting/base_short.html:139
msgid "My Virtual Machines"
msgstr ""
#: templates/hosting/base_short.html:73 templates/hosting/base_short.html:145
#: templates/hosting/orders.html.py:12
#: hosting/templates/hosting/base_short.html:73
#: hosting/templates/hosting/base_short.html:145
#: hosting/templates/hosting/orders.html:12
msgid "My Orders"
msgstr ""
#: templates/hosting/base_short.html:78 templates/hosting/base_short.html:152
#: hosting/templates/hosting/base_short.html:78
#: hosting/templates/hosting/base_short.html:152
msgid "Keys"
msgstr ""
#: templates/hosting/base_short.html:83 templates/hosting/base_short.html:158
#: hosting/templates/hosting/base_short.html:83
#: hosting/templates/hosting/base_short.html:158
msgid "Notifications "
msgstr ""
#: templates/hosting/base_short.html:90
#: hosting/templates/hosting/base_short.html:90
msgid "Logout"
msgstr ""
#: templates/hosting/base_short.html:95
#: hosting/templates/hosting/base_short.html:95
msgid "How it works"
msgstr ""
#: templates/hosting/base_short.html:98
#: hosting/templates/hosting/base_short.html:98
msgid "Your infrastructure"
msgstr ""
#: templates/hosting/base_short.html:101
#: hosting/templates/hosting/base_short.html:101
msgid "Our inftrastructure"
msgstr ""
#: templates/hosting/base_short.html:104
#: hosting/templates/hosting/base_short.html:104
msgid "Pricing"
msgstr ""
#: templates/hosting/base_short.html:107
#: hosting/templates/hosting/base_short.html:107
msgid "Contact"
msgstr ""
#: templates/hosting/base_short.html:110
#: templates/hosting/confirm_reset_password.html:38
#: templates/hosting/login.html:31 templates/hosting/login.html.py:40
#: templates/hosting/reset_password.html:30 templates/hosting/signup.html:29
#: hosting/templates/hosting/base_short.html:110
#: hosting/templates/hosting/login.html:32
#: hosting/templates/hosting/login.html:41
#: hosting/templates/hosting/reset_password.html:31
#: hosting/templates/hosting/signup.html:30
msgid "Login"
msgstr ""
#: templates/hosting/base_short.html:134
#: hosting/templates/hosting/base_short.html:134
msgid "Home"
msgstr ""
@ -135,8 +144,8 @@ msgstr ""
msgid "Customers"
msgstr ""
#: templates/hosting/bills.html:16
#: templates/hosting/virtual_machine_key.html:45
#: hosting/templates/hosting/bills.html:16
#: hosting/templates/hosting/virtual_machine_key.html:42
msgid "Name"
msgstr ""
@ -168,13 +177,14 @@ msgstr "Ihre VM in der Schweiz"
msgid "Set your new password"
msgstr ""
#: templates/hosting/confirm_reset_password.html:29
#: templates/hosting/reset_password.html:21
#: hosting/templates/hosting/confirm_reset_password.html:28
#: hosting/templates/hosting/reset_password.html:22
msgid "Reset"
msgstr ""
#: templates/hosting/confirm_reset_password.html:35
#: templates/hosting/reset_password.html:27 templates/hosting/signup.html:26
#: hosting/templates/hosting/confirm_reset_password.html:32
#: hosting/templates/hosting/reset_password.html:28
#: hosting/templates/hosting/signup.html:27
msgid "Already have an account ?"
msgstr ""
@ -210,20 +220,27 @@ msgstr ""
msgid "The %(site_name)s team"
msgstr ""
#: templates/hosting/login.html:25
#: hosting/templates/hosting/login.html:10
#: hosting/templates/hosting/reset_password.html:10
#: hosting/templates/hosting/signup.html:9
msgid "Your VM hosted in Switzerland"
msgstr ""
#: hosting/templates/hosting/login.html:26
msgid "You haven been logged out"
msgstr ""
#: templates/hosting/login.html:48
#: hosting/templates/hosting/login.html:49
msgid "Don't have an account yet ? "
msgstr ""
#: templates/hosting/login.html:51 templates/hosting/signup.html.py:12
#: templates/hosting/signup.html:20
#: hosting/templates/hosting/login.html:52
#: hosting/templates/hosting/signup.html:13
#: hosting/templates/hosting/signup.html:21
msgid "Sign up"
msgstr ""
#: templates/hosting/login.html:53
#: hosting/templates/hosting/login.html:54
msgid "Forgot your password ? "
msgstr ""
@ -298,10 +315,10 @@ msgstr ""
msgid "Amount"
msgstr ""
#: templates/hosting/orders.html:19
#: templates/hosting/virtual_machine_detail.html:30
#: templates/hosting/virtual_machine_key.html:47
#: templates/hosting/virtual_machines.html:31
#: hosting/templates/hosting/orders.html:19
#: hosting/templates/hosting/virtual_machine_detail.html:30
#: hosting/templates/hosting/virtual_machine_key.html:44
#: hosting/templates/hosting/virtual_machines.html:31
msgid "Status"
msgstr ""
@ -333,7 +350,7 @@ msgstr ""
msgid "Delete"
msgstr ""
#: templates/hosting/reset_password.html:13
#: hosting/templates/hosting/reset_password.html:14
msgid "Reset your password"
msgstr ""
@ -389,50 +406,46 @@ msgstr ""
msgid "Access Key"
msgstr ""
#: templates/hosting/virtual_machine_key.html:22
#: hosting/templates/hosting/virtual_machine_key.html:25
msgid "Upload your own key. "
msgstr ""
#: templates/hosting/virtual_machine_key.html:29
msgid "Upload Key"
msgstr ""
#: templates/hosting/virtual_machine_key.html:33
#: hosting/templates/hosting/virtual_machine_key.html:29
msgid "Or generate a new key pair."
msgstr ""
#: templates/hosting/virtual_machine_key.html:37
#: hosting/templates/hosting/virtual_machine_key.html:31
msgid "Generate Key Pair"
msgstr ""
#: templates/hosting/virtual_machine_key.html:46
#: hosting/templates/hosting/virtual_machine_key.html:43
msgid "Created at"
msgstr ""
#: templates/hosting/virtual_machine_key.html:68
#: templates/hosting/virtual_machine_key.html:81
#: hosting/templates/hosting/virtual_machine_key.html:66
#: hosting/templates/hosting/virtual_machine_key.html:79
msgid "Warning!"
msgstr ""
#: templates/hosting/virtual_machine_key.html:68
#: hosting/templates/hosting/virtual_machine_key.html:66
msgid "You can download your SSH private key once. Don't lost your key"
msgstr ""
#: templates/hosting/virtual_machine_key.html:76
#: hosting/templates/hosting/virtual_machine_key.html:74
msgid "Copy to Clipboard"
msgstr ""
#: templates/hosting/virtual_machine_key.html:77
#: hosting/templates/hosting/virtual_machine_key.html:75
msgid "Download"
msgstr ""
#: templates/hosting/virtual_machine_key.html:81
#: hosting/templates/hosting/virtual_machine_key.html:79
msgid ""
"Your SSH private key was already generated and downloaded, if you lost it, "
"contact us. "
msgstr ""
#: templates/hosting/virtual_machine_key.html:84
#: hosting/templates/hosting/virtual_machine_key.html:82
msgid "Generate my key"
msgstr ""

View file

@ -50,5 +50,8 @@
select {
width: 280px;
}
.content-dashboard {
width: 90%;
}
}

View file

@ -344,6 +344,19 @@ h6 {
ul.banner-social-buttons > li:last-child {
margin-bottom: 0;
}
.auth-box .form {
padding: 15px 0px 0 0;
}
.auth-box.sign-up .form {
padding: 15px 0px 0 0;
}
.auth-box .form .form-control {
height: 44px;
font-size: 13px;
}
.auth-container .auth-title {
display: none;
}
}
@media (max-width: 540px) {
.auth-container .auth-title h2{
@ -357,7 +370,6 @@ h6 {
margin-bottom: 50px;
}
.auth-box .form {
padding: 15px;
width: 90%;
}
.auth-box .section-heading {

View file

@ -73,11 +73,7 @@
<i class="fa fa-credit-card"></i> {% trans "My Orders"%}
</a>
</li>
<li>
<a href="{% url 'hosting:key_pair' %}">
<i class="fa fa-key" aria-hidden="true"></i> {% trans "Keys"%}
</a>
</li>
<li>
<a href="{% url 'hosting:notifications' %}">
<i class="fa fa-bell"></i> {% trans "Notifications "%}
@ -88,6 +84,11 @@
<i class="glyphicon glyphicon-user"></i> {{request.user.name}} <span class="caret"></span></a>
<ul id="g-account-menu" class="dropdown-menu" role="menu">
<li><a href="{% url 'hosting:logout' %}"><i class="glyphicon glyphicon-lock"></i>{% trans "Logout"%} </a></li>
<li>
<a href="{% url 'hosting:key_pair' %}">
<i class="fa fa-key"></i> {% trans "Keys"%}
</a>
</li>
</ul>
</li>
<!--
@ -127,42 +128,7 @@
{% if request.user.is_authenticated %}
<footer class="navbar-fixed-bottom">
<div class="container">
<div class="row">
<div class="col-lg-12">
<!-- <ul class="list-inline">
<li>
<a href="#">{% trans "Home"%}</a>
</li>
<li class="footer-menu-divider">&sdot;</li>
<li>
<a href="{% url 'hosting:virtual_machines' %}">
{% trans "My Virtual Machines"%}
</a>
</li>
<li class="footer-menu-divider">&sdot;</li>
<li>
<a href="{% url 'hosting:orders' %}">
{% trans "My Orders"%}
</a>
</li>
<li>&sdot;</li>
<li>
<li>
<a href="{% url 'hosting:key_pair' %}">
{% trans "Keys"%}
</a>
</li>
<li class="footer-menu-divider">&sdot;</li>
<li>
<a href="{% url 'hosting:notifications' %}">
{% trans "Notifications "%}
</a>
</li>
</ul> -->
<p class="copyright text-muted small">Copyright &copy; ungleich GmbH {% now "Y" %}. All Rights Reserved</p>
</div>
</div>
<p class="copyright text-muted small">Copyright &copy; ungleich GmbH {% now "Y" %}. All Rights Reserved</p>
</div>
</footer>
{% endif %}

View file

@ -6,7 +6,7 @@
<div class="row">
<div class="container-table col-md-9 col-md-offset-2">
<div class="col-sm-12">
<form method="POST" action="" >
<form method="POST" action="" novalidate>
{% csrf_token %}
<h3><i class="fa fa-key fa-separate" aria-hidden="true"></i>{% trans "Access Key"%} </h3>
{% if messages %}
@ -15,28 +15,25 @@
<span>{{ message }}</span>
{% endfor %}
</div>
{% endif %}
<hr/>
{% if not user_key %}
<h3>
{% endif %}
{% for field in form %}
{% bootstrap_field field %}
{% endfor %}
{% buttons %}
<button type="submit" class="btn btn-success">
{% trans "Upload your own key. "%}
</h3>
<div class="form-group">
<label for="comment">Paste here your public key</label>
<textarea class="form-control" rows="6" name="public_key"></textarea>
</div>
<div class="form-group">
<button class="btn btn-success">{% trans "Upload Key"%} </a>
</div>
<h3>
{% trans "Or generate a new key pair."%}
</h3>
<div class="form-group">
</button>
<br />
<br />
{% trans "Or generate a new key pair."%} <br />
<br />
<button class="btn btn-success">{% trans "Generate Key Pair"%} </a>
</button>
{% endbuttons %}
<div class="form-group">
</div>
{% else %}
<h5> Use your created key to access to the machine. If you lost it, contact us. </h5>
<table class="table borderless table-hover">
<br/>
@ -49,6 +46,7 @@
</tr>
</thead>
<tbody>
{% for user_key in keys %}
<tr>
<td scope="row">{{user_key.name}}</td>
<td>{{user_key.created_at}}</td>
@ -57,9 +55,9 @@
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</form>
{% if private_key %}

View file

@ -1,3 +1,5 @@
from django.test import TestCase
# Create your tests here.
test_user_can_add_key()

View file

@ -301,16 +301,12 @@ class GenerateVMSSHKeysView(LoginRequiredMixin, FormView):
self
).get_context_data(**kwargs)
try:
user_key = UserHostingKey.objects.get(
user=self.request.user
)
except UserHostingKey.DoesNotExist:
user_key = None
user_keys = UserHostingKey.objects.filter(
user=self.request.user
)
context.update({
'user_key': user_key
'keys': user_keys
})
return context
@ -351,24 +347,14 @@ class GenerateVMSSHKeysView(LoginRequiredMixin, FormView):
opennebula_user = user_pool.get_by_name(owner.email)
# Get user ssh key
user_key = UserHostingKey.objects.get(user=owner)
public_key = form.cleaned_data.get('public_key')
# Add ssh key to user
manager.oneadmin_client.call('user.update', opennebula_user.id,
'<CONTEXT><SSH_PUBLIC_KEY>{ssh_key}</SSH_PUBLIC_KEY></CONTEXT>'.format(ssh_key=user_key.public_key))
'<CONTEXT><SSH_PUBLIC_KEY>{key}</SSH_PUBLIC_KEY></CONTEXT>'.format(key=public_key))
return render(self.request, self.template_name, context)
def post(self, request, *args, **kwargs):
try:
UserHostingKey.objects.get(
user=self.request.user
)
return HttpResponseRedirect(reverse('hosting:key_pair'))
except UserHostingKey.DoesNotExist:
pass
form = self.get_form()
if form.is_valid():
return self.form_valid(form)
@ -421,11 +407,7 @@ class PaymentVMView(LoginRequiredMixin, FormView):
return context
def get(self, request, *args, **kwargs):
try:
UserHostingKey.objects.get(
user=self.request.user
)
except UserHostingKey.DoesNotExist:
if not UserHostingKey.objects.filter( user=self.request.user).exists():
messages.success(
request,
'In order to create a VM, you create/upload your SSH KEY first.'
@ -487,14 +469,16 @@ class PaymentVMView(LoginRequiredMixin, FormView):
manager = OpenNebulaManager(email=owner.email,
password=owner.password)
# Get user ssh key
try:
user_key = UserHostingKey.objects.get(
user=self.request.user
)
except UserHostingKey.DoesNotExist:
pass
if not UserHostingKey.objects.filter( user=self.request.user).exists():
context.update({
'sshError': 'error',
'form': form
})
return render(request, self.template_name, context)
# For now just get first one
user_key = UserHostingKey.objects.filter(
user=self.request.user).first()
# Create a vm using logged user
vm_id = manager.create_vm(
template_id=vm_template_id,
@ -639,11 +623,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
def get(self, request, *args, **kwargs):
try:
UserHostingKey.objects.get(
user=self.request.user
)
except UserHostingKey.DoesNotExist:
if not UserHostingKey.objects.filter( user=self.request.user).exists():
messages.success(
request,
'In order to create a VM, you need to create/upload your SSH KEY first.'
@ -667,7 +647,7 @@ class CreateVirtualMachinesView(LoginRequiredMixin, View):
)
context = {
'error': 'connection'
}
}
return render(request, self.template_name, context)