added exam cell staff user creation and changed workspace

This commit is contained in:
Pranav Jerry 2023-03-26 14:26:08 +05:30
parent d406c0ca50
commit d359d0d7ad
Signed by: pranav
GPG Key ID: F1DCDC4FED0A0C5B
7 changed files with 180 additions and 4 deletions

View File

@ -0,0 +1,8 @@
// Copyright (c) 2023, CSE 2020 Batch and contributors
// For license information, please see license.txt
// frappe.ui.form.on("Exam Cell Staff", {
// refresh(frm) {
// },
// });

View File

@ -0,0 +1,65 @@
{
"actions": [],
"allow_rename": 1,
"creation": "2023-03-26 11:42:03.030716",
"default_view": "List",
"description": "Create a new user",
"doctype": "DocType",
"editable_grid": 1,
"engine": "InnoDB",
"field_order": [
"email",
"full_name",
"password"
],
"fields": [
{
"fieldname": "email",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Email",
"options": "Email",
"reqd": 1
},
{
"fieldname": "full_name",
"fieldtype": "Data",
"in_list_view": 1,
"label": "Full name",
"options": "Name",
"reqd": 1
},
{
"fieldname": "password",
"fieldtype": "Data",
"label": "Password",
"no_copy": 1,
"reqd": 1
}
],
"index_web_pages_for_search": 1,
"is_virtual": 1,
"links": [],
"modified": "2023-03-26 13:27:39.909466",
"modified_by": "Administrator",
"module": "Exam Helper",
"name": "Exam Cell Staff",
"owner": "Administrator",
"permissions": [
{
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "System Manager",
"share": 1,
"write": 1
}
],
"sort_field": "modified",
"sort_order": "DESC",
"states": []
}

View File

@ -0,0 +1,86 @@
# Copyright (c) 2023, CSE 2020 Batch and contributors
# For license information, please see license.txt
import frappe
from frappe.model.document import Document
from frappe.utils.password import update_password
class ExamCellStaff(Document):
"""class to easily create new users"""
def db_insert(self, *args, **kwargs):
"""create a user with the given info"""
print("creating user", self.name, self.email, self.full_name, self.password)
user = frappe.get_doc(
doctype="User",
email=self.email,
first_name=self.full_name,
)
user.module_profile = "Exam Cell"
print("created obj")
user.insert()
print("insert done")
self.name = user.name
print(user.name, "done, setting password")
user = frappe.get_doc("User", self.name)
role = frappe.new_doc("Has Role")
role.update(
{
"role": "Exam Cell Staff",
"parent": user.name,
"parentfield": "roles",
"parenttype": "User",
}
)
user.roles.append(role)
user.new_password = self.password
user.save()
print("done")
def load_from_db(self):
user = frappe.get_doc("User", self.name)
super(Document, self).__init__(
{"name": user.name, "email": user.email, "full_name": user.full_name}
)
def db_update(self):
print(0)
user = frappe.get_doc("User", self.name)
print(1)
user.email = self.email
print(2)
user.first_name = self.full_name
print(3)
user.new_password = self.password
print(4)
user.save()
print(5)
if self.password != "":
update_password(user.name, self.password)
print(6)
def delete(self):
frappe.delete_doc("User", self.name)
@staticmethod
def get_list(args):
users = frappe.get_list("User")
staff = []
for i in users:
user = frappe.get_doc("User", i)
staff.append(
{"name": user.name, "email": user.email, "full_name": user.full_name}
)
return staff
@staticmethod
def get_count(args):
return frappe.db.count("User")
@staticmethod
def get_stats(args):
pass

View File

@ -0,0 +1,9 @@
# Copyright (c) 2023, CSE 2020 Batch and Contributors
# See license.txt
# import frappe
from frappe.tests.utils import FrappeTestCase
class TestExamCellStaff(FrappeTestCase):
pass

View File

@ -45,7 +45,7 @@
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2023-03-26 10:15:08.423191",
"modified": "2023-03-26 11:05:54.539783",
"modified_by": "Administrator",
"module": "Exam Helper",
"name": "Staff",

View File

@ -1,6 +1,6 @@
{
"charts": [],
"content": "[{\"id\":\"7w-Gz8ZpX6\",\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\">Home</span>\",\"col\":12}},{\"id\":\"nryCoa8NMT\",\"type\":\"quick_list\",\"data\":{\"quick_list_name\":\"Staff\",\"col\":4}},{\"id\":\"mQ57GLzWVP\",\"type\":\"quick_list\",\"data\":{\"quick_list_name\":\"Class\",\"col\":4}},{\"id\":\"3nUXsURjU-\",\"type\":\"quick_list\",\"data\":{\"quick_list_name\":\"Exam Hall\",\"col\":4}}]",
"content": "[{\"id\":\"7w-Gz8ZpX6\",\"type\":\"header\",\"data\":{\"text\":\"<span class=\\\"h4\\\">Home</span>\",\"col\":12}},{\"id\":\"DEz5-1WRQ6\",\"type\":\"shortcut\",\"data\":{\"shortcut_name\":\"Exam\",\"col\":3}},{\"id\":\"J6E7ouMV20\",\"type\":\"spacer\",\"data\":{\"col\":12}},{\"id\":\"nryCoa8NMT\",\"type\":\"quick_list\",\"data\":{\"quick_list_name\":\"Staff\",\"col\":4}},{\"id\":\"mQ57GLzWVP\",\"type\":\"quick_list\",\"data\":{\"quick_list_name\":\"Class\",\"col\":4}},{\"id\":\"3nUXsURjU-\",\"type\":\"quick_list\",\"data\":{\"quick_list_name\":\"Exam Hall\",\"col\":4}}]",
"creation": "2023-03-26 10:18:07.334942",
"docstatus": 0,
"doctype": "Workspace",
@ -11,7 +11,7 @@
"is_hidden": 0,
"label": "Home",
"links": [],
"modified": "2023-03-26 10:38:50.370737",
"modified": "2023-03-26 10:57:26.579454",
"modified_by": "Administrator",
"module": "Exam Helper",
"name": "Home",
@ -35,6 +35,14 @@
],
"roles": [],
"sequence_id": 8.0,
"shortcuts": [],
"shortcuts": [
{
"color": "Grey",
"doc_view": "List",
"label": "Exam",
"link_to": "Exam",
"type": "DocType"
}
],
"title": "Home"
}