Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft-Responders2 #32

Merged
merged 2 commits into from
Jun 11, 2020
Merged
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
5 changes: 5 additions & 0 deletions src/goal3/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.media',
],
},
},
Expand Down Expand Up @@ -141,3 +142,7 @@
# https://docs.djangoproject.com/en/3.0/howto/static-files/

STATIC_URL = '/static/'

#Media files
MEDIA_ROOT= os.path.join(BASE_DIR, 'media/')
MEDIA_URL= "/media/"
14 changes: 7 additions & 7 deletions src/templates/incident_create.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,15 @@

<div class="container-fluid">
<div class="container">
<div>
{% for message in messages %}
<h3> {{message}}</h3>
{% endfor %}

</div>
<h1>Accident Form</h1>
<p>It is our collective responsibility to report an accident. By reporting accidents, relevant agencies monitor problems and identify their root causes. Reporting road accidents enable actions to be taken to reduce future ocurrences, and at LifeShield it takes less than 5 minutes to report an accident.</p>
<form action="{% url 'incident_create' %}"
<form enctype="multipart/form-data" method="POST" action="{% url 'incident_create' %}"
method="post">
{% csrf_token %}
{% bootstrap_form form %}
Expand All @@ -17,11 +23,5 @@ <h1>Accident Form</h1>
{% endbuttons %}
</form>

<div>
{% for message in messages %}
<h3> {{message}}</h3>
{% endfor %}

</div>
</div>
<div>
2 changes: 1 addition & 1 deletion src/usersapp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
class IncidentForm(ModelForm):
class Meta:
model = Incident
fields = ['accident_location', 'local_government_area', 'nearest_landmark', 'date_of_accident', 'time_of_accident', 'number_of_vehicles_involved', 'vehicle_type', 'if_other_vehicle_specify', 'vehicles_number_plates', 'vehicles_precrash_factors', 'road_geometry', 'road_type', 'driver_precrash_factors', 'collision_type', 'number_of_victims', 'number_of_injured', 'number_of_deaths', 'category_of_victims', 'victims_age_group', 'number_of_male_victims', 'number_of_female_victims', 'number_of_child_victims', 'victims_current_location', 'if_hospital_specify', 'if_other_location_specify', 'more_accident_info']
fields = ['your_category', 'if_other_category_specify', 'accident_location', 'local_government_area', 'address_or_nearest_landmark', 'date_of_accident', 'time_of_accident', 'number_of_vehicles_involved', 'vehicle_type', 'if_other_vehicle_specify', 'vehicles_number_plates', 'vehicles_precrash_factors', 'road_geometry', 'road_type', 'driver_precrash_factors', 'collision_type', 'number_of_victims', 'number_of_injured', 'number_of_deaths', 'category_of_victims', 'victims_age_group', 'number_of_male_victims', 'number_of_female_victims', 'number_of_child_victims', 'victims_current_location', 'if_hospital_specify', 'if_other_location_specify', 'more_accident_info', 'videofile']
widgets = {
'date_of_accident': DatePickerInput(), # default date-format %m/%d/%Y will be used
# 'end_date': DatePickerInput(format='%Y-%m-%d'), # specify date-frmat
Expand Down
29 changes: 29 additions & 0 deletions src/usersapp/migrations/0012_auto_20200609_0216.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 3.0.6 on 2020-06-09 01:16

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('usersapp', '0011_auto_20200607_1614'),
]

operations = [
migrations.AddField(
model_name='incident',
name='videofile',
field=models.FileField(blank=True, null=True, upload_to='videos/', verbose_name='upload a video or an image'),
),
migrations.AddField(
model_name='incident',
name='your_category',
field=models.CharField(choices=[('Victim', 'Accident victim'), ('Eye nitness', 'Eye witness'), ('Driver', 'Driver of a vehicle in the accident')], db_column='User category', default=0, max_length=30),
preserve_default=False,
),
migrations.AlterField(
model_name='incident',
name='collision_type',
field=models.CharField(choices=[('Mv/mv head on', 'Moving vehicles, head on'), ('Mv/mv rear end', 'Moving vehicles, rear end'), ('Mv/mv intersecting', 'Moving vehicles, intersecting'), ('Mv/mv overtake', 'Moving vehicles, overtake'), ('Mv/mv turn', 'Moving vehicles, turn'), ('Single mv hit object', 'Single moving vehicle, hit object'), ('Single mv run off', 'Single moving vehicle, run off'), ('Single mv falling off', 'Single moving vehicle, falling off'), ('Mv/pedestrian', 'Moving vehicle with pedestrian'), ('Mv/motorcyclist', 'Moving vehicle with motorcyclist'), ('Mv/bicyclist', 'Moving vehicle with bicyclist'), ('Other', 'Other')], max_length=70),
),
]
23 changes: 23 additions & 0 deletions src/usersapp/migrations/0013_auto_20200609_0349.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.0.6 on 2020-06-09 02:49

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('usersapp', '0012_auto_20200609_0216'),
]

operations = [
migrations.RemoveField(
model_name='incident',
name='nearest_landmark',
),
migrations.AddField(
model_name='incident',
name='address_or_nearest_landmark',
field=models.CharField(default=0, help_text='By landmark we mean somewhere notable such as bustop, market, hotel, hospital etc.', max_length=50, verbose_name='address and/or nearest landmark'),
preserve_default=False,
),
]
23 changes: 23 additions & 0 deletions src/usersapp/migrations/0014_auto_20200609_0454.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.0.6 on 2020-06-09 03:54

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('usersapp', '0013_auto_20200609_0349'),
]

operations = [
migrations.AddField(
model_name='incident',
name='if_other_category_specify',
field=models.CharField(blank=True, db_column='User other category', max_length=50, null=True),
),
migrations.AlterField(
model_name='incident',
name='your_category',
field=models.CharField(choices=[('Victim', 'Accident victim'), ('Eye nitness', 'Eye witness'), ('Driver', 'Driver of a vehicle in the accident'), ('Other', 'Other')], db_column='User category', max_length=30),
),
]
16 changes: 14 additions & 2 deletions src/usersapp/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@ class Incident(models.Model) :
('Other', 'Other')
]

USER_CATEGORY = [
('Victim', 'Accident victim'),
('Eye nitness', 'Eye witness'),
('Driver', 'Driver of a vehicle in the accident'),
('Other', 'Other')
]


COLLISION_CHOICES = [
('Mv/mv head on', 'Moving vehicles, head on'),
('Mv/mv rear end', 'Moving vehicles, rear end'),
Expand All @@ -147,10 +155,12 @@ class Incident(models.Model) :
('Mv/bicyclist', 'Moving vehicle with bicyclist'),
('Other', 'Other')
]


your_category=models.CharField(choices=USER_CATEGORY,max_length=30,null=False,blank=False, db_column='User category')
if_other_category_specify=models.CharField(max_length=50,null=True,blank=True, db_column='User other category')
accident_location=models.CharField(choices=USER_LOCATION,max_length=45,null=False,blank=False)
local_government_area=models.CharField(max_length=25,null=False,blank=False, db_column='LGA')
nearest_landmark=models.CharField(max_length=50,null=True,blank=True, help_text="By landmark we mean somewhere notable such as bustop, market, hotel, hospital etc.")
address_or_nearest_landmark=models.CharField(max_length=50,null=False,blank=False, help_text="By landmark we mean somewhere notable such as bustop, market, hotel, hospital etc.", verbose_name="address and/or nearest landmark")
date_of_accident=models.DateField(auto_now=False)
time_of_accident=models.TimeField(auto_now=False)
number_of_vehicles_involved=models.PositiveIntegerField(null=False,blank=False, db_column='vehicles involved', help_text="Number of vehicles can be zero or more.")
Expand All @@ -174,6 +184,8 @@ class Incident(models.Model) :
if_hospital_specify=models.CharField(max_length=50,null=True,blank=True, db_column='hospital location')
if_other_location_specify=models.CharField(max_length=50,null=True,blank=True, db_column='other location')
more_accident_info=models.TextField(blank=True,null=True)
videofile= models.FileField(upload_to='videos/', null=True, blank=True, verbose_name="upload a video or an image")

#calling objects used in responder and search_responses function from views.py
objects = models.Manager()

Expand Down
5 changes: 4 additions & 1 deletion src/usersapp/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@
#connecting incident_create to usersapp
from .views import home, incident_create, responder, search_responses

# helps with video upload
from django.conf import settings
from django.conf.urls.static import static

urlpatterns = [
path('', home, name='home'),
path('incident/create/', incident_create, name='incident_create'),
path('responder', responder, name='responder'),
path('search/responses/', search_responses, name='search_responses'),
]
]+ static(settings.MEDIA_URL, document_root= settings.MEDIA_ROOT)
8 changes: 6 additions & 2 deletions src/usersapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ def home (request):

def incident_create(request):
if request.method == 'POST':

# lastvideo= Incident.objects.last()

#videofile= lastvideo.videofile

#form = IncidentForm(request.POST)
userform = IncidentForm(request.POST)
userform = IncidentForm(request.POST, request.FILES)

#if form.is_valid():
if userform.is_valid():
Expand All @@ -31,14 +35,14 @@ def incident_create(request):
return redirect('incident_create')
else:
print('Unable to submit')
#messages.info(request, 'Unable to submit, some fields cannot be empty')

#form = IncidentForm()
userform = IncidentForm()

return render(request,
'incident_create.html',
{
#'videofile': videofile,
#'form': form
'form': userform
})
Expand Down