diff --git a/corpus/accounts/forms.py b/corpus/accounts/forms.py index 442a29a9..eb8193fe 100644 --- a/corpus/accounts/forms.py +++ b/corpus/accounts/forms.py @@ -5,6 +5,8 @@ from django.forms.widgets import ClearableFileInput from .models import ExecutiveMember +from .models import Faculty +from .models import Post from .models import User from corpus.forms import CorpusModelForm @@ -102,3 +104,20 @@ class Meta: "hide_github", "hide_linkedin", ] + + +class FacultyForm(CorpusModelForm): + class Meta: + model = Faculty + fields = [ + "linkedin", + "website", + ] + + +class PostForm(CorpusModelForm): + class Meta: + model = Post + fields = [ + "name", + ] diff --git a/corpus/accounts/models.py b/corpus/accounts/models.py index d955e3cb..e49e345a 100644 --- a/corpus/accounts/models.py +++ b/corpus/accounts/models.py @@ -204,7 +204,7 @@ class Meta: society = models.ForeignKey( Society, blank=True, null=True, on_delete=models.CASCADE ) - post = models.ForeignKey(Post, null=True, blank=True, on_delete=models.CASCADE) + post = models.OneToOneField(Post, null=True, blank=True, on_delete=models.CASCADE) website = models.URLField(max_length=200, null=True, blank=True) linkedin = models.URLField( blank=True, null=True, verbose_name="Linkedin Profile URL" diff --git a/corpus/accounts/urls.py b/corpus/accounts/urls.py index 670ad956..30eccc95 100644 --- a/corpus/accounts/urls.py +++ b/corpus/accounts/urls.py @@ -32,6 +32,6 @@ PasswordResetCompleteView.as_view(), name="password_reset_complete", ), - path("profile/", profile, name="accounts_profile"), - path("profile//edit", edit_profile, name="edit_profile"), + path("profile/", profile, name="accounts_profile"), + path("profile//edit", edit_profile, name="edit_profile"), ] diff --git a/corpus/accounts/views.py b/corpus/accounts/views.py index bd32592f..2483482a 100644 --- a/corpus/accounts/views.py +++ b/corpus/accounts/views.py @@ -4,6 +4,7 @@ from constants import MAX_IMAGE_SIZE from django.contrib import messages from django.contrib.auth import authenticate +from django.contrib.auth import get_user_model from django.contrib.auth import login from django.contrib.auth import logout from django.contrib.auth.decorators import login_required @@ -15,8 +16,13 @@ from .forms import CorpusCreationForm from .forms import CorpusLoginForm from .forms import ExecutiveMemberForm +from .forms import FacultyForm +from .forms import PostForm from .forms import UserForm from .models import ExecutiveMember +from .models import Faculty + +User = get_user_model() # Create your views here. @@ -90,18 +96,31 @@ def signout(request): return redirect("index") -def profile(request, roll_no): - exec_member = get_object_or_404(ExecutiveMember, roll_number=roll_no) - profile_user = exec_member.user +def profile(request, pk): + profile_user = get_object_or_404(User, pk=pk) - # Get Virtual Expo Reports - reports = Report.objects.filter(reportmember__member=exec_member) + try: + exec_member = ExecutiveMember.objects.get(user=profile_user) + faculty = None + except ExecutiveMember.DoesNotExist: + exec_member = None + try: + faculty = Faculty.objects.get(user=profile_user) + except Faculty.DoesNotExist: + faculty = None - # Get Blogs written by the Executive Member - blogs = Post.objects.filter(author=exec_member) + # Get Virtual Expo Reports + if exec_member: + reports = Report.objects.filter(reportmember__member=exec_member) + # Get Blogs written by the Executive Member + blogs = Post.objects.filter(author=exec_member) + else: + reports = None + blogs = None args = { "exec_member": exec_member, + "faculty": faculty, "profile_user": profile_user, "curr_user": request.user, "reports": reports, @@ -112,30 +131,81 @@ def profile(request, roll_no): @login_required -def edit_profile(request, roll_no): - user = request.user # Get the currently logged-in user +def edit_profile(request, pk): + user = get_object_or_404(User, pk=pk) # Get the user explicitly by ID + + # Authorization check: Ensure logged-in user can only edit their own profile + if request.user != user: + messages.warning(request, "You are not authorized to edit this profile.") + return redirect("index") # Check if the user has an associated ExecutiveMember record try: - executive_member = ExecutiveMember.objects.get(roll_number=roll_no, user=user) + executive_member = ExecutiveMember.objects.get(user=user) + faculty = None + post = None except ExecutiveMember.DoesNotExist: - messages.warning(request, "You are not authorized to edit this profile.") - return redirect("index") + executive_member = None + try: + faculty = Faculty.objects.get(user=user) + post = faculty.post + except Faculty.DoesNotExist: + faculty = None + post = None if request.method == "POST": user_form = UserForm(request.POST, request.FILES, instance=user) - executive_member_form = ExecutiveMemberForm( - request.POST, instance=executive_member - ) + if executive_member: + executive_member_form = ExecutiveMemberForm( + request.POST, instance=executive_member + ) + faculty_form = None + post_form = None + if user_form.is_valid() and executive_member_form.is_valid(): + user_form.save() + executive_member_form.save() + return redirect("accounts_profile", pk=pk) + + else: + if faculty and post: + faculty_form = FacultyForm(request.POST, instance=faculty) + post_form = PostForm(request.POST, instance=post) + executive_member_form = None + if ( + user_form.is_valid() + and faculty_form.is_valid() + and post_form.is_valid() + ): + user_form.save() + faculty_form.save() + post_form.save() + return redirect("accounts_profile", pk=pk) + if not faculty_form.is_valid(): + return render( + request, + "accounts/edit_profile.html", + {"form": faculty_form, "errors": faculty_form.errors}, + ) - if user_form.is_valid() and executive_member_form.is_valid(): - user_form.save() - executive_member_form.save() - return redirect("accounts_profile", roll_no=roll_no) + else: + if user_form.is_valid(): + user_form.save() + return redirect("accounts_profile", pk=pk) else: user_form = UserForm(instance=user) - executive_member_form = ExecutiveMemberForm(instance=executive_member) + if executive_member: + executive_member_form = ExecutiveMemberForm(instance=executive_member) + faculty_form = None + post_form = None + else: + executive_member_form = None + if faculty: + faculty_form = FacultyForm(instance=faculty) + post_form = PostForm(instance=faculty.post) + else: + faculty_form = None + post_form = None return render( request, @@ -143,6 +213,8 @@ def edit_profile(request, roll_no): { "user_form": user_form, "executive_member_form": executive_member_form, + "faculty_form": faculty_form, + "post_form": post_form, "exec_member": executive_member, "max_image_size": MAX_IMAGE_SIZE, }, diff --git a/corpus/corpus/settings.py b/corpus/corpus/settings.py index a61b776e..38a37010 100644 --- a/corpus/corpus/settings.py +++ b/corpus/corpus/settings.py @@ -67,6 +67,7 @@ "farewell.apps.FarewellConfig", "virtual_expo.apps.VirtualExpoConfig", "blog", + 'django_extensions', "smp.apps.SmpConfig", "codeRed.apps.CoderedConfig", "chimera.apps.ChimeraConfig", diff --git a/corpus/pages/views.py b/corpus/pages/views.py index 260761df..a97d7c20 100644 --- a/corpus/pages/views.py +++ b/corpus/pages/views.py @@ -191,6 +191,8 @@ def team(request): "sac_core": sac_core, "faculty": faculty, } + + print(context) return render(request, "pages/team.html", context) diff --git a/corpus/requirements.txt b/corpus/requirements.txt index 64167717..2c30f688 100644 --- a/corpus/requirements.txt +++ b/corpus/requirements.txt @@ -25,6 +25,7 @@ typing_extensions==4.8.0 urllib3==2.2.1 virtualenv==20.25.0 wheel==0.41.2 +django-extensions celery dotenv redis diff --git a/corpus/templates/accounts/edit_profile.html b/corpus/templates/accounts/edit_profile.html index c8b906c6..dd3d3209 100644 --- a/corpus/templates/accounts/edit_profile.html +++ b/corpus/templates/accounts/edit_profile.html @@ -1,127 +1,189 @@ {% extends 'base.html' %} {% block title %} - Edit Profile | {{ user }} +Edit Profile | {{ user }} {% endblock %} {% block content %} -
-

