diff options
Diffstat (limited to 'src/dashboard')
-rw-r--r-- | src/dashboard/forms.py | 46 | ||||
-rw-r--r-- | src/dashboard/views.py | 53 |
2 files changed, 89 insertions, 10 deletions
diff --git a/src/dashboard/forms.py b/src/dashboard/forms.py new file mode 100644 index 0000000..dd87ec6 --- /dev/null +++ b/src/dashboard/forms.py @@ -0,0 +1,46 @@ +from django import forms + +class NewIPAAccountForm(forms.Form): + + # First name + first_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'First Name', 'style': 'width: 300px;', 'class': 'form-control'})) + # Last name + last_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Last Name', 'style': 'width: 300px;', 'class': 'form-control'})) + # Company + company = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Company', 'style': 'width: 300px;', 'class': 'form-control'})) + # Email + email = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Email', 'style': 'width: 300px;', 'class': 'form-control', "readonly": True})) + +class ReadOnlyIPAAccountForm(forms.Form): + # IPA Username + ipa_username = forms.CharField(required=False, widget=forms.TextInput(attrs={'placeholder': 'IPA Username', 'style': 'width: 300px;', 'class': 'form-control', "readonly": True})) + # First name + first_name = forms.CharField(required=False, widget=forms.TextInput(attrs={'placeholder': 'First Name', 'style': 'width: 300px;', 'class': 'form-control', "readonly": True})) + # Last name + last_name = forms.CharField(required=False, widget=forms.TextInput(attrs={'placeholder': 'Last Name', 'style': 'width: 300px;', 'class': 'form-control', "readonly": True})) + # Company + company = forms.CharField(required=False, widget=forms.TextInput(attrs={'placeholder': 'Company', 'style': 'width: 300px;', 'class': 'form-control', "readonly": True})) + # Email + email = forms.CharField(required=False, widget=forms.TextInput(attrs={'placeholder': 'Email', 'style': 'width: 300px;', 'class': 'form-control', "readonly": True})) + +class ConflictIPAAcountForm(forms.Form): + # IPA Username + ipa_username = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'IPA Username', 'style': 'width: 300px;', 'class': 'form-control'})) + # First name + first_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'First Name', 'style': 'width: 300px;', 'class': 'form-control'})) + # Last name + last_name = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Last Name', 'style': 'width: 300px;', 'class': 'form-control'})) + # Company + company = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Company', 'style': 'width: 300px;', 'class': 'form-control'})) + # Email + email = forms.CharField(widget=forms.TextInput(attrs={'placeholder': 'Email', 'style': 'width: 300px;', 'class': 'form-control', "readonly": True})) + +class SetCompanyForm(forms.Form): + # Company + company = forms.CharField(required=True, widget=forms.TextInput(attrs={'placeholder': 'Company', 'style': 'width: 300px;', 'class': 'form-control'})) + +class SetSSHForm(forms.Form): + # SSH key + ssh_public_key = forms.CharField(required=True, widget=forms.Textarea(attrs={'placeholder': 'SSH Public Key', 'style': 'width: 300px;', 'class': 'form-control'})) + + diff --git a/src/dashboard/views.py b/src/dashboard/views.py index 2942d59..f250a3c 100644 --- a/src/dashboard/views.py +++ b/src/dashboard/views.py @@ -16,8 +16,11 @@ from django.db.models import Q from datetime import datetime import pytz -from account.models import Lab +from account.models import Lab, UserProfile +from api.utils import get_ipa_migration_form, ipa_query_user +from api.views import ipa_conflict_account from booking.models import Booking +from dashboard.forms import * from laas_dashboard import settings @@ -72,25 +75,55 @@ def host_profile_detail_view(request): def landing_view(request): user = request.user + ipa_migrator = { + "exists": "false" # Jinja moment + } if not user.is_anonymous: bookings = Booking.objects.filter( Q(owner=user) | Q(collaborators=user), end__gte=datetime.now(pytz.utc) ) + profile = UserProfile.objects.get(user=user) + if (not profile.ipa_username): + ipa_migrator = get_ipa_migration_form(user, profile) + ipa_migrator["exists"] = "true" + else: bookings = None + print("IPA migrator is", ipa_migrator) LFID = True if settings.AUTH_SETTING == 'LFID' else False - return render( - request, - 'dashboard/landing.html', - { - 'title': "Welcome to the Lab as a Service Dashboard", - 'bookings': bookings, - 'LFID': LFID - } - ) + if request.method == "GET": + return render( + request, + 'dashboard/landing.html', + { + 'title': "Welcome to the Lab as a Service Dashboard", + 'bookings': bookings, + 'LFID': LFID, + 'ipa_migrator': ipa_migrator, + } + ) + + # Using this for the special case in the ipa_migrator + if request.method == 'POST': + existing_profile = ipa_query_user(request.POST['ipa_username']) + print("exists already?", existing_profile != None) + if (existing_profile != None): + return render( + request, + 'dashboard/landing.html', + { + 'title': "Welcome to the Lab as a Service Dashboard", + 'bookings': bookings, + 'LFID': LFID, + 'ipa_migrator': ipa_migrator, + 'error': "Username is already taken" + } + ) + else: + return ipa_conflict_account(request) class LandingView(TemplateView): template_name = "dashboard/landing.html" |