Просмотр исходного кода

add registration form for staff member.

Mohidul Islam 4 лет назад
Родитель
Сommit
1b5469ce4f

+ 9 - 3
dashboard/static/user-dashboard.css

@@ -153,8 +153,8 @@ body {
   background: #fff;
   border-radius: 2px;
   display: inline-block;
-  margin: 1rem;
-  position: relative;
+  margin: 1rem 0rem 1rem 0rem;
+  padding:1rem;
 }
 
 .graph-card-shadow {
@@ -168,5 +168,11 @@ body {
 
 .graph-container {
     display: flex;
-    padding:1rem;
+}
+
+.modal-content {
+    padding: 1rem;
+}
+#id_nick_names {
+    height: 4rem;
 }

+ 8 - 0
user/forms.py

@@ -1,5 +1,6 @@
 from django import forms
 from django.contrib.auth.models import User
+from name_extractor.models import Staff
 from django.contrib.auth.forms import UserCreationForm
 
 
@@ -9,3 +10,10 @@ class UserRegisterForm(UserCreationForm):
     class Meta:
         model = User
         fields = ['username', 'email', 'password1', 'password2']
+
+
+class StaffRegistrationForm(forms.ModelForm):
+
+    class Meta:
+        model = Staff
+        fields = ['name', 'department', 'nick_names']

+ 9 - 6
user/templates/location-wise-reviews.html

@@ -1,6 +1,7 @@
 {% extends 'user-base.html' %}
 
 {% block content %}
+
   <div class="graph-card graph-card-shadow graph-container">
     <div style="width: 100%;">
       <canvas id="myChart" width="1200" height="300"></canvas>
@@ -15,6 +16,7 @@
         <canvas id="googlePieChart" width="200" height="150"></canvas>
       </div>
   </div>
+
   <div class="graph-card graph-card-shadow graph-container">
       <div style="position: relative; width: 70%;">
         <canvas id="facebookLineChart" width="900" height="300"></canvas>
@@ -207,8 +209,9 @@
             options: {
               title: {
                 display: true,
-                fontSize: 16,
-                text: 'This is google reviews'
+                fontSize: 12,
+               // position: 'bottom',
+                text: 'All reviews of this month'
               }
             }
         });
@@ -277,8 +280,8 @@
             options: {
               title: {
                 display: true,
-                fontSize: 16,
-                text: 'This is google reviews'
+                fontSize: 12,
+                text: 'All reviews of this month'
               }
             }
         });
@@ -378,8 +381,8 @@
             options: {
               title: {
                 display: true,
-                fontSize: 16,
-                text: 'This is yelp reviews'
+                fontSize: 12,
+                text: 'All reviews of this month'
               }
             }
         });

+ 23 - 0
user/templates/staff_list.html

@@ -1,5 +1,28 @@
 {% extends 'user-base.html' %}
+{% load crispy_forms_tags %}
 {% block content %}
+
+<!--adding a new staff member.-->
+<button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bd-example-modal-lg">Large modal</button>
+  <div class="modal fade bd-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
+    <div class="modal-dialog modal-lg">
+      <div class="modal-content">
+        <div class="content-section">
+        <form method="POST">
+            {% csrf_token %}
+            <fieldset class="form-group">
+                <legend style="text-align: center;" class="border-bottom mb-4"><b>Add a new staff.</b></legend>
+                {{ form|crispy }}
+            </fieldset>
+            <div class="form-group" style="display: grid;">
+                <button class="btn btn-outline-info" type="submit">Submit</button>
+            </div>
+        </form>
+      </div>
+      </div>
+    </div>
+  </div>
+
   <div class="row">
     {% for staff in staffs %}
     <div class="col-sm-6">

+ 30 - 5
user/views.py

@@ -2,7 +2,7 @@ from django.http import Http404
 from django.shortcuts import render, redirect
 from django.views.generic import View
 from django.contrib import messages
-from .forms import UserRegisterForm
+from .forms import UserRegisterForm, StaffRegistrationForm
 from .models import UserAccount
 from gauth.models import Location
 from review.models import Review
@@ -130,9 +130,34 @@ class ReviewAnalyticsGraph(View):
 
 class StaffLeaderBoard(View):
 
-    def get(self, requests, *args, **kwargs):
-        staffs = Staff.objects.filter(location=requests.user.useraccount.location).order_by('-total_units')
+    def get(self, request, *args, **kwargs):
+        staffs = Staff.objects.filter(location=request.user.useraccount.location).order_by('-total_units')
+        form = StaffRegistrationForm()
+
+        context = {
+            'staffs': staffs,
+            'form': form
+        }
+        return render(request, 'staff_list.html', context)
+
+    def post(self, request, *args, **kwargs):
+        staffs = Staff.objects.filter(location=request.user.useraccount.location).order_by('-total_units')
+        form = StaffRegistrationForm(request.POST)
+        if form.is_valid():
+            name = form.cleaned_data.get('name')
+            department = form.cleaned_data.get('department')
+            nick_names = form.cleaned_data.get('nick_names')
+            location_id = request.user.useraccount.location_id
+            staff = Staff.objects.create(
+                name=name,
+                location_id=location_id,
+                department=department,
+                nick_names=nick_names
+            )
+            messages.success(request, f'A new staff {staff} has been created!')
+
         context = {
-            'staffs': staffs
+            'staffs': staffs,
+            'form': form
         }
-        return render(requests, 'staff_list.html', context)
+        return render(request, 'staff_list.html', context)