On WIMS, a Class is the main structure. Each class contains its own Users, Sheets, Exercises and Exams.
## Instantiation
To get a Class instance, you have two possibility. You can either create a new instance, or get one from the WIMS server.
To create a new instance, you’ll need an User to use as a supervisor.
from wimsapi import Class, User
= User("quser", "lastname", "firstname", "password", "mail@mail.com")
user = Class("rclass", "Title", "Institution", "mail@mail.com", "password", user) c
Note: The quser of the User used to create the supervisor does not matter, it will be overwritten with “supervisor” as soon as the class is saved.
Class can also take a lot of optionnal argument:
Class(rclass, name, institution, email, password, supervisor, qclass=None, lang="en", expiration=None, limit=30, level="H4", secure='all', bgcolor='', refcolor='', css='')
Where:
if provided, qclass will be the identifier of the newly created WIMS class when this instance is saved. The identifier is randomly chosen by the WIMS server if qclass is not provided.
To get an instance from the WIMS server, you can use the class method :
Class.get(url, ident, passwd, qclass, rclass)
Where :
url
is the url to the WIMS server’s cgi (eg.
https://wims.unice.fr/wims/wims.cgi).ident
and password
are credentials as
defined in [WIMS_HOME]/log/classes/.connections/
(see configuration)qclass
is the ID of the class on the WIMS
server (name of the directory corresponding to the class in
[WIMS_HOME]/log/classes/[ID]
)rclass
the identifier corresponding to the class
(again, see configuration).Any changes made to a Class instance can be
reflected on the WIMS server with the method
save()
:
from wimsapi import Class
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = "Another institution"
c.institution c.save()
If the Class has been instantiated through its
constructor, and not with Class.get()
method, and has not
been saved yet, you will need to provide the server’s url, ident, and
passwd (see configuration) :
= Class("myclass", "Title", "Institution", "mail@mail.com", "password", user)
c "https://wims.unice.fr/wims/wims.cgi", "myself", "toto")
c.save(= "Another institution"
c.institution c.save()
To reflect server-side changes on an instance of
Class, use refresh()
:
= Class(9999, "myclass", "Title", "Institution", "mail@mail.com", "password", supervisor)
c "https://wims.unice.fr/wims/wims.cgi", "myself", "toto")
c.save(
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c2
= "Another institution"
c.institution
c.save()
# "Institution"
c2.institution
c2.refresh()# "Another institution" c2.institution
To delete an already saved Class, simply use
delete()
:
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c c.delete()
You can obtain the list of every classes of a server using a
particular rclass with :
Class.list(url, ident, passwd, rclass)
list("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", "myclass") Class.
Once the Class has been saved you can acceed the
additionnal fields ident
, passwd
,
url
and infos
:
= Class(999999, "myclass", "Title", "Institution", "mail@mail.com", "password", user)
c "https://wims.unice.fr/wims/wims.cgi", "myself", "toto")
c.save(# "myself"
c.ident # "toto"
c.passwd # "https://wims.unice.fr/wims/wims.cgi"
c.url
c.infos# {
# 'query_class': '999999', 'rclass': 'myclass', 'password': 'password',
# 'creator': '172.17.0.1', 'secure': 'all', 'external_auth': '',
# 'mixed_external_auth': '', 'cas_auth': '', 'php_auth': '',
# 'authidp': '', 'supervisor': 'Firstname Lastname',
# 'description': 'Title', 'institution': 'Institution', 'lang': 'en',
# 'email': 'mail@mail.com', 'expiration': '20191127', 'limit': '30',
# 'topscores': '', 'superclass': '', 'type': '0', 'level': 'H4',
# 'parent': '', 'typename': 'class', 'bgcolor': '', 'bgimg': '',
# 'scorecolor': '#ffffff, #ff0000, #ff0000, #ff0000, #ffa500, #ffa500,
# #fff500, #d2ff00, #b9ff00, #2fc42f, #259425',
# 'css': '-theme-', 'logo': '', 'logoside': '', 'refcolor': '',
# 'ref_menucolor': '', 'ref_button_color': '', 'ref_button_bgcolor': '',
# 'ref_button_help_color': '', 'ref_button_help_bgcolor': '',
# 'theme': 'standard', 'theme_icon': '', 'sendmailteacher': '',
# 'connections': '+myself/myclass+ ', 'creation': '20181127',
# 'userlist': [''], 'usercount': '0', 'examcount': '0', 'sheetcount': '0'
# }
Class has 4 methods allowing it to interact with its User, Sheets, Exercises and Exams.
You can add an item with the method additem(item)
, where
item is an instance of User, Sheets, Exercises or Exams.
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = User("quser", "lastname", "firstname", "password", "mail@mail.com")
user c.additem(user)
You can retrieve an item with the method
getitem(identifier, cls)
, where cls is the python
class User, Sheets, Exercises or Exams, and
identifier it’s ID on the WIMS class.
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = User("quser", "lastname", "firstname", "password", "mail@mail.com")
user
c.additem(user)= c.getitem("quser", User) u
You can delete an item from a WIMS class with the method
delitem(item, cls=None)
. Item must be either an
instance of User, Sheets,
Exercises or Exams ; or
string. If item is a string, cls must be provided and be the
corresponding python class.
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = User("quser", "lastname", "firstname", "password", "mail@mail.com")
user
c.additem(user)
c.delitem(user)# OR
"quser", User) c.delitem(
You can check if an item is in a WIMS class with the method
checkitem(item, cls=None)
. Item must be either an
instance of User, Sheets,
Exercises, Exams, or
string. If item is a string, cls must be provided and be the
corresponding python class.
This method returns True if the item is present in the WIMS class, False otherwise.
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = User("quser", "lastname", "firstname", "password", "mail@mail.com")
user = User("unknown", "lastname", "firstname", "password", "mail@mail.com")
unknown
c.additem(user)
# True
c.checkitem(user) # False
c.checkitem(unknown) # OR
"quser", User) # True
c.checkitem("unknown", User) # False c.checkitem(
You can also use item in class
operator, where item is
an instance of User, Sheets, Exercises or Exams.
in c # True
user in c # False unknown
You can list every item in a WIMS class with the method
listitem(cls)
. cls
must be the python’s class
corresponding to the item to be listed.
This method returns a list of instances of cls
.
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = c.listitem(User)
users = c.listitem(Sheet) sheets