The first time a Sheet is saved in a Class, the corresponding instance of the class is
then link to the Sheet through the .wclass
attribute. This allow to use some methods such as delete()
or save()
without any argument.
The instance of Class is also link to a
Sheet obtained through Class.getitem()
or
Sheet.get()
.
## Instantiation
To get a Sheet instance, you have two possibility. You can either create a new instance, or get one from the WIMS server.
To create a new instance :
from wimsapi import Sheet
= Sheet("Title", "Description") sheet
Sheet can also take a lot of optionnal argument:
Sheet(title, description, expiration=None, sheetmode=0, weight=1, formula=2, indicator=1, contents="")
Where:
To get an instance from the WIMS server, you can use either of the following class method :
Sheet.get(wclass, qsheet)
Where :
wclass
is an instance of Class
which the Sheet belong to.Sheet
is the identifier corresponding to the
sheet.or
c.getitem(qsheet, Sheet)
Where :
c
is an instance of Class which
the Sheet belong to.qsheet
is the identifier corresponding to the
sheet.Sheet
the Sheet class.Any changes made to a Sheet instance can be
reflected on the WIMS server with the method
save()
:
from wimsapi import Class, Sheet
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = Sheet.get(c, "qsheet")
s = "Newname"
s.firstname s.save()
If the Sheet has been instantiated through its
constructor, and not with one of the get
method, and has
not been saved yet, you will need to provide a Class which had already been saved on the
server.
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = Sheet("qsheet", "lastname", "firstname", "password", "mail@mail.com")
s s.save(c)
To add an Sheet to a Class, you can
also use c.additem(sheet)
.
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = Sheet("qsheet", "lastname", "firstname", "password", "mail@mail.com")
s c.additem(s)
In fact, c.additem(sheet)
will call
sheet.save(c)
, therefore if a same sheet is added to
multiple classes through s.save(c)
or
c.additem(s)
, future call to s.save()
will
only save changed on the last Class the Sheet has been saved to.
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 8888, "myclass")
c2 = Sheet("qsheet", "lastname", "firstname", "password", "mail@mail.com")
s
c.additem(s)
s.save(c2)= "Newname"
s.firstname # Only save changes on c2 s.save()
To reflect server-side changes on an instance of
Sheet, use refresh()
:
= "Old"
s.title
c.save(s)
= c.getitem(s.qsheet, Sheet)
s2
= "New"
s2.title
s2.save()
# "Old"
s.institution
s.refresh()# "New" s.institution
To delete an already saved Sheet s
from
a Class c
, you have a lot
possibility:
s.delete()
Sheet.delete(c, s)
Sheet.delete(c, "qsheet")
where
"qsheet" == s.qsheet
c.delitem(s)
c.delitem("qsheet", Sheet)
where
"qsheet" == s.qsheet
To check whether Sheet u
is in a Class c
, you have once again a lot of
possibility:
Sheet.check(c, s)
Sheet.check(c, "qsheet")
where
"qsheet" == s.qsheet
c.checkitem(s)
c.checkitem("qsheet", Sheet)
where
"qsheet" == s.qsheet
s in c
All of these methods return True
if the sheet exists in
the class, False
otherwise.
Once the Sheet has been saved you can acceed the
additionnal fields infos
and wclass
which is
the instance of Class this sheet is saved on:
= Class.get("https://wims.unice.fr/wims/wims.cgi", "myself", "toto", 9999, "myclass")
c = Sheet("Title", "Description")
s
c.additem(s)
== c # True
s.wclass
c.infos