diff --git a/osinaweb/db.sqlite3 b/osinaweb/db.sqlite3 index aa8e16c0..83ef60fd 100644 Binary files a/osinaweb/db.sqlite3 and b/osinaweb/db.sqlite3 differ diff --git a/osinaweb/osinacore/__pycache__/forms.cpython-310.pyc b/osinaweb/osinacore/__pycache__/forms.cpython-310.pyc index e3e7e983..8f6ca498 100644 Binary files a/osinaweb/osinacore/__pycache__/forms.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/forms.cpython-310.pyc differ diff --git a/osinaweb/osinacore/__pycache__/models.cpython-310.pyc b/osinaweb/osinacore/__pycache__/models.cpython-310.pyc index d32a970b..98e3d851 100644 Binary files a/osinaweb/osinacore/__pycache__/models.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/models.cpython-310.pyc differ diff --git a/osinaweb/osinacore/__pycache__/views.cpython-310.pyc b/osinaweb/osinacore/__pycache__/views.cpython-310.pyc index f3b4c006..c601feec 100644 Binary files a/osinaweb/osinacore/__pycache__/views.cpython-310.pyc and b/osinaweb/osinacore/__pycache__/views.cpython-310.pyc differ diff --git a/osinaweb/osinacore/forms.py b/osinaweb/osinacore/forms.py index 86958069..0a782d2c 100644 --- a/osinaweb/osinacore/forms.py +++ b/osinaweb/osinacore/forms.py @@ -11,3 +11,9 @@ class SignUpForm(forms.ModelForm): class Meta: model = CustomerProfile fields = ['first_name', 'last_name', 'email', 'password', 'mobile_number', 'status', 'reference', 'personal_website', 'business'] + + +class StaffSignUpForm(forms.ModelForm): + class Meta: + model = StaffProfile + fields = ['first_name', 'last_name', 'image', 'email', 'mobile_number', 'password', 'position', 'intern', 'active'] \ No newline at end of file diff --git a/osinaweb/osinacore/migrations/0031_alter_staffprofile_image.py b/osinaweb/osinacore/migrations/0031_alter_staffprofile_image.py new file mode 100644 index 00000000..ed2e442f --- /dev/null +++ b/osinaweb/osinacore/migrations/0031_alter_staffprofile_image.py @@ -0,0 +1,18 @@ +# Generated by Django 4.2.5 on 2023-09-21 13:23 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('osinacore', '0030_tag'), + ] + + operations = [ + migrations.AlterField( + model_name='staffprofile', + name='image', + field=models.ImageField(blank=True, null=True, upload_to=''), + ), + ] diff --git a/osinaweb/osinacore/migrations/__pycache__/0031_alter_staffprofile_image.cpython-310.pyc b/osinaweb/osinacore/migrations/__pycache__/0031_alter_staffprofile_image.cpython-310.pyc new file mode 100644 index 00000000..d76a61c8 Binary files /dev/null and b/osinaweb/osinacore/migrations/__pycache__/0031_alter_staffprofile_image.cpython-310.pyc differ diff --git a/osinaweb/osinacore/models.py b/osinaweb/osinacore/models.py index a9da4ba6..0e65fc6e 100644 --- a/osinaweb/osinacore/models.py +++ b/osinaweb/osinacore/models.py @@ -87,16 +87,10 @@ class StaffProfile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) first_name = models.CharField(max_length=50) last_name = models.CharField(max_length=50) - image = models.ImageField(null=True) + image = models.ImageField(null=True, blank=True) email = models.EmailField(unique=True) mobile_number = models.CharField(max_length=50) password = models.CharField(max_length=128) - Staff_CHOICES = ( - ('Developer', 'Developer'), - ('Designer', 'Designer'), - ('Support', 'Support'), - ('Project Manager', 'Project Manager'), - ) position = models.CharField(max_length=100) intern = models.BooleanField(default=False) active = models.BooleanField(default=True) diff --git a/osinaweb/osinacore/views.py b/osinaweb/osinacore/views.py index 3a270c53..bde28faf 100644 --- a/osinaweb/osinacore/views.py +++ b/osinaweb/osinacore/views.py @@ -8,7 +8,6 @@ from django.utils import timezone from django.urls import reverse from django.http import HttpResponse from django.db.models import Q - from django.http import JsonResponse from .models import Task, Epic @@ -223,6 +222,7 @@ def addbusiness(request): } return render(request, 'add-business.html', context) + @login_required def businessdetails(request): context = { @@ -230,6 +230,7 @@ def businessdetails(request): } return render(request, 'business-details.html', context) + @login_required def businesses(request): context = { @@ -239,32 +240,37 @@ def businesses(request): @login_required -def adduser(request): +def addstaff(request): context = { } - return render(request, 'add-user.html', context) + return render(request, 'add-staff.html', context) + @login_required -def userdetails(request): +def staffdetails(request): context = { } - return render(request, 'user-details.html', context) + return render(request, 'staff-details.html', context) + + @login_required -def users(request): +def staffs(request): + staffs = StaffProfile.objects.all().order_by('-id') context = { - + 'staffs' : staffs, + } - return render(request, 'users.html', context) + return render(request, 'staffs.html', context) @@ -676,6 +682,7 @@ def save_business_modal(request): return render(request, 'addbusiness-modal.html') + def save_customer(request): if request.method == 'POST': form = SignUpForm(request.POST) @@ -709,6 +716,52 @@ def save_customer(request): return redirect('customers') +def save_staff(request): + if request.method == 'POST': + form = StaffSignUpForm(request.POST, request.FILES) + if form.is_valid(): + # Extract cleaned data from the form + email = form.cleaned_data['email'] + first_name = form.cleaned_data['first_name'].replace(" ", "") + last_name = form.cleaned_data['last_name'].replace(" ", "") + username = f"{first_name.lower()}{last_name.lower()}" + original_username = username + counter = 1 # Initialize a counter to add numbers + + while User.objects.filter(username=username).exists(): + # If the username already exists, append the counter to it + username = f"{original_username.lower()}{counter}" + counter += 1 + + # Create a User instance + user = User.objects.create_user( + username=username, + email=email, + password=form.cleaned_data['password'] + ) + user.first_name = form.cleaned_data['first_name'] + user.last_name = form.cleaned_data['last_name'] + user.save() + + # Create a StaffProfile instance with the associated user + staff_profile = form.save(commit=False) + staff_profile.user = user + + # Attach the uploaded image to the StaffProfile instance + staff_profile.image = form.cleaned_data['image'] + + staff_profile.save() + else: + # Print form errors to see why it's not valid + print('Form is not valid. Errors:') + print(form.errors) + + return redirect('users') + + + + + @login_required def save_status(request): if request.method == 'POST': diff --git a/osinaweb/osinaweb/__pycache__/urls.cpython-310.pyc b/osinaweb/osinaweb/__pycache__/urls.cpython-310.pyc index 2ea09a4b..279d9eaf 100644 Binary files a/osinaweb/osinaweb/__pycache__/urls.cpython-310.pyc and b/osinaweb/osinaweb/__pycache__/urls.cpython-310.pyc differ diff --git a/osinaweb/osinaweb/urls.py b/osinaweb/osinaweb/urls.py index 954cc276..9917a483 100644 --- a/osinaweb/osinaweb/urls.py +++ b/osinaweb/osinaweb/urls.py @@ -34,9 +34,9 @@ urlpatterns = [ path('addbusiness/', views.addbusiness, name='addbusiness'), path('businessdetails/', views.businessdetails, name='businessdetails'), path('businesses/', views.businesses, name='businesses'), - path('adduser/', views.adduser, name='adduser'), - path('userdetails/', views.userdetails, name='userdetails'), - path('users/', views.users, name='users'), + path('addstaff/', views.addstaff, name='adduser'), + path('staffdetails/', views.staffdetails, name='userdetails'), + path('staffs/', views.staffs, name='users'), path('projectdetails//', views.detailed_project, name='detailed-project'), path('createproject/', views.create_project, name='createproject'), path('createepic//', views.create_epic, name='createepic'), @@ -79,10 +79,12 @@ urlpatterns = [ path('save_business/', views.save_business, name='save_business'), path('save_business_modal/', views.save_business_modal, name='save_business_modal'), path('save_customer/', views.save_customer, name='save_customer'), + path('save_staff/', views.save_staff, name='save_staff'), path('save_status/', views.save_status, name='save_status'), path('save_projecttype/', views.save_projecttype, name='save_projecttype'), path('save_reference/', views.save_reference, name='save_reference'), path('save_tag/', views.save_tag, name='save_tag'), + ] urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/osinaweb/static/images/checkicon.png b/osinaweb/static/images/checkicon.png new file mode 100644 index 00000000..21289a31 Binary files /dev/null and b/osinaweb/static/images/checkicon.png differ diff --git a/osinaweb/static/images/contactbanner.jpg b/osinaweb/static/images/contactbanner.jpg new file mode 100644 index 00000000..2714164d Binary files /dev/null and b/osinaweb/static/images/contactbanner.jpg differ diff --git a/osinaweb/templates/add-user.html b/osinaweb/templates/add-staff.html similarity index 74% rename from osinaweb/templates/add-user.html rename to osinaweb/templates/add-staff.html index c6c9df37..348b0d6f 100644 --- a/osinaweb/templates/add-user.html +++ b/osinaweb/templates/add-staff.html @@ -14,7 +14,7 @@ --> -
+ {% csrf_token %}
@@ -23,7 +23,7 @@
- + Upload Profile Picture
- - - - - - - - @@ -99,18 +80,37 @@ - -
- -

Active

-
+ -
- -

Intern

-
+
+ +

Active

+
+ +
+ +

Intern

+
+ + + + +