ddsf documentation

Python library to work with DSF

installation

pip install ddsf

quick start

First of all we need to initiate the connection to dsf. The Ddsf object is our entrypoint, from which we can obtain all other objects.

from ddsf import Ddsf
# create auth object
# ntlm
from requests_ntlm import HttpNtlmAuth
auth = HttpNtlmAuth(user, password)
# or basic
from requests.auth import HTTPBasicAuth
auth =  HTTPBasicAuth(user, password)
# inititate connection
dsf = Ddsf(url, auth)

The following example uses ddsf.UserAccount to demonstrate the key features of this module. All classes that derive from ddsf.Resource behave similar.

The methods patch(), delete() and post() correspond to http-methods and return a requests.Response object.

get

Get a ddsf.UserAccount by username

user = dsf.user("tadao.kikumoto")

Get all Attributes

# unprettified
print(user.data)
# prettified
print(user)
print(user.pretty())

You can access each attribute inside the data dictionary as it would be a member of the class itself. See: ddsf.Resource.__getattr__()

# instead of
print(user.data['EMailAddress'])
# use
print(user.EMailAddress)

patch

This notation can also be used to change data. See: ddsf.Resource.__setattr__()

user.EMailAddress = "tadao303@roland.com"
user.PasswordNeverExpires = True

The edited data remains locally until you send a request to dsf. This can be done with ddsf.Resource.patch()

user.patch()

delete

To delete a user use ddsf.Resource.delete()

user.delete()

post

To add a new object to dsf we use ddsf.Resource.post(). For simplicity we are not adding a UserAccount, but an OrgUnit

typeId = dsf.orgUnitType("OrgUnitTypeName eq 'Bereich'").OrgUnitTypeId
newOu= {
    "OrgUnitName": "Bereich Mathematik und Naturwissenschaften",
    "OrgUnitNumber": 10001175,
    "OrgUnitType": typeId,
}
newOrgUnit = OrgUnit(dsf.url, dsf.session, newOu)
newOrgUnit.post()

api

class ddsf.AcademicTitle(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.Achievement(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.Activity(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.ActorToActorType(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

delete()[source]

delete ActorToActorType. This method is overloaded because 2 ids are neccessary to delete an element

patch()[source]

patch ActorToActorType

Example:

at = dsf.user("ljurk").actorTypes()[0]
at.Active = True
at.patch()
class ddsf.ActorType(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.CommunicationNumber(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

delete()[source]

delete CommunicationNumber. This method is overloaded because 3 ids are neccessary to patch an element

patch()[source]

patch CommunicationNumber. This method is overloaded because 3 ids are neccessary to patch an element

class ddsf.Ddsf(url, auth)[source]

object that stores session

Parameters:
  • url – dsf url
  • auth – auth object: HTTPBasicAuth or HttpNtlmAuth
__init__(url, auth)[source]

Initialize self. See help(type(self)) for accurate signature.

__weakref__

list of weak references to the object (if defined)

actorToActorTypes(filter=None)[source]

get Mappings between an Actor and an ActorType

Parameters:filter – dsf filter
Returns:list of ActorToActorTypes
Return type:list[ActorToActorType]
actorTypes()[source]

get list of all ActorTypes

Returns:list of ActorTypes
Return type:list[ActorType]
connectdb(host, database, user, password)[source]

initialize database connection for the use of non-dsf functions

mailingListActor(id)[source]

get all Members of a MailingList

Parameters:id (int) – id of the mailingList
Returns:all Members
Return type:list[MailingListActor]
mailingListId(name)[source]

get MailingListId of a given MailingListName

Parameters:name (str) – name of the MailingList
Returns:id of the MailingList
Return type:MailingListId(int)
orgUnitType(filter='')[source]

get all available orgUnitTypes

Returns:a list of OrgUnitType
Return type:list[OrgUnitType]
orgUnitTypes()[source]

get all available orgUnitTypes

Returns:a list of OrgUnitType
Return type:list[OrgUnitType]
orgUnits(filter='IsDeleted eq false')[source]

get all available orgUnits

Returns:a list of OrgUnits
Return type:list[OrgUnit]
room(id, full=False)[source]

get a specific room

Parameters:
  • id – RoomId to search for
  • full – if True it will replace RoomType with the corresponding object
Returns:

Room with the given id

Return type:

Room

roomTypes()[source]

get all available roomTypes

Returns:a list of RoomType
Return type:list[RoomType]
rooms()[source]

get all available rooms

Returns:a list of Room
Return type:list[Room]
student(matric)[source]

find a student by matriculation number

Parameters:matric (int) – matriculationNumber
Returns:a student object
Return type:Student
studentByPersonId(personId)[source]

find a student by personId

Parameters:personId (int) – personId
Returns:a student object
Return type:Student
study(studyid)[source]

find a study by studyid

Parameters:studyid – studyid
Returns:a Studies object
Return type:Studies
studyProcessStudies(personid)[source]

get StudyProcessStudies of a person

Parameters:personid (int) – id of a person
Returns:a StudyProcessStudies object
Return type:StudyProcessStudies
user(username)[source]

find a user by username

Parameters:username – zih-login
Returns:a user object
Return type:UserAccount
userGroup(name)[source]

find a usergroup by name

Parameters:name – name of the group
Returns:a usergroup object
Return type:UserGroup
userGroups()[source]

get all usergroups

class ddsf.MailingList(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.MailingListActor(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.ModuleOfferingRegistration(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

delete()[source]

delete ModuleOfferingRegistration. This method is overloaded because 2 ids are neccessary to delete an element

class ddsf.OrgUnit(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.OrgUnitType(url, session, data=None, db=None)[source]
class ddsf.Payment(url, session, data=None, db=None)[source]
class ddsf.Person(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

actorTypes()[source]

get all ActorTypes of a user

Returns:a list of Users ActorTypes
Return type:list[ActorToActorType]
class ddsf.Resource(url, session, data=None, db=None)[source]

base object for all Resources

session

requests session

Type:requests.Session
data

all userData is stored inside this dict

Type:dict
url

dsf base url

db

db connection used by username()

__getattr__(item)[source]

tries to return members of the data dict

Example

instead of accessing the data like

user.data['UserAccount']

use this notation:

user.UserAccount
__init__(url, session, data=None, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

__len__()[source]

returns length of data dict

__setattr__(name, value)[source]

set value inside data dict

Example

instead of changing data like this:

person.data['FirstName'] = "Tadao"

use this notation:

person.FirstName = "Tadao"
__str__()[source]

is called when you print the object

Returns:prettyprinted data dict
Return type:str
__weakref__

list of weak references to the object (if defined)

delete()[source]

delete object from entity

patch()[source]

patch object

Example:

person = dsf.person(123)
person.FirstName = "Klaus"
person.patch()
post()[source]

post data to dsf-entity. You can create a new object and then call its post() method to create it in dsf.

Returns:request object
Return type:requests.Response

Example

This Example creates a new CommunicationNumber and creates it in dsf:

data = {"Actor": user.ActorId,
        "CommunicationType": 7,
        "CommunicationNumberValue": ldapData['mail']}
mail = CommunicationNumber(self.dsf.url, self.dsf.session, data)
mail.post()
pretty(sort=False)[source]

pretty print data dict

Returns:prettyprinted data dict
Return type:str
serialize(obj)[source]

this method is used by json.dumps() to serialize

class ddsf.Room(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.RoomType(url, session, data=None, db=None)[source]
class ddsf.Student(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

isActive()[source]

check if student is immatriculated

Returns:True=immatriculated; False=exmatriculated
Return type:status(bool)
class ddsf.Studies(url, session, data=None, db=None)[source]
class ddsf.StudiesProlongation(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.StudyProcessStudies(url, session, data=None, db=None)[source]
class ddsf.Teacher(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.TeacherOrgUnit(url, session, data={}, db=None)[source]
__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class ddsf.UserAccount(url, session, data={}, db=None)[source]

represents UserAccount() entity

__init__(url, session, data={}, db=None)[source]

Initialize self. See help(type(self)) for accurate signature.

actorTypes()[source]

get all ActorTypes of a user

Returns:a list of Users ActorTypes
Return type:list[ActorToActorType]
basedata(FirstName, LastName, BirthDate, BirthPlace, genderId=0, titleId=0, BirthName='')[source]

change basedata of the UserAccount via database

FirstName
Type:str
LastName
Type:str
BirthDate

1987-01-25 or 19870125

Type:int or str
BirthPlace
Type:str
genderId
Type:int
titleId
Type:int
privateMail()[source]

get privateMail of the UserAccount

Returns:privateMail
Return type:CommunicationNumber
resetLoginAttempts()[source]

Set NumberOfFailedLoginAttempts to 0 set FailedLoginAttemptsExceeded to False

uniMail()[source]

get uniMail of the UserAccount

Returns:uniMail
Return type:CommunicationNumber
username(username)[source]

change username of the UserAccount via database

username[source]

new username for the user

Type:str
class ddsf.UserGroup(url, session, data=None, db=None)[source]
class ddsf.datetime(year, month, day[, hour[, minute[, second[, microsecond[, tzinfo]]]]])[source]

The year, month and day arguments are required. tzinfo may be None, or an instance of a tzinfo subclass. The remaining arguments may be ints.

__add__

Return self+value.

__eq__

Return self==value.

__ge__

Return self>=value.

__getattribute__

Return getattr(self, name).

__gt__

Return self>value.

__hash__

Return hash(self).

__le__

Return self<=value.

__lt__

Return self<value.

__ne__

Return self!=value.

__new__()

Create and return a new object. See help(type) for accurate signature.

__radd__

Return value+self.

__reduce__() -> (cls, state)
__reduce_ex__(proto) -> (cls, state)
__repr__

Return repr(self).

__rsub__

Return value-self.

__str__

Return str(self).

__sub__

Return self-value.

astimezone()

tz -> convert to local time in new timezone tz

combine()

date, time -> datetime with same date and time fields

ctime()

Return ctime() style string.

date()

Return date object with same year, month and day.

dst()

Return self.tzinfo.dst(self).

fromisoformat()

string -> datetime from datetime.isoformat() output

fromtimestamp()

timestamp[, tz] -> tz’s local time from POSIX timestamp.

isoformat()

[sep] -> string in ISO 8601 format, YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM]. sep is used to separate the year from the time, and defaults to ‘T’. timespec specifies what components of the time to include (allowed values are ‘auto’, ‘hours’, ‘minutes’, ‘seconds’, ‘milliseconds’, and ‘microseconds’).

now()

Returns new datetime object representing current time local to tz.

tz
Timezone object.

If no tz is specified, uses local timezone.

replace()

Return datetime with new specified fields.

strptime()

string, format -> new datetime parsed from a string (like time.strptime()).

time()

Return time object with same time but with tzinfo=None.

timestamp()

Return POSIX timestamp as float.

timetuple()

Return time tuple, compatible with time.localtime().

timetz()

Return time object with same time and tzinfo.

tzname()

Return self.tzinfo.tzname(self).

utcfromtimestamp()

Construct a naive UTC datetime from a POSIX timestamp.

utcnow()

Return a new datetime representing UTC day and time.

utcoffset()

Return self.tzinfo.utcoffset(self).

utctimetuple()

Return UTC time tuple, compatible with time.localtime().

Indices and tables