Skip to content

Commit

Permalink
Merge pull request #251 from gm3dmo/provost2
Browse files Browse the repository at this point in the history
Adding provost menu
  • Loading branch information
gm3dmo authored Nov 10, 2024
2 parents 3749d05 + 4a0ffc7 commit e905e19
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 5 deletions.
23 changes: 23 additions & 0 deletions cmp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from .models import Company
from .models import Decoration
from .models import Acknowledgement
from .models import ProvostAppointment


class CustomUserCreationForm(UserCreationForm):
Expand Down Expand Up @@ -79,4 +80,26 @@ class Meta:
fields = "__all__"


class ProvostOfficerForm(forms.ModelForm):
class Meta:
model = Soldier
fields = ['id', 'surname', 'initials', 'army_number', 'rank', 'notes']

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['rank'].queryset = Rank.objects.filter(rank_class="OF").order_by('name')

def save(self, commit=True):
soldier = super().save(commit=False)
soldier.provost_officer = True # Set provost_officer to True
print(soldier)
if commit:
soldier.save()
return soldier

class ProvostAppointmentForm(forms.ModelForm):
class Meta:
model = ProvostAppointment
fields = ['soldier', 'rank', 'date', 'notes']


1 change: 1 addition & 0 deletions cmp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class Soldier(models.Model):
initials = models.CharField(max_length=255, unique=False, default="", blank=True)
army_number = models.CharField(max_length=255, unique=False, default="", blank=True)
rank = models.ForeignKey("Rank", on_delete=models.CASCADE, related_name="ranks")
provost_officer = models.BooleanField(default=False)
notes = models.TextField(unique=False, default="", blank=True)

def __str__(self):
Expand Down
3 changes: 3 additions & 0 deletions cmp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@
path("mgmt/acknowledgements/edit/<int:acknowledgement_id>", views.edit_acknowledgements, name="edit-acknowledgements"),
path('mgmt/acknowledgements/search/', views.search_acknowledgements, name='search-acknowledgements'),

# Provost Officers
path('mgmt/create-provost-officer/', views.create_provost_officer, name='create-provost-officer'),

# Soldiers
path('soldiers/', views.soldiers, name='soldiers'),

Expand Down
18 changes: 14 additions & 4 deletions cmp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
from .models import SoldierImprisonment

from .forms import editSoldierForm, editSoldierDeathForm
#from .forms import ProvostOfficerForm, ProvostAppointmentForm
from .forms import ProvostOfficerForm, ProvostAppointmentForm

import folium
from django.views.generic import TemplateView
Expand Down Expand Up @@ -654,16 +654,26 @@ def index(request):
return render(request, 'cmp/soldier-results.html', context)


from django.shortcuts import render, redirect
from .forms import ProvostOfficerForm, ProvostAppointmentForm

def create_provost_officer(request):
if request.method == 'POST':
officer_form = ProvostOfficerForm(request.POST)
appointment_form = ProvostAppointmentForm(request.POST)
if officer_form.is_valid() and appointment_form.is_valid():
soldier = officer_form.save()
soldier = officer_form.save(commit=False)
print(f"woo{soldier}")
soldier.provost_officer = True # Set provost_officer to True
soldier.save() # Save the Soldier instance
appointment = appointment_form.save(commit=False)
appointment.soldier = soldier
appointment.save()
appointment.soldier = soldier # Set the soldier field
appointment.save() # Save the ProvostAppointment instance
return redirect('success_url') # Replace with your success URL
else:
# Print form errors to the console for debugging
print(officer_form.errors)
print(appointment_form.errors)
else:
officer_form = ProvostOfficerForm()
appointment_form = ProvostAppointmentForm()
Expand Down
2 changes: 1 addition & 1 deletion pyinfra/configure-caddy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Define your Caddyfile configuration
caddyfile_config = '''
cmp.oxenfor.de {
www.corpsofmilitarypolice.org, corpsofmilitarypolice.org {
root * /usr/share/caddy
file_server
reverse_proxy 127.0.0.1:8000
Expand Down
38 changes: 38 additions & 0 deletions templates/cmp/create-provost-officer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{% extends "base.html" %}
{% load static crispy_forms_tags %}
{% block title %}Provost Officer{% endblock %}
{% block content %}

<div class="center-content">

<h1>Create Provost Officer</h1>
<form method="POST">
{% csrf_token %}
{{ form.management_form }}
{{ form.errors }}
{{ officer_form | crispy }}
<button type="submit" class="btn btn-primary">SAVE</button>
</form>
{% if officer_form.errors %}
<div class="form-errors">
<h2>Officer Form Errors:</h2>
<ul>
{% for field, errors in officer_form.errors.items %}
<li>{{ field }}: {{ errors }}</li>
{% endfor %}
</ul>
</div>
{% endif %}
{% if appointment_form.errors %}
<div class="form-errors">
<h2>Appointment Form Errors:</h2>
<ul>
{% for field, errors in appointment_form.errors.items %}
<li>{{ field }}: {{ errors }}</li>
{% endfor %}
</ul>
</div>
{% endif %}

<div>
{% endblock %}
1 change: 1 addition & 0 deletions templates/cmp/mgmt-index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ <h3>Management Index</h3>
<li><a href="/mgmt/ranks/search/">Ranks</a></li>
<li><a href="/mgmt/prisoner-of-war-camps/search/">Prisoner of War Camps</a></li>
<li><a href="/mgmt/acknowledgements/search/">Acknowledgements</a></li>
<li><a href="/mgmt/create-provost-officer/">Create Provost Officer Record</a></li>
</ul>
{% endblock %}
</div>

0 comments on commit e905e19

Please sign in to comment.