示例#1
0
    def get_student(self, id_or_card_number):
        # LiU-ID is normally 8 chars long (or 5 chars for some employees)
        valid_pid = format_pid(id_or_card_number)
        if valid_pid:
            return self.get_student_by_pid(format_kobra_pid(valid_pid))

        if len(id_or_card_number) <= 8:
            return self.get_student_by_liu_id(id_or_card_number)
        return self.get_student_by_card(id_or_card_number)
def try_get_from_kobra(pid, liu_id):
    student = None

    if pid:
        try:
            student = client.get_student_by_pid(pid=format_kobra_pid(pid))
        except StudentNotFound:
            pass
    elif liu_id:
        try:
            student = client.get_student_by_liu_id(liu=liu_id)
        except StudentNotFound:
            pass

    if student:
        return Visitor(**get_kwargs(student))
    return None
示例#3
0
文件: models.py 项目: LinTek/SOF13
 def send_as_email(self):
     person = self.person
     person.formatted_pid = format_kobra_pid(person.pid)
     send_mail('tickets/mail/ticket', [person.email], {'ticket': self, 'person': person})
     self.is_sent_as_email = True
     self.save()
示例#4
0
文件: models.py 项目: LinTek/SOF13
 def generate_data(self):
     self.token = os.urandom(20).encode('hex')
     self.due_date = datetime.date.today() + datetime.timedelta(days=14)
     self.ocr = 'sof-%s' % format_kobra_pid(self.person.pid, dash=False)
示例#5
0
from django.conf import settings

from sof.functionary.models import Worker
from sof.utils.forms import format_kobra_pid
from sof.utils.kobra_client import KOBRAClient, StudentNotFound

client = KOBRAClient(settings.KOBRA_USER, settings.KOBRA_KEY)

for worker in Worker.objects.order_by('first_name', 'last_name'):
    if not worker.liu_id:
        print worker.get_full_name()

        try:
            student = client.get_student_by_pid(format_kobra_pid(worker.pid))

            worker.lintek_member = (student.get('union') == 'LinTek')
            worker.liu_id = student.get('liu_id')
            worker.rfid_number = student.get('rfid_number')
            worker.barcode_number = student.get('barcode_number')
            worker.save()

        except StudentNotFound:
            print '  !!! Not found'