.
This commit is contained in:
@@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 3.2.8 on 2021-12-11 22:38
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('generic', '0016_ciduser_active'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='ciduser',
|
||||||
|
name='cid',
|
||||||
|
field=models.IntegerField(blank=True, null=True, unique=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
+1
-1
@@ -188,7 +188,7 @@ class QuestionNote(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class CidUser(models.Model):
|
class CidUser(models.Model):
|
||||||
cid = models.IntegerField(blank=True, null=True)
|
cid = models.IntegerField(blank=True, null=True, unique=True)
|
||||||
passcode = models.CharField(blank=True, max_length=50)
|
passcode = models.CharField(blank=True, max_length=50)
|
||||||
active = models.BooleanField(default=True)
|
active = models.BooleanField(default=True)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
{% extends 'base.html' %}
|
||||||
|
|
||||||
|
{% load render_table from django_tables2 %}
|
||||||
|
{% block css %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
<div id="view-filter-options">
|
||||||
|
<h3>Filter CID Users </h3>
|
||||||
|
<form action="" method="get">
|
||||||
|
{{ filter.form }}
|
||||||
|
<input class="btn btn-primary btn-sm mt-1 mb-1" type="submit" />
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% render_table table %}
|
||||||
|
|
||||||
|
<button id="add-new-cids">Add New</button>
|
||||||
|
<input type="number" id="add-number" value="number to add">
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block js %}
|
||||||
|
<script>
|
||||||
|
$(document).ready(function () {
|
||||||
|
$("#add-new-cids").click((evt) => {
|
||||||
|
|
||||||
|
|
||||||
|
$.ajax({
|
||||||
|
url: "{% url 'generic:create_cid_users' %}",
|
||||||
|
data: {
|
||||||
|
csrfmiddlewaretoken: "{{ csrf_token }}",
|
||||||
|
number: $("#add-number").get(0).value
|
||||||
|
},
|
||||||
|
type: "POST",
|
||||||
|
dataType: "json",
|
||||||
|
})
|
||||||
|
// $.ajax().done(), $.ajax().fail(), $ajax().always() are upto you. Add/change accordingly
|
||||||
|
.done(function (data) {
|
||||||
|
console.log(data);
|
||||||
|
|
||||||
|
if (data.status == "success") {
|
||||||
|
toastr.info('Added');
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
// show some message according to the response.
|
||||||
|
// For eg. A message box showing that the status has been changed
|
||||||
|
})
|
||||||
|
.always(function () {
|
||||||
|
console.log('[Done]');
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
{% endblock %}
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
{% extends 'base.html' %}
|
|
||||||
|
|
||||||
{% load render_table from django_tables2 %}
|
|
||||||
{% block css %}
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block content %}
|
|
||||||
|
|
||||||
<div id="view-filter-options">
|
|
||||||
<h3>Filter CID Users </h3>
|
|
||||||
<form action="" method="get">
|
|
||||||
{{ filter.form }}
|
|
||||||
<input class="btn btn-primary btn-sm mt-1 mb-1" type="submit" />
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
{% render_table table %}
|
|
||||||
|
|
||||||
{% endblock %}
|
|
||||||
|
|
||||||
{% block js %}
|
|
||||||
{% endblock %}
|
|
||||||
@@ -27,4 +27,5 @@ urlpatterns = [
|
|||||||
name="examination-autocomplete",
|
name="examination-autocomplete",
|
||||||
),
|
),
|
||||||
path("cids/manage/", views.CidUserView.as_view(), name="manage_cids"),
|
path("cids/manage/", views.CidUserView.as_view(), name="manage_cids"),
|
||||||
|
path("cids/create", views.create_cid_users, name="create_cid_users"),
|
||||||
]
|
]
|
||||||
|
|||||||
+15
-1
@@ -1,6 +1,7 @@
|
|||||||
from dal import autocomplete
|
from dal import autocomplete
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
from django.db.models.expressions import Random
|
||||||
from django.forms.models import model_to_dict
|
from django.forms.models import model_to_dict
|
||||||
from django.shortcuts import render, get_object_or_404, redirect
|
from django.shortcuts import render, get_object_or_404, redirect
|
||||||
|
|
||||||
@@ -51,6 +52,7 @@ from django.conf import settings
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
|
import string
|
||||||
|
|
||||||
#from rad.views import get_question_and_content_type
|
#from rad.views import get_question_and_content_type
|
||||||
|
|
||||||
@@ -841,6 +843,18 @@ class ExaminationAutocomplete(autocomplete.Select2QuerySetView):
|
|||||||
class CidUserView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
class CidUserView(LoginRequiredMixin, SingleTableMixin, FilterView):
|
||||||
model = CidUser
|
model = CidUser
|
||||||
table_class = CidUserTable
|
table_class = CidUserTable
|
||||||
template_name = "generic/question_view.html"
|
template_name = "generic/cid_view.html"
|
||||||
|
|
||||||
filterset_class = CidUserFilter
|
filterset_class = CidUserFilter
|
||||||
|
|
||||||
|
def create_cid_users(request):
|
||||||
|
if request.is_ajax() and request.method == "POST":
|
||||||
|
number = request.POST.get("number")
|
||||||
|
|
||||||
|
new_cid = max(CidUser.objects.all().order_by("-cid")[0].cid+1, 50000)
|
||||||
|
|
||||||
|
for n in range(number):
|
||||||
|
passcode = Random.choice(string.aschii_uppercase)
|
||||||
|
c = CidUser(cid=new_cid, passcode=passcode)
|
||||||
|
c.save()
|
||||||
|
new_cid = new_cid + 1
|
||||||
Reference in New Issue
Block a user