diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9903a07 --- /dev/null +++ b/.gitignore @@ -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 diff --git a/db.sqlite3 b/db.sqlite3 deleted file mode 100644 index 4b81901..0000000 Binary files a/db.sqlite3 and /dev/null differ diff --git a/myapp/__pycache__/__init__.cpython-37.pyc b/myapp/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 85b3d18..0000000 Binary files a/myapp/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/myapp/__pycache__/admin.cpython-37.pyc b/myapp/__pycache__/admin.cpython-37.pyc deleted file mode 100644 index 4963cc4..0000000 Binary files a/myapp/__pycache__/admin.cpython-37.pyc and /dev/null differ diff --git a/myapp/__pycache__/forms.cpython-37.pyc b/myapp/__pycache__/forms.cpython-37.pyc deleted file mode 100644 index c8eb798..0000000 Binary files a/myapp/__pycache__/forms.cpython-37.pyc and /dev/null differ diff --git a/myapp/__pycache__/models.cpython-37.pyc b/myapp/__pycache__/models.cpython-37.pyc deleted file mode 100644 index a074bf0..0000000 Binary files a/myapp/__pycache__/models.cpython-37.pyc and /dev/null differ diff --git a/myapp/__pycache__/urls.cpython-37.pyc b/myapp/__pycache__/urls.cpython-37.pyc deleted file mode 100644 index 659d7a6..0000000 Binary files a/myapp/__pycache__/urls.cpython-37.pyc and /dev/null differ diff --git a/myapp/__pycache__/views.cpython-37.pyc b/myapp/__pycache__/views.cpython-37.pyc deleted file mode 100644 index 71246c0..0000000 Binary files a/myapp/__pycache__/views.cpython-37.pyc and /dev/null differ diff --git a/myapp/forms.py b/myapp/forms.py index 03666ab..f21dba5 100644 --- a/myapp/forms.py +++ b/myapp/forms.py @@ -6,11 +6,31 @@ from . import models # validator to ensure email addresses are unique -def must_be_unique(value): +def must_be_unique_email(value): user = User.objects.filter(email=value) if len(user) > 0: raise forms.ValidationError("A user with that email already exists.") +# validator to ensure usernames are unique +def must_be_unique_user(value): + user = User.objects.filter(username=value) + if len(user) > 0: + raise forms.ValidationError("A user with that username already exists.") + +ISSUE_CHOICES = [ + ('Desktop', 'Desktop'), + ('Laptop', 'Laptop'), + ('Tablet', 'Tablet'), + ('Phone', 'Phone'), + ('Server', 'Server'), + ('Networking', 'Networking'), + ('Application', 'Application'), + ('Operating System', 'Operating System'), + ('Email', 'Email'), + ('Account Management', 'Account Management'), + ('Lost Password', 'Lost Password'), + ('Other', 'Other') +] class IssueForm(forms.Form): title = forms.CharField( widget = forms.TextInput( @@ -30,65 +50,17 @@ class IssueForm(forms.Form): max_length=240 ) - issue_type = forms.IntegerField( - widget = forms.TextInput( - attrs={'class': 'form-control'} - ), + issue_type = forms.CharField( label='Issue Type', + widget=forms.Select(choices=ISSUE_CHOICES), 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() @@ -107,7 +79,7 @@ class IssueFilter(forms.Form): max_length=100 ) - issue_type = forms.IntegerField( + issue_type = forms.CharField( widget = forms.TextInput( attrs={ 'class': 'form-control', @@ -122,7 +94,7 @@ class RegistrationForm(UserCreationForm): email = forms.EmailField( label="Email", required=True, - validators=[must_be_unique] + validators=[must_be_unique_email] ) class Meta: @@ -148,18 +120,22 @@ def save(self, commit=True): return user class ProfileForm(forms.Form): + """ user_name = forms.CharField( widget = forms.TextInput( attrs={'class': 'form-control'} ), label='User Name', required=False, + validators=[must_be_unique_user], max_length=150 ) - + """ + email = forms.EmailField( label="Email", required=False + #validators=[must_be_unique_email] ) bio = forms.CharField( @@ -171,29 +147,44 @@ 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: this_user.email = self.cleaned_data["email"] - if self.cleaned_data['user_name']: - this_user.username = self.cleaned_data["user_name"] + #if self.cleaned_data['user_name']: + # 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 class ProfileFormNontech(forms.Form): + """ user_name = forms.CharField( widget = forms.TextInput( attrs={'class': 'form-control'} ), label='User Name', required=False, + validators=[must_be_unique_user], max_length=150 ) - + """ + email = forms.EmailField( label="Email", + #validators=[must_be_unique_email], required=False ) @@ -201,8 +192,8 @@ 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: this_user.email = self.cleaned_data["email"] - if self.cleaned_data['user_name']: - this_user.username = self.cleaned_data["user_name"] + #if self.cleaned_data['user_name']: + # this_user.username = self.cleaned_data["user_name"] this_user.save() return this_user @@ -230,3 +221,141 @@ 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 + ) + +STARS = [ + ('5','5'), + ('4','4'), + ('3','3'), + ('2','2'), + ('1','1'), + ('0','0'), +] +class AddReviewForm(forms.Form): + rating = forms.CharField( + widget = forms.Select( + choices=STARS, + attrs={'class': 'form-control'} + ), + label='Rating', + required=True + ) + + review = forms.CharField( + label='Review', + widget=forms.Textarea( + attrs={'class': 'form-control'} + ), + required=False, + max_length=240 + ) + + def save(self, writer, subject): + review_instance = models.Review() + review_instance.rating = int(self.cleaned_data["rating"]) + review_instance.review = self.cleaned_data["review"] + review_instance.writer = User.objects.get(id__exact=writer) + review_instance.subject = User.objects.get(id__exact=subject) + review_instance.save() + subject_instance = models.Profile.objects.get(user=review_instance.subject) + subject_instance.rating_count = subject_instance.rating_count + 1 + subject_instance.rating_sum = subject_instance.rating_sum + review_instance.rating + subject_instance.rating_avg = round(subject_instance.rating_sum / subject_instance.rating_count,1) + subject_instance.save() + return review_instance + +class EditReviewForm(forms.Form): + rating = forms.CharField( + widget = forms.Select( + choices=STARS, + attrs={'class': 'form-control'} + ), + label='Rating', + required=True + ) + + review = forms.CharField( + label='Review', + widget=forms.Textarea( + attrs={'class': 'form-control'} + ), + required=False, + max_length=240 + ) + + def save(self, id): + review_instance = models.Review.objects.get(id__exact=id) + subject_instance = models.Profile.objects.get(user=review_instance.subject) + subject_instance.rating_sum = subject_instance.rating_sum - review_instance.rating + review_instance.rating = int(self.cleaned_data["rating"]) + subject_instance.rating_sum = subject_instance.rating_sum + review_instance.rating + review_instance.review = self.cleaned_data["review"] + subject_instance.rating_avg = round(subject_instance.rating_sum / subject_instance.rating_count,1) + subject_instance.save() + review_instance.save() + return review_instance + +class ResolveIssueForm(forms.Form): + resolution = forms.CharField( + widget=forms.Textarea( + attrs={'class': 'form-control'} + ), + label='Resolution', + required=False, + max_length=720 + ) + + def save(self, id): + this_ticket = models.Issue_Model.objects.get(id__exact=id) + this_ticket.is_solved = 1 + if self.cleaned_data['resolution']: + this_ticket.resolution = self.cleaned_data["resolution"] + this_ticket.save() + return this_ticket + +class EditIssueForm(forms.Form): + title = forms.CharField( + widget = forms.TextInput( + attrs={'class': 'form-control'} + ), + label='Title', + required=True, + max_length=100 + ) + + description = forms.CharField( + label='Description', + widget=forms.Textarea( + attrs={'class': 'form-control'} + ), + required=False, + max_length=240 + ) + + issue_type = forms.CharField( + label='Issue Type', + widget=forms.Select(choices=ISSUE_CHOICES), + required=True + ) + + def save(self, id): + this_ticket = models.Issue_Model.objects.get(id__exact=id) + if self.cleaned_data['title']: + this_ticket.title = self.cleaned_data["title"] + if self.cleaned_data['description']: + this_ticket.description = self.cleaned_data["description"] + if self.cleaned_data['issue_type']: + this_ticket.issue_type = self.cleaned_data["issue_type"] + this_ticket.save() + return this_ticket diff --git a/myapp/migrations/__pycache__/0001_initial.cpython-37.pyc b/myapp/migrations/__pycache__/0001_initial.cpython-37.pyc deleted file mode 100644 index 02ce77d..0000000 Binary files a/myapp/migrations/__pycache__/0001_initial.cpython-37.pyc and /dev/null differ diff --git a/myapp/migrations/__pycache__/__init__.cpython-37.pyc b/myapp/migrations/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index abd2b75..0000000 Binary files a/myapp/migrations/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/myapp/models.py b/myapp/models.py index ea21d20..600a393 100644 --- a/myapp/models.py +++ b/myapp/models.py @@ -2,29 +2,41 @@ from django.contrib.auth.models import User from django.db.models.signals import post_save from django.dispatch import receiver +from django.core.validators import MinValueValidator, MaxValueValidator # Create your models here. class Issue_Model(models.Model): - title = models.CharField(max_length=100) - description = models.CharField(max_length=240, null=True) - issue_type = models.IntegerField() - date_created = models.DateField(auto_now_add=True) - assigned_user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='assigned_user') - affected_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='affected_user') - is_solved = models.BooleanField(null=True) # 0 for unsolved, 1 for solved + title = models.CharField(max_length=100) + description = models.CharField(max_length=240, null=True) + issue_type = models.CharField(max_length=240) + date_created = models.DateField(auto_now_add=True) + assigned_user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name='assigned_user') + affected_user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='affected_user') + is_solved = models.BooleanField(null=True) # 0 for unsolved, 1 for solved + resolution = models.CharField(max_length=240, null=True) class Profile(models.Model): - user = models.OneToOneField(User, on_delete=models.CASCADE) - bio = models.TextField(null=True, max_length=500, blank=True) - location = models.CharField(null=True, max_length=200) - user_type = models.BooleanField(null=True) # 0 for user, 1 for ODITer - birth_date = models.DateField(null=True, blank=True) + user = models.OneToOneField(User, on_delete=models.CASCADE) + bio = models.TextField(null=True, max_length=500, blank=True) + location = models.CharField(null=True, max_length=200) + user_type = models.BooleanField(null=True) # 0 for user, 1 for ODITer + birth_date = models.DateField(null=True, blank=True) + rating_sum = models.IntegerField(default=0) + rating_count = models.IntegerField(default=0) + rating_avg = models.FloatField(default=0) @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): - if created: - Profile.objects.create(user=instance) + if created: + Profile.objects.create(user=instance) @receiver(post_save, sender=User) def save_user_profile(sender, instance, **kwargs): - instance.profile.save() + instance.profile.save() + +class Review(models.Model): + writer = models.ForeignKey(User, on_delete=models.CASCADE, related_name='writer') + subject = models.ForeignKey(User, on_delete=models.CASCADE, related_name='subject') + date_created = models.DateField(auto_now_add=True) + rating = models.IntegerField(validators=[MinValueValidator(0), MaxValueValidator(5)]) + review = models.CharField(max_length=240, null=True) diff --git a/myapp/templates/base.html b/myapp/templates/base.html index 9bb8ded..e912a15 100644 --- a/myapp/templates/base.html +++ b/myapp/templates/base.html @@ -15,11 +15,11 @@ {% if user.is_authenticated %} - + {% if is_technician %} - - + {% endif %} + {% endif %} diff --git a/myapp/templates/editreview.html b/myapp/templates/editreview.html new file mode 100644 index 0000000..c068e2a --- /dev/null +++ b/myapp/templates/editreview.html @@ -0,0 +1,22 @@ +{% extends "base.html" %} +{% block content %} + +{% load static %} +
+
+
+
+ +
+
+ {% csrf_token %} + {{ form.as_table }}

+ + Cancel +
+
+
+
+
+ +{% endblock %} diff --git a/myapp/templates/editticket.html b/myapp/templates/editticket.html new file mode 100644 index 0000000..46a5832 --- /dev/null +++ b/myapp/templates/editticket.html @@ -0,0 +1,21 @@ +{% extends "base.html" %} +{% block content %} + +{% load static %} +
+
+
+
+
+
+ {% csrf_token %} + {{ form.as_table }}

+ + Cancel +
+
+
+
+
+ +{% endblock %} diff --git a/myapp/templates/profile.html b/myapp/templates/profile.html index 9bf41dd..4dd4185 100644 --- a/myapp/templates/profile.html +++ b/myapp/templates/profile.html @@ -17,9 +17,12 @@

Email: {{ email }}

{% if is_technician %}

Bio:

{{ bio }}

+

Location:

+

{{ location }}

{% else %} - Sign Up to be a Technician! + Sign Up to be a Technician!
{% endif %} + Edit Profile diff --git a/myapp/templates/viewissues.html b/myapp/templates/viewissues.html index b5cc3f9..09eecb7 100644 --- a/myapp/templates/viewissues.html +++ b/myapp/templates/viewissues.html @@ -2,7 +2,7 @@ {% block content %}
-

Search for posted issues:

+

Search for Requests:

@@ -32,17 +32,18 @@

Search for posted issues:

{% if issues_list %} {% for i in issues_list %}
-
Ticket #{{ i.id }}: {{ i.title|title }} +
+ Ticket #{{ i.id }}: {{ i.title|title }}

Description: {{ i.description }}

Date created: {{ i.date_created }}

Issue type: {{ i.issue_type }}

-

Assigned user: {{ i.assigned_user }}

-

Affected user: {{ i.affected_user }}

+

Assigned user: {{ i.assigned_user }} {% if i.assigned_user %}View Profile{% endif %}

+

Affected user: {{ i.affected_user }} {% if i.affected_user %}View Profile{% endif %}

Issue solved?: {% if i.is_solved == True %} Yes {% else %} No {% endif %}

- {% if is_technician and user != i.assigned_user and user != i.affected_user %} - Assign Myself + {% if is_technician and user != i.assigned_user and user != i.affected_user and i.is_solved == False %} + Assign Issue {% endif %}
diff --git a/myapp/templates/viewmyissues.html b/myapp/templates/viewmyissues.html index 3eae4e1..48195b1 100644 --- a/myapp/templates/viewmyissues.html +++ b/myapp/templates/viewmyissues.html @@ -2,7 +2,7 @@ {% block content %}
-

My Assigned Issues:

+

My Assigned Requests:

@@ -19,26 +19,34 @@

My Assigned Issues:

-{% if issues_list %} -
-
+
+ {% if issues_list %} {% for i in issues_list %} -

Ticket # {{ i.id }}

-
  • Title: {{ i.title }}
  • -
  • Description: {{ i.description }}
  • -
  • Date Created: {{ i.date_created }}
  • -
  • Issue_type: {{ i.issue_type }}
  • -
  • Assigned_user: {{ i.assigned_user }}
  • -
  • Affected_user: {{ i.affected_user }}
  • -
  • Is_solved?: {{ i.is_solved }}

  • +
    +
    + Issue #{{ i.id }}: {{ i.title|title }} +
    +
    +

    Description: {{ i.description }}

    +

    Date created: {{ i.date_created }}

    +

    Issue type: {{ i.issue_type }}

    +

    Affected user: {{ i.affected_user }} {% if i.affected_user %}View Profile{% endif %}

    +

    Issue solved?: {% if i.is_solved == True %} Yes {% else %} No {% endif %}

    + {% if i.is_solved == False %} + Resolve? + {% else %} +

    Resolution: {{ i.resolution }}

    + {% endif %} +
    +
    {% endfor %} + {% else %} +

    There are no entries with those parameters.

    + {% endif %}
    -{% else %} -

    You don't have any assigned issued with those parameters.

    -{% endif %} {% endblock %} diff --git a/myapp/templates/viewmysubmittedissues.html b/myapp/templates/viewmysubmittedissues.html index 7fbfcee..0735e47 100644 --- a/myapp/templates/viewmysubmittedissues.html +++ b/myapp/templates/viewmysubmittedissues.html @@ -30,14 +30,17 @@ {% if issues_list.count > 0 %} {% comment %} TODO: Add a filter form to this list, too {% endcomment %} {% for issue in issues_list %} -
    +
    {{ issue.title|title }}

    {{ issue.description }}

    Date Created: {{ issue.date_created }}

    -

    Issue type: {{ issue.issue_type }}

    +

    Issue Type: {{ issue.issue_type }}

    +

    Assigned Technician: {{ issue.assigned_user }} {% if issue.assigned_user %}View Profile{% endif %}

    +

    Issue solved?: {% if issue.is_solved == True %} Yes {% else %} No {% endif %}

    + Edit Issue
    {% endfor %} diff --git a/myapp/templates/viewprofile.html b/myapp/templates/viewprofile.html index cb6b09d..eef47ed 100644 --- a/myapp/templates/viewprofile.html +++ b/myapp/templates/viewprofile.html @@ -3,10 +3,45 @@ {% load static %} -

    {{ user_name }}

    +

    {{ user_name }} ({{ rating }} Stars)

    Email: {{ email }}

    Bio:

    {{ bio }}

    - +

    Location:

    +

    {{ location }}

    +{% if form %} +
    +

    Leave a Review:

    +
    +
    +
    +
    +
    + {% csrf_token %} + {{ form.as_table }}

    + +
    +
    +
    +
    +
    +{% endif %} +{% if reviews_list %} +
    +

    Reviews

    + {% for r in reviews_list %} +
    +
    +

    {{ r.writer }} gave {{ r.subject }} {{ r.rating }} stars on {{ r.date_created }}{% if r.writer %}: View Profile{% endif %}

    +
    +
    +

    {{ r.review }}

    + {% if r.writer == user %} + Edit + {% endif %} +
    +
    + {% endfor %} +{% endif %} {% endblock %} diff --git a/myapp/templates/viewtechnicians.html b/myapp/templates/viewtechnicians.html index c9bb78b..1339168 100644 --- a/myapp/templates/viewtechnicians.html +++ b/myapp/templates/viewtechnicians.html @@ -2,7 +2,8 @@ {% block content %}
    -

    Search for users

    +

    Search for technicians

    +

    Searches can be done via username, bio or location.

    @@ -26,8 +27,11 @@

    Search for users

    {% for i in profile_list %}
  • Name: {{ i.user.username }}
  • -
  • Bio: {{ i.bio }}
  • -
  • View Profile
  • +
  • Rating: {{ i.rating_avg }} Stars
  • +
  • Bio: {{ i.bio }}
  • +
  • Location: {{ i.location }}
  • +
  • View Profile
  • +
    {% endfor %}
    diff --git a/myapp/urls.py b/myapp/urls.py index e88794c..2d288d8 100644 --- a/myapp/urls.py +++ b/myapp/urls.py @@ -27,12 +27,15 @@ path('viewmyissues.html', views.viewmyissues), path('viewmysubmittedissues.html', views.viewmysubmittedissues), path('viewissues/assign/', views.self_assign), + path('resolve/', views.resolve_ticket), + path('editticket/', views.edit_ticket), path('aboutodit.html', views.about), path('profile.html',views.profile_page), path('profile/edit.html',views.edit_profile), path('profile/become_technician',views.become_technician), path('viewtechnicians.html',views.view_technicians), path('viewprofile/',views.view_profile), + path('editreview/',views.edit_review), path('login/', auth_views.LoginView.as_view()), path('register/', views.register), path('logout/', views.logoff) diff --git a/myapp/views.py b/myapp/views.py index fc63a61..95599b4 100644 --- a/myapp/views.py +++ b/myapp/views.py @@ -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, @@ -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, } @@ -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 = { @@ -192,10 +193,15 @@ def view_technicians(request): if (form.cleaned_data['keyword']): profile_list = profile_list.filter( Q(bio__contains=form.cleaned_data['keyword']) | - Q(user__username__contains=form.cleaned_data['keyword']) + Q(user__username__contains=form.cleaned_data['keyword']) | + Q(location__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) @@ -218,40 +224,128 @@ def view_profile(request,user_id): view_user = models.Profile.objects.get(user__id__exact=user_id) except ObjectDoesNotExist: return redirect("/viewtechnicians.html") + if request.method == "POST": + form_instance = forms.AddReviewForm(request.POST) + if form_instance.is_valid(): + form_instance.save(this_user.user.id,view_user.user.id) + return redirect("/viewprofile/{}".format(view_user.id)) + else: + if this_user != view_user and (not models.Review.objects.filter(writer=this_user.user).filter(subject=view_user.user).exists()) and models.Issue_Model.objects.filter(affected_user=this_user.user).filter(assigned_user=view_user.user).exists(): + form = forms.AddReviewForm() + else: + form = False + context = { + "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, + "form": form, + "reviews_list": models.Review.objects.filter(subject=view_user.user), + "rating": view_user.rating_avg, + "is_technician": this_user.user_type, + } + print(list(context['reviews_list'])) + return render(request, "viewprofile.html", context=context) + +@login_required +def viewmysubmittedissues(request): + issues_list = models.Issue_Model.objects.filter(affected_user=request.user) + if request.method == "POST": + form = forms.IssueFilter(request.POST) + if form.is_valid(): + if (form.cleaned_data['keyword']): + issues_list = issues_list.filter( + Q(title__contains=form.cleaned_data['keyword']) | + Q(description__contains=form.cleaned_data['keyword']) | + Q(affected_user__username__contains=form.cleaned_data['keyword']) + ) + if (form.cleaned_data['issue_type']): + issues_list = issues_list.filter( + Q(issue_type__exact=form.cleaned_data['issue_type']) + ) + else: + form = forms.IssueFilter() + else: + form = forms.IssueFilter() + context = { - "title": "ODIT - {}".format(view_user.user.username), - "user_name": view_user.user.username, - "bio": view_user.bio, - "email": view_user.user.email, - "is_technician": this_user.user_type, + "title":"ODIT - Your Submitted Issues", + "issues_list":issues_list, + "form":form, + "is_technician": models.Profile.objects.get(user__exact=request.user).user_type, } - return render(request, "viewprofile.html", context=context) + return render(request, "viewmysubmittedissues.html", context=context) @login_required -def viewmysubmittedissues(request): - issues_list = models.Issue_Model.objects.filter(affected_user=request.user) - if request.method == "POST": - form = forms.IssueFilter(request.POST) - if form.is_valid(): - if (form.cleaned_data['keyword']): - issues_list = issues_list.filter( - Q(title__contains=form.cleaned_data['keyword']) | - Q(description__contains=form.cleaned_data['keyword']) | - Q(affected_user__username__contains=form.cleaned_data['keyword']) - ) - if (form.cleaned_data['issue_type']): - issues_list = issues_list.filter( - Q(issue_type__exact=form.cleaned_data['issue_type']) - ) - else: - form = forms.IssueFilter() - else: - form = forms.IssueFilter() +def edit_review(request,id): + this_user = models.Profile.objects.get(user__exact=request.user) + try: + this_review = models.Review.objects.get(id__exact=id) + view_user = models.Profile.objects.get(user__exact=this_review.subject) + except ObjectDoesNotExist: + return redirect("/viewtechnicians.html") + if request.method == "POST": + form_instance = forms.EditReviewForm(request.POST) + if form_instance.is_valid(): + form_instance.save(id) + return redirect("/viewprofile/{}".format(view_user.user.id)) + else: + if this_user == models.Review.objects.get(id__exact=id).writer.profile: + form = forms.EditReviewForm(initial={'rating':this_review.rating,'review':this_review.review}) + context = { + "title": "ODIT - Edit Review for {}".format(view_user.user.username), + "form": form, + "id": view_user.user.id, + "is_technician": this_user.user_type, + } + return render(request, "editreview.html", context=context) + else: + return redirect("/viewprofile/{}".format(view_user.user.id)) - context = { - "title":"ODIT - Your Submitted Issues", - "issues_list":issues_list, - "form":form, - "is_technician": models.Profile.objects.get(user__exact=request.user).user_type, - } - return render(request, "viewmysubmittedissues.html", context=context) \ No newline at end of file +@login_required +def resolve_ticket(request, id): + try: + this_ticket = models.Issue_Model.objects.get(id__exact=id) + except ObjectDoesNotExist: + return redirect("/viewmyissues.html") + if request.method == "POST": + form_instance = forms.ResolveIssueForm(request.POST) + if form_instance.is_valid(): + form_instance.save(id) + return redirect("/viewmyissues.html") + else: + if this_ticket == models.Issue_Model.objects.get(id__exact=id): + form = forms.ResolveIssueForm(initial={'Resolved?':this_ticket.is_solved,'Resolution':this_ticket.resolution}) + context = { + "title": "ODIT - Resolve Ticket", + "form": form, + "id": this_ticket, + } + return render(request, "editticket.html", context=context) + else: + return redirect("/viewmyissues") + +@login_required +def edit_ticket(request, id): + try: + this_ticket = models.Issue_Model.objects.get(id__exact=id) + except ObjectDoesNotExist: + return redirect("/viewmysubmittedissues.html") + if request.method == "POST": + form_instance = forms.EditIssueForm(request.POST) + if form_instance.is_valid(): + form_instance.save(id) + return redirect("/viewmysubmittedissues.html") + else: + if this_ticket == models.Issue_Model.objects.get(id__exact=id): + form = forms.EditIssueForm(initial={'title':this_ticket.title,'description':this_ticket.description,'issue_type':this_ticket.issue_type}) + context = { + "title": "ODIT - Edit Ticket", + "form": form, + "id": this_ticket, + } + return render(request, "editticket.html", context=context) + else: + return redirect("/viewmyissues") + diff --git a/mysite/__pycache__/__init__.cpython-37.pyc b/mysite/__pycache__/__init__.cpython-37.pyc deleted file mode 100644 index 132e18d..0000000 Binary files a/mysite/__pycache__/__init__.cpython-37.pyc and /dev/null differ diff --git a/mysite/__pycache__/settings.cpython-37.pyc b/mysite/__pycache__/settings.cpython-37.pyc deleted file mode 100644 index 3861ca9..0000000 Binary files a/mysite/__pycache__/settings.cpython-37.pyc and /dev/null differ diff --git a/mysite/__pycache__/urls.cpython-37.pyc b/mysite/__pycache__/urls.cpython-37.pyc deleted file mode 100644 index d74c7a6..0000000 Binary files a/mysite/__pycache__/urls.cpython-37.pyc and /dev/null differ diff --git a/mysite/__pycache__/wsgi.cpython-37.pyc b/mysite/__pycache__/wsgi.cpython-37.pyc deleted file mode 100644 index cf6bf12..0000000 Binary files a/mysite/__pycache__/wsgi.cpython-37.pyc and /dev/null differ