Skip to content

Commit

Permalink
Added ability to edit location information along with functionality t…
Browse files Browse the repository at this point in the history
…o search for technicians by location. Closes #18.
  • Loading branch information
VioletInferno committed Apr 27, 2020
1 parent 76d9766 commit 55099b2
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 54 deletions.
66 changes: 66 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Django #
*.log
*.pot
*.pyc
__pycache__
db.sqlite3
media

# Backup files #
*.bak

# Python #
*.py[cod]
*$py.class

# Distribution / packaging
.Python build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
.pytest_cache/
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Visual Studio Code #
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history
Binary file modified db.sqlite3
Binary file not shown.
69 changes: 23 additions & 46 deletions myapp/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,57 +38,11 @@ class IssueForm(forms.Form):
required=True
)

"""
date_created = forms.CharField(
widget = forms.TextInput(
attrs={'class': 'form-control'}
),
label='Date Created',
required=True,
)
"""

"""
assigned_user = forms.CharField(
widget = forms.TextInput(
attrs={'class': 'form-control'}
),
label='Assigned User',
required=False,
max_length=50
)
"""

# this field will eventually be removed as the affected user will
# be automatically set to the user who is logged in
"""
affected_user = forms.CharField(
widget = forms.TextInput(
attrs={'class': 'form-control'}
),
label='Affected User',
required=True,
max_length=50,
)
"""
# it's now been removed :D

"""
is_solved = forms.BooleanField(
widget = forms.CheckboxInput(
attrs={'class':'form-check'}
),
label='Is this issue solved?'
)
"""

def save(self, this_user):
issues_instance = models.Issue_Model()
issues_instance.title = self.cleaned_data["title"]
issues_instance.description = self.cleaned_data["description"]
issues_instance.issue_type = self.cleaned_data["issue_type"]
#issues_instance.date_created = self.cleaned_data["date_created"]
#issues_instance.assigned_user = self.cleaned_data["assigned_user"]
issues_instance.affected_user = this_user
issues_instance.is_solved = 0
issues_instance.save()
Expand Down Expand Up @@ -171,6 +125,15 @@ class ProfileForm(forms.Form):
max_length=720
)

location = forms.CharField(
widget = forms.TextInput(
attrs={'class': 'form-control'}
),
label='Location',
required=False,
max_length=100
)

def save(self,id):
this_user = User.objects.get(id__exact=id)
if self.cleaned_data["email"] and self.cleaned_data["email"] != this_user.email:
Expand All @@ -179,6 +142,8 @@ def save(self,id):
this_user.username = self.cleaned_data["user_name"]
if self.cleaned_data['bio']:
this_user.profile.bio = self.cleaned_data["bio"]
if self.cleaned_data['location']:
this_user.profile.location = self.cleaned_data["location"]
this_user.save()
return this_user

Expand Down Expand Up @@ -230,3 +195,15 @@ class ProfileFilter(forms.Form):
required=False,
max_length=100
)

location = forms.CharField(
widget = forms.TextInput(
attrs={
'class': 'form-control font-weight-normal',
'id': 'issue_type'
}
),
label='Filter by Location',
required=False,
max_length=100
)
4 changes: 2 additions & 2 deletions myapp/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
{% if user.is_authenticated %}
<li class="nav-item"><a class="nav-link" href="/submit.html">Submit Request</a></li>
<li class="nav-item"><a class="nav-link" href="/viewmysubmittedissues.html">View my Submitted Requests</a></li>
<li class="nav-item"><a class="nav-link" href="/viewtechnicians.html">Find a Technician</a></li>
{% if is_technician %}
<li class="nav-item"><a class="nav-link" href="/viewissues.html">View Requests</a></li>
<li class="nav-item"><a class="nav-link" href="/viewissues.html">View All Requests</a></li>
<li class="nav-item"><a class="nav-link" href="/viewmyissues.html">View Assignments</a></li>
{% endif %}
<li class="nav-item"><a class="nav-link" href="/viewtechnicians.html">Find a Technician</a></li>
{% endif %}
<li class="nav-item"><a class="nav-link" href="/aboutodit.html" id="left">About Us</a></li>
</ul>
Expand Down
3 changes: 3 additions & 0 deletions myapp/templates/profile.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ <h2>Email: {{ email }}</h2>
{% if is_technician %}
<h2>Bio:</h2>
<p>{{ bio }}</p>
<h2>Location:</h2>
<p>{{ location }}</p>
{% else %}
<a class="btn btn-primary my-2" href="/profile/become_technician">Sign Up to be a Technician!</a>
{% endif %}
<a class="btn btn-primary" href="/profile/edit.html">Edit Profile</a>
</div>
</div>
</div>
Expand Down
2 changes: 2 additions & 0 deletions myapp/templates/viewprofile.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ <h1>{{ user_name }}</h1>
<h2>Email: {{ email }}</h2>
<h2>Bio:</h2>
<p>{{ bio }}</p>
<h2>Location:</h2>
<p>{{ location }}</p>


{% endblock %}
9 changes: 6 additions & 3 deletions myapp/templates/viewtechnicians.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
{% block content %}

<div class="container mb-2 card bg-secondary">
<h3 class="card bg-primary font-weight-bold">Search for users</h3>
<h3 class="card bg-primary font-weight-bold">Search for technicians</h3>
<p>Searches can be done via username, bio or location.</p>
<form method="post" enctype="multipart/form-data">
<div class="row">
<div class="col col-md-4">
Expand All @@ -26,8 +27,10 @@ <h3 class="card bg-primary font-weight-bold">Search for users</h3>
<div class="column ml-2 mr-2">
{% for i in profile_list %}
<li>Name: {{ i.user.username }}</li>
<li>Bio: {{ i.bio }}</li>
<li><a class="btn btn-secondary" href="/viewprofile/{{i.id}}">View Profile</a></li>
<li>Bio: {{ i.bio }}</li>
<li>Location: {{ i.location }}</li>
<li><a class="btn btn-secondary" href="/viewprofile/{{i.id}}">View Profile</a></li>
<br>
{% endfor %}
</div>
</div>
Expand Down
12 changes: 9 additions & 3 deletions myapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def viewmyissues(request):
form = forms.IssueFilter()

context = {
"title":"ODIT - View Requests",
"title":"ODIT - View Assignments",
"issues_list":issues_list,
"form":form,
"is_technician": models.Profile.objects.get(user__exact=request.user).user_type,
Expand Down Expand Up @@ -148,6 +148,7 @@ def profile_page(request):
"title": "ODIT - {}".format(request.user.username),
"user_name": request.user.username,
"bio": this_user.bio,
"location": this_user.location,
"email": request.user.email,
"is_technician": this_user.user_type,
}
Expand All @@ -163,7 +164,7 @@ def edit_profile(request):
return redirect("/profile.html")
else:
if this_user.user_type:
form_instance = forms.ProfileForm(initial={'bio':this_user.bio,'email':request.user.email,'user_name':request.user.username})
form_instance = forms.ProfileForm(initial={'location':this_user.location,'bio':this_user.bio,'email':request.user.email,'user_name':request.user.username})
else:
form_instance = forms.ProfileFormNontech(initial={'email':request.user.email,'user_name':request.user.username})
context = {
Expand Down Expand Up @@ -195,7 +196,11 @@ def view_technicians(request):
Q(user__username__contains=form.cleaned_data['keyword'])
)
if (form.cleaned_data['name']):
profile_list = profile_list.filter(user__username__contains=form.cleaned_data['user_name'])
profile_list = profile_list.filter(user__username__contains=form.cleaned_data['name'])
if (form.cleaned_data['location']):
profile_list = profile_list.filter(
Q(location__contains=form.cleaned_data['location'])
)
else:
form = forms.ProfileFilter()
profile_list = models.Profile.objects.filter(user_type=True)
Expand All @@ -222,6 +227,7 @@ def view_profile(request,user_id):
"title": "ODIT - {}".format(view_user.user.username),
"user_name": view_user.user.username,
"bio": view_user.bio,
"location": view_user.location,
"email": view_user.user.email,
"is_technician": this_user.user_type,
}
Expand Down

0 comments on commit 55099b2

Please sign in to comment.