Edit Profile

- -
- {% csrf_token %} - - -
-
-

Personal Information

-
- - -
- - - -
- {% if user.profile_pic %} - {{ user }} - {% else %} - {{ user }} - {% endif %} -
- - - - - +{% if errors %} +
{{ errors }}
+{% endif %} +
+

Edit Profile

+ + + {% csrf_token %} + + +
+
+

Personal Information

+
+ + +
+ + + +
+ {% if user.profile_pic %} + {{ user }} + {% else %} + {{ user }} + {% endif %}
- -
- {% for field in user_form %} -
- - {{ field }} - {% if field.errors %} -
- {% for error in field.errors %} - {{ error }} - {% endfor %} -
- {% endif %} - {% if field.help_text %} - - {% endif %} -
- {% endfor %} -
+ + +
-
-
- {% if executive_member_form %} - -
-
-

NITK Details

+
+ {% for field in user_form %}
- {{ executive_member_form.edu_email }} -
-
- - {{ executive_member_form.roll_number }} -
-
- - {{ executive_member_form.reg_number }} -
-
+ {{ field }} + {% if field.errors %} +
+ {% for error in field.errors %} + {{ error }} + {% endfor %} +
+ {% endif %} + {% if field.help_text %} - {{ executive_member_form.minor_branch }} + {% endif %}
+ {% endfor %}
+
+
+ + {% if executive_member_form %} + +
+
+

NITK Details

+
+
+ + {{ executive_member_form.edu_email }} +
+
+ + {{ executive_member_form.roll_number }} +
+
+ + {{ executive_member_form.reg_number }} +
+
+ + {{ executive_member_form.minor_branch }} +
+
+
+
+ + +
+
+

IEEE Details

+
+
+ + {{ executive_member_form.ieee_number }} +
+
+ + {{ executive_member_form.ieee_email }} +
+
+
+
+ + +
+
+

Socials

+
+ +
+ + {{ executive_member_form.linkedin }} + +
+ + +
+ + {{ executive_member_form.github }} + +
+
+
+
+ + {% else %} + {% if faculty_form %} - + {% if post_form %} +
-

IEEE Details

+

Post Details

- {{ executive_member_form.ieee_number }} + {{ post_form.name }}
-
- - {{ executive_member_form.ieee_email }} -
-
+ {% endif %}
@@ -133,145 +195,135 @@

Socials

- {{ executive_member_form.linkedin }} - + {{ faculty_form.linkedin }}
- +
- {{ executive_member_form.github }} - + {{ faculty_form.website }}
- {% endif %} - - - - -
+ {% if exec_member %}
IEEE Membership Information
@@ -61,7 +69,33 @@

{{ exec_member.sig }}

+ {% else %} + {% if faculty %} +
+
IEEE Faculty Information
+
+
+
Post
+
{{ faculty.post.name }}
+
+
+
SIG
+ {% if faculty.sig %} +
{{ faculty.sig }}
+ {% endif %} +
+
+
Society
+ {% if faculty.society %} +
{{ faculty.society }}
+ {% endif %} +
+
+
+ {% endif %} + {% endif %} + {% if exec_member %}
Reports Published
@@ -105,10 +139,12 @@

{{ blog.title }}

{% endif %}
+ {% endif %}
Links
+ {% if exec_member %}
GitHub
@@ -140,6 +176,33 @@

{{ blog.title }}

{% endif %}
+ {% else %} + {% if faculty %} +
+ +
Website
+
+ {% if faculty.website %} + Website + {% else %} + None + {% endif %} +
+
+ +
+ +
LinkedIn
+
+ {% if faculty.linkedin %} + LinkedIn Profile + {% else %} + None + {% endif %} +
+
+ {% endif %} + {% endif %}
diff --git a/corpus/templates/blog/full_post.html b/corpus/templates/blog/full_post.html index a199b03c..287ed05a 100644 --- a/corpus/templates/blog/full_post.html +++ b/corpus/templates/blog/full_post.html @@ -16,31 +16,27 @@ {% endif %} {% load markdown_extras %} -
+
{{individual_post.title}}
{% for tag in individual_post.blog_tag.all %} -
{{ tag.tag_name }}
+
{{ tag.tag_name }}
{% endfor %}
-
published on {{individual_post.published_date}}
+ -by + {{individual_post.author}}
-
+
published on {{individual_post.published_date}}
+
+
{{individual_post.text|render_function}}
-
- {% if not preview %} - - {% else %} - Back - {% endif %} +
+ {% endblock %} diff --git a/corpus/templates/components/navbar_profile_dropdown.html b/corpus/templates/components/navbar_profile_dropdown.html index af164492..294cfa74 100644 --- a/corpus/templates/components/navbar_profile_dropdown.html +++ b/corpus/templates/components/navbar_profile_dropdown.html @@ -3,8 +3,6 @@
  • Welcome, {{ user.first_name }} {{ user.last_name }}!
  • - {% if user.executivemember %} -
  • Profile
  • - {% endif %} +
  • Profile
  • Logout
  • - + \ No newline at end of file diff --git a/corpus/templates/pages/core_box.html b/corpus/templates/pages/core_box.html index 8b0edd96..59f7f872 100644 --- a/corpus/templates/pages/core_box.html +++ b/corpus/templates/pages/core_box.html @@ -1,5 +1,5 @@ {% load static %} - + - + \ No newline at end of file diff --git a/corpus/templates/pages/faculty_box.html b/corpus/templates/pages/faculty_box.html index e2530831..b7fab934 100644 --- a/corpus/templates/pages/faculty_box.html +++ b/corpus/templates/pages/faculty_box.html @@ -1,45 +1,47 @@ {% load static %} -
    -
    -
    - photo -
    -
    -

    {{ faculty.user }}

    -

    {{ faculty.post.name }}

    -
    - {% if faculty.linkedin %} - - - + +
    +
    +
    + photo +
    +
    +

    {{ faculty.user }}

    +

    {{ faculty.post.name }}

    +
    + {% if faculty.linkedin %} + + + + + + {% endif %} + {% if faculty.website %} + + + + + - {% endif %} - {% if faculty.website %} - - - - - - - - {% endif %} + {% endif %} +
    -
    \ No newline at end of file + diff --git a/corpus/templates/pages/member_box.html b/corpus/templates/pages/member_box.html index c0207413..6fa2b0eb 100644 --- a/corpus/templates/pages/member_box.html +++ b/corpus/templates/pages/member_box.html @@ -1,5 +1,5 @@ {% load static %} - +
    - + \ No newline at end of file diff --git a/corpus/templates/smp/program.html b/corpus/templates/smp/program.html index b3dabdd3..4bddb25c 100644 --- a/corpus/templates/smp/program.html +++ b/corpus/templates/smp/program.html @@ -1,156 +1,167 @@ {% extends "smp/base.html" %} {% block title %} - {{ program.title }} - {{ block.super }} +{{ program.title }} +{{ block.super }} {% endblock %} {% block content %} - {% include "smp/header.html" with year=program.year %} +{% include "smp/header.html" with year=program.year %} - {% if preview %} -
    - Preview Mode - This is a draft version of the program +{% if preview %} +
    + Preview Mode - This is a draft version of the program +
    +{% endif %} + +
    +
    +
    +

    {{ program.title }}

    +
    + {% for sig in program.sigs %} + + {{ sig }} + + {% endfor %} +
    - {% endif %} -
    -
    -
    -

    {{ program.title }}

    -
    - {% for sig in program.sigs %} - - {{ sig }} - - {% endfor %} +
    + + {% if program.abstract %} + - -
    - - {% if program.abstract %} - - {% endif %} - {% if program.abstract %} - - {% endif %} - -
    - {{ program.description | safe }} + {% endif %} + {% if program.abstract %} + + {% endif %} - +
    + {{ program.description | safe }} +
    - -
    -

    Program Information

    + + + +
    +

    Program Information

    -
    - - +
    + + - + - - + + - +
    -
    +
    +
    -
    - {% if not preview %} -
    -

    Explore More Programs

    - - View All {{ program.year }} Programs - -
    - {% else %} - - {% endif %} +
    + {% if not preview %} + + {% else %} + + {% endif %}
    -{% endblock %} +
    +{% endblock %} \ No newline at end of file diff --git a/corpus/templates/virtual_expo/report.html b/corpus/templates/virtual_expo/report.html index 6e8c9ed5..f4e47c89 100644 --- a/corpus/templates/virtual_expo/report.html +++ b/corpus/templates/virtual_expo/report.html @@ -1,147 +1,156 @@ {% extends "virtual_expo/base.html" %} {% block title %} - {{ report.title }} - {{ block.super }} +{{ report.title }} +{{ block.super }} {% endblock %} {% block content %} - {% include "virtual_expo/header.html" with year=report.year %} +{% include "virtual_expo/header.html" with year=report.year %} - {% if preview %} -
    - Preview Mode - This is a draft version of the report +{% if preview %} +
    + Preview Mode - This is a draft version of the report +
    +{% endif %} + +
    +
    +
    +

    {{ report.title }}

    +
    + + {{ report.report_type }} + + {% for sig in report.sigs %} + + {{ sig }} + + {% endfor %} +
    - {% endif %} -
    -
    -
    -

    {{ report.title }}

    -
    - - {{ report.report_type }} - - {% for sig in report.sigs %} - - {{ sig }} - - {% endfor %} +
    + + {% if report.abstract %} + - -
    - - {% if report.abstract %} - - {% endif %} - {% if report.abstract %} - - {% endif %} - -
    - {{ report.content | safe }} + {% endif %} + {% if report.abstract %} + + {% endif %} - -
    -

    Report Information

    - -
    - - +
    + {{ report.content | safe }} +
    - + +
    +

    Report Information

    + +
    + + - - -
    +
    +
    -
    - {% if not preview %} -
    -

    Explore More Projects

    - - View All {{ report.year }} Projects - -
    - {% else %} - - {% endif %} +
    + {% if not preview %} +
    +

    Explore More Projects

    + + View All {{ report.year }} Projects + +
    + {% else %} + + {% endif %}
    +
    {% endblock %} \ No newline at end of file