Skip to content

Commit

Permalink
Refactor team member fields in ImpulseUser model and forms
Browse files Browse the repository at this point in the history
This commit refactors the member fields in the ImpulseUser model and forms into Team model. The member fields have been renamed and moved to the Team model.This change also updates the corresponding templates to reflect the new field names.
  • Loading branch information
Vignaraj-pai committed Dec 31, 2023
1 parent 6e5a6cd commit f2502ee
Show file tree
Hide file tree
Showing 7 changed files with 259 additions and 162 deletions.
18 changes: 9 additions & 9 deletions corpus/impulse/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ class Meta:

class Member2Form(CorpusModelForm):
class Meta:
model = ImpulseUser
model = Team
fields = [
"member2_name",
"member2_email",
"member2_from_nitk",
"member2_college_name",
"member2_roll_no",
"member2_phone",
"member2_ieee_member",
"member2_ieee_membership_no",
"member_name",
"member_email",
"member_from_nitk",
"member_college_name",
"member_roll_no",
"member_phone",
"member_ieee_member",
"member_ieee_membership_no",
]

class PaymentProofForm(CorpusModelForm):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Generated by Django 4.2.7 on 2023-12-31 05:58

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('impulse', '0001_initial'),
]

operations = [
migrations.RemoveField(
model_name='impulseuser',
name='is_member2',
),
migrations.RemoveField(
model_name='impulseuser',
name='member2_college_name',
),
migrations.RemoveField(
model_name='impulseuser',
name='member2_email',
),
migrations.RemoveField(
model_name='impulseuser',
name='member2_from_nitk',
),
migrations.RemoveField(
model_name='impulseuser',
name='member2_ieee_member',
),
migrations.RemoveField(
model_name='impulseuser',
name='member2_ieee_membership_no',
),
migrations.RemoveField(
model_name='impulseuser',
name='member2_name',
),
migrations.RemoveField(
model_name='impulseuser',
name='member2_phone',
),
migrations.RemoveField(
model_name='impulseuser',
name='member2_roll_no',
),
migrations.AddField(
model_name='team',
name='is_member',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='team',
name='member_college_name',
field=models.CharField(default='National Institute of Technology Karnataka', max_length=200),
),
migrations.AddField(
model_name='team',
name='member_email',
field=models.EmailField(blank=True, max_length=254, null=True),
),
migrations.AddField(
model_name='team',
name='member_from_nitk',
field=models.BooleanField(default=True),
),
migrations.AddField(
model_name='team',
name='member_ieee_member',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='team',
name='member_ieee_membership_no',
field=models.BigIntegerField(blank=True, null=True),
),
migrations.AddField(
model_name='team',
name='member_name',
field=models.CharField(blank=True, max_length=200, null=True),
),
migrations.AddField(
model_name='team',
name='member_phone',
field=models.CharField(blank=True, max_length=13, null=True),
),
migrations.AddField(
model_name='team',
name='member_roll_no',
field=models.CharField(blank=True, max_length=8, null=True),
),
migrations.AlterField(
model_name='impulseuser',
name='roll_no',
field=models.CharField(blank=True, max_length=8, null=True),
),
]
24 changes: 13 additions & 11 deletions corpus/impulse/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,6 @@ class ImpulseUser(models.Model):
team = models.ForeignKey(
"Team", on_delete=models.CASCADE, related_name="team", blank=True, null=True
)
is_member2 = models.BooleanField(default=False)
member2_name = models.CharField(max_length=200, blank=True, null=True)
member2_email = models.EmailField(blank=True, null=True)
member2_from_nitk = models.BooleanField(default=True)
member2_college_name = models.CharField(
max_length=200, default="National Institute of Technology Karnataka"
)
member2_roll_no = models.CharField(max_length=8, blank=True, null=True)
member2_phone = models.CharField(max_length=13, blank=True, null=True)
member2_ieee_member = models.BooleanField(default=False)
member2_ieee_membership_no = models.BigIntegerField(blank=True, null=True)

def __str__(self):
return self.user.email
Expand All @@ -34,6 +23,19 @@ class Team(models.Model):
team_leader = models.ForeignKey(
ImpulseUser, on_delete=models.CASCADE, related_name="leader"
)

is_member = models.BooleanField(default=False)
member_name = models.CharField(max_length=200, blank=True, null=True)
member_email = models.EmailField(blank=True, null=True)
member_from_nitk = models.BooleanField(default=True)
member_college_name = models.CharField(
max_length=200, default="National Institute of Technology Karnataka"
)
member_roll_no = models.CharField(max_length=8, blank=True, null=True)
member_phone = models.CharField(max_length=13, blank=True, null=True)
member_ieee_member = models.BooleanField(default=False)
member_ieee_membership_no = models.BigIntegerField(blank=True, null=True)

payment_status = models.CharField(
max_length=1, choices=PAYMENT_STATUS, blank=False, null=False, default="U"
)
Expand Down
100 changes: 44 additions & 56 deletions corpus/impulse/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,12 @@
from impulse.forms import Member2Form
from impulse.forms import PaymentProofForm

# from impulse.forms import TeamCreationForm



from corpus.decorators import ensure_group_membership
from corpus.decorators import module_enabled

# Create your views here.
def home(request):
# check group_membership, if admin redirect to admin page
args = {}
# Checking if user is Impulse_admin group member
if request.user.groups.filter(name="impulse_admin").exists():
args = {"admin": True}
config = ModuleConfiguration.objects.get(module_name="impulse").module_config
Expand Down Expand Up @@ -66,32 +61,35 @@ def index(request):
messages.error(request, "Please register for Impulse first!")
return redirect("impulse_register")

# Check if already part of team
if impulse_user.team is not None:
args["in_team"] = True

args["team_creation_form"] = TeamCreationForm(instance=impulse_user.team)

team = impulse_user.team

args["is_member2"] = impulse_user.is_member2
if impulse_user.is_member2:
args['team_count'] = 2
else:
args['team_count'] = 1

args["is_member2"] = team.is_member
args["team_count"] = 1 + team.is_member
args["member"] = impulse_user

args["team"] = team
args["payment_status"] = team.payment_status

if not impulse_user.is_member2:
pay_status = "Not Registered"

if args["payment_status"] == "E" or args["payment_status"] == "P":
pay_status = "Complete"
elif args["payment_status"] == "U":
pay_status = "Incomplete"

if not team.is_member:
args["member2_form"] = Member2Form()
else:
args["member2_form"] = Member2Form(instance=impulse_user)
args["member2_form"] = Member2Form(instance=impulse_user.team)
else:
args["in_team"] = False
args["team_creation_form"] = TeamCreationForm()


config = ModuleConfiguration.objects.get(module_name="impulse").module_config

reg_start_datetime, reg_end_datetime = (
Expand All @@ -110,22 +108,17 @@ def index(request):
args["payment_proof_form"] = PaymentProofForm()

args["registration_active"] = registration_active
if args["in_team"]:
team = impulse_user.team
if team.payment_status in ["P", "E"]:
args["payment_status"] = "Complete"
else:
args["payment_status"] = "Incomplete"

if args["payment_status"] == "Complete":
# filder announcements based on payment status, get all announcements marked as type A or P
announcements = Announcement.objects.filter(announcement_type__in=["A", "P"])
elif args["payment_status"] == "Incomplete":
announcements = Announcement.objects.filter(announcement_type__in=["A", "U"])
else:
try :
if pay_status == "Complete":
announcements = Announcement.objects.filter(announcement_type__in=["A", "P"])
elif pay_status == "Incomplete":
announcements = Announcement.objects.filter(announcement_type__in=["A", "U"])
else:
announcements = Announcement.objects.filter(announcement_type__in=["A", "N"])
except:
announcements = Announcement.objects.filter(announcement_type__in=["A", "N"])

# sort announcements by date created

announcements = announcements.order_by("-date_created")

args["announcements"] = announcements
Expand Down Expand Up @@ -165,14 +158,10 @@ def register(request):

if request.method == "POST":
form = ImpulseForm(request.POST)
print("Form received")
if form.is_valid():
print("Form is valid")
impulse_user = form.save(commit=False)
print("Form saved")
impulse_user.user = request.user
impulse_user.save()
print("Impulse user saved")
messages.success(request, "Successfully registered for Impulse!")
return redirect("impulse_index")
else:
Expand All @@ -182,7 +171,6 @@ def register(request):
form = ImpulseForm()

args = {"form": form}
print("Creating registration form")
return render(request, "impulse/register.html", args)


Expand All @@ -194,7 +182,6 @@ def create_team(request):
impulse_user = ImpulseUser.objects.get(user=request.user)
if impulse_user.team is not None:
if form.is_valid():
# update team name
team = impulse_user.team
team.team_name = form.cleaned_data["team_name"]
team.save()
Expand Down Expand Up @@ -228,23 +215,28 @@ def add_member(request):
updation = False
if form.is_valid():
impulse_user = ImpulseUser.objects.get(user=request.user)
updation = impulse_user.is_member2
# Save the member2 details in the form into the impulse_user
impulse_user.is_member2 = True
impulse_user.member2_name = form.cleaned_data["member2_name"]
impulse_user.member2_email = form.cleaned_data["member2_email"]
impulse_user.member2_from_nitk = form.cleaned_data["member2_from_nitk"]
impulse_user.member2_college_name = form.cleaned_data["member2_college_name"]
impulse_user.member2_roll_no = form.cleaned_data["member2_roll_no"]
impulse_user.member2_phone = form.cleaned_data["member2_phone"]
impulse_user.member2_ieee_member = form.cleaned_data["member2_ieee_member"]
impulse_user.member2_ieee_membership_no = form.cleaned_data["member2_ieee_membership_no"]
impulse_user.save()

if impulse_user.member2_from_nitk or impulse_user.member2_ieee_member:
team = impulse_user.team
team = impulse_user.team
if impulse_user.team is None:
messages.error(request, "Please create a team first!")
return redirect("impulse_index")
if team.is_member:
updation = True
else:
team.is_member = True

team.member_name = form.cleaned_data["member_name"]
team.member_email = form.cleaned_data["member_email"]
team.member_from_nitk = form.cleaned_data["member_from_nitk"]
team.member_college_name = form.cleaned_data["member_college_name"]
team.member_roll_no = form.cleaned_data["member_roll_no"]
team.member_phone = form.cleaned_data["member_phone"]
team.member_ieee_member = form.cleaned_data["member_ieee_member"]
team.member_ieee_membership_no = form.cleaned_data["member_ieee_membership_no"]

if team.member_from_nitk or team.member_ieee_member:
team.payment_status = "E"
team.save()

team.save()

if updation:
messages.success(request, "Successfully updated member details!")
Expand Down Expand Up @@ -306,10 +298,6 @@ def team_page(request, pk):
args = {}
team = Team.objects.get(pk=pk)
args["team"] = team
members = ImpulseUser.objects.filter(team=team)
for member in members:
args["member"] = member

return render(request, "impulse/admin/team_page.html", args)

@login_required
Expand Down
1 change: 1 addition & 0 deletions corpus/templates/impulse/admin/announcements.html
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,6 @@ <h2 class="text-center">Current Announcements</h2>
</tbody>
</table>
</div>
<a href="{% url 'impulse_admin' %}" class="btn btn-secondary text-black font-bold no-underline">Back</a>
</div>
{% endblock %}
23 changes: 13 additions & 10 deletions corpus/templates/impulse/admin/team_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ <h3>Members</h3>
<tr>
<th></th>
<th>Name</th>
<th>Email</th>
<th>From NITK?</th>
<th>College Name</th>
<th>IEEE Member?</th>
Expand All @@ -27,19 +28,21 @@ <h3>Members</h3>
<tbody>
<tr>
<td>1</td>
<td>{{ member.user }}</td>
<td>{{ member.from_nitk|yesno:"Yes,No" }}</td>
<td>{{ member.college_name }}</td>
<td>{{ member.ieee_member|yesno:"Yes,No" }}</td>
<td>{{ member.ieee_membership_no }}</td>
<td>{{ team.team_leader.user }}</td>
<td>{{ team.team_leader.user.email }}</td>
<td>{{ team.team_leader.from_nitk|yesno:"Yes,No" }}</td>
<td>{{ team.team_leader.college_name }}</td>
<td>{{ team.team_leader.ieee_member|yesno:"Yes,No" }}</td>
<td>{{ team.team_leader.ieee_membership_no }}</td>
</tr>
<tr>
<td>2</td>
<td>{{ member.member2_name }}</td>
<td>{{ member.member2_from_nitk|yesno:"Yes,No" }}</td>
<td>{{ member.member2_college_name }}</td>
<td>{{ member.member2_ieee_member|yesno:"Yes,No" }}</td>
<td>{{ member.member2_ieee_membership_no }}</td>
<td>{{ team.member_name }}</td>
<td>{{ team.member_email }}</td>
<td>{{ team.member_from_nitk|yesno:"Yes,No" }}</td>
<td>{{ team.member_college_name }}</td>
<td>{{ team.member_ieee_member|yesno:"Yes,No" }}</td>
<td>{{ team.member_ieee_membership_no }}</td>
</tr>
</tbody>
</table>
Expand Down
Loading

0 comments on commit f2502ee

Please sign in to comment.