Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .envs/.local/.django
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# General
DJANGO_SETTINGS_MODULE=config.settings.local

# ------------------------------------------------------------------------------
USE_DOCKER=yes
IPYTHONDIR=/app/.ipython
Expand All @@ -25,4 +27,8 @@ SLACK_TOKEN=xoxb-1835271736544-1830161031810-VovHkwU9mK3x8quSPkeG01iO

# ASSESSMENT
# ------------------------------------------------------------------------------
ASSESSMENT_PASSWORD=test_password
ASSESSMENT_PASSWORD=test_password

#adding database url
DATABASE_URL=postgres://RHSQIZWBALCEoMwzlabSEAiqjgOFvLD:Ozs0ll0FqF2fHftZJ13vYWdrS1glWu3lCAA8yyHUkfJs70u6eTBcuisrGL8Ir2nA@postgres:5432/codershq
CELERY_BROKER_URL=redis://redis:6379/0
1 change: 1 addition & 0 deletions .envs/.local/.postgres
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ POSTGRES_PORT=5432
POSTGRES_DB=codershq
POSTGRES_USER=RHSQIZWBALCEoMwzlabSEAiqjgOFvLD
POSTGRES_PASSWORD=Ozs0ll0FqF2fHftZJ13vYWdrS1glWu3lCAA8yyHUkfJs70u6eTBcuisrGL8Ir2nA

78 changes: 77 additions & 1 deletion codershq/api/serializers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib.auth import get_user_model
"""from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, User
from django.contrib.auth.password_validation import validate_password
from djangosaml2idp.models import ServiceProvider
Expand Down Expand Up @@ -60,3 +60,79 @@ def create(self, validated_data):
user.save()

return user
"""
#new
from django.contrib.auth import get_user_model
from django.contrib.auth.password_validation import validate_password
from rest_framework import serializers
from rest_framework.validators import UniqueValidator
from codershq.users.models import User
from codershq.portfolio.models import Portfolio
from rest_framework import serializers

User = get_user_model() # Use custom user model

class UserSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = User
fields = ['url', 'username', 'email', 'groups','id']

class PortfolioSerializer(serializers.ModelSerializer):
class Meta:
model = Portfolio
fields = '__all__'


class RegisterSerializer(serializers.ModelSerializer):
email = serializers.EmailField(
required=True,
validators=[UniqueValidator(queryset=User.objects.all())]
)

password = serializers.CharField(
write_only=True,
required=True,
validators=[validate_password]
)

password2 = serializers.CharField(
write_only=True,
required=True,
label="Confirm Password"
)

class Meta:
model = User
fields = (
'username',
'email',
'first_name',
'last_name',
'password',
'password2',
)
extra_kwargs = {
'first_name': {'required': True},
'last_name': {'required': True},
}

def validate(self, attrs):
if attrs['password'] != attrs['password2']:
raise serializers.ValidationError({
"password": "Passwords do not match."
})
return attrs

def create(self, validated_data):
# Remove password2 from data before creating the user
validated_data.pop('password2')

user = User(
username=validated_data['username'],
email=validated_data['email'],
first_name=validated_data['first_name'],
last_name=validated_data['last_name']
)
user.set_password(validated_data['password'])
user.save()
return user
19 changes: 18 additions & 1 deletion codershq/assessment/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
from django import forms
from codershq.users.models import Assessment
#class PluralPasswordForm(forms.Form):
# password = forms.PasswordInput('password', max_length=255)
# adding
from django import forms

class PluralPasswordForm(forms.Form):
password = forms.PasswordInput('password', max_length=255)
password = forms.CharField(
widget=forms.PasswordInput,
max_length=255,
label='Password'
)

from django import forms

#adding Assesment form
class AssessmentForm(forms.ModelForm):
class Meta:
model = Assessment
exclude = ['user', 'submitted_at']
5 changes: 4 additions & 1 deletion codershq/assessment/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
urlpatterns = [
path('idp/', include('djangosaml2idp.urls', namespace='djangosaml2')),
path('login/', LoginView.as_view(template_name='idp/login.html'), name='login'),
path('logout/', LogoutView.as_view()),
path('logout/', LogoutView.as_view(),name='logout'), #adding name
path('', views.IndexView.as_view()),
# App views
path('', views.IndexView.as_view(), name='index'), # Only one root path
path('assessment/', views.assessment_form, name='assessment_form'),
]
25 changes: 24 additions & 1 deletion codershq/assessment/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
from django.conf import settings
from django.views.generic import TemplateView
from djangosaml2idp.models import ServiceProvider

from .forms import AssessmentForm
from django.contrib.auth.decorators import login_required
from django.shortcuts import render, redirect

class IndexView(TemplateView):
template_name = "assessment/index.html"
Expand All @@ -17,4 +19,25 @@ def get_context_data(self, **kwargs):
"known_sp_ids": [sp for sp in ServiceProvider.objects.filter(active=True)],
})
return context
#added assessment function
@login_required
def assessment_form(request):
if request.method == 'POST':
print("Form POST submitted")
profile_form = AssessmentForm(request.POST)
if profile_form.is_valid():
print("Form is valid")
assessment = profile_form.save(commit=False)
assessment.user = request.user
assessment.save()
print("Redirecting to dashboard:home")
return redirect('dashboard:home') # or use reverse()
else:
print("Form is invalid:")
print(profile_form.errors)
else:
profile_form = AssessmentForm()

return render(request, 'assessment/plural_password.html', {
'profile_form': profile_form
})
6 changes: 5 additions & 1 deletion codershq/dashboard/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@

app_name = "dashboard"
urlpatterns = [
# path('', TemplateView.as_view(template_name="dashboard/home.html"), name="home"),
# path('', TemplateView.as_view(template_name="dashboard/home.html"), name="home"),
path("", views.index, name="home"),
path("landing/", views.landing, name="landing"),
path("news/", views.news, name="news"),

]



24 changes: 18 additions & 6 deletions codershq/dashboard/views.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
import requests
from django.shortcuts import redirect, render

news_url = "https://www.reddit.com/r/programming/.json"

from django.http import JsonResponse
from codershq.users.forms import UserInterestForm
from codershq.users.models import UserInterest

def index(request):
if not request.user.is_authenticated:
return redirect("/accounts/login/")
return redirect("/accounts/login/")
# return render(request, "pages/dashboard.html")

instance, created = UserInterest.objects.get_or_create(user=request.user)

# ✅ Handle AJAX POST (inside modal)
if request.method == "POST" and request.headers.get("x-requested-with") == "XMLHttpRequest":
form = UserInterestForm(request.POST, instance=instance)
if form.is_valid():
form.save()
message = "✅ Interests registered successfully." if created else "✅ Interests updated successfully."
return JsonResponse({"message": message})
return JsonResponse({"errors": form.errors}, status=400)

# GET: Render base page with button
form = UserInterestForm()
return render(request, "_dashboard.html", {"form": form})


def landing(request):
Expand Down
28 changes: 28 additions & 0 deletions codershq/portfolio/migrations/0009_auto_20251017_0504.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 3.2.11 on 2025-10-17 01:04

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('portfolio', '0008_auto_20221010_0132'),
]

operations = [
migrations.AlterField(
model_name='portfolio',
name='about',
field=models.TextField(blank=True, help_text='Tell us a bit about yourself', max_length=1500, verbose_name='Use this space to tell us about yourself'),
),
migrations.AlterField(
model_name='portfolio',
name='academic_qualification',
field=models.CharField(help_text='e.g. MSc Sustainable Energy Technologies', max_length=30, verbose_name='Your highest academic qualification'),
),
migrations.AlterField(
model_name='portfolio',
name='fav_language',
field=models.CharField(blank=True, help_text='This can be a language or framework', max_length=50, null=True, verbose_name='Whats your favourite programming language?'),
),
]
Loading