Example #1
0
def get_new_ticket_RT_info(uid, recId):
    response = {}
    response["resultCode"] = 0
    if BIBCATALOG_SYSTEM is None:
        response["description"] = "<!--No ticket system configured-->"
    elif BIBCATALOG_SYSTEM and uid:
        bibcat_resp = BIBCATALOG_SYSTEM.check_system(uid)
        if bibcat_resp == "":
            # add available owners
            users = []
            users_list = list_registered_users()
            for user_tuple in users_list:
                try:
                    user = {"username": get_user_preferences(user_tuple[0])["bibcatalog_username"], "id": user_tuple[0]}
                except KeyError:
                    continue
                users.append(user)
            response["users"] = users
            # add available queues
            response["queues"] = BIBCATALOG_SYSTEM.get_queues(uid)
            # add user email
            response["email"] = get_email(uid)
            # TODO try catch
            response["ticketTemplates"] = load_ticket_templates(recId)
            response["resultCode"] = 1
        else:
            # put something in the tickets container, for debug
            response["description"] = "Error connecting to RT<!--" + bibcat_resp + "-->"
    return response
Example #2
0
def get_new_ticket_RT_info(uid, recId):
    response = {}
    response['resultCode'] = 0
    if BIBCATALOG_SYSTEM is None:
        response['description'] = "<!--No ticket system configured-->"
    elif BIBCATALOG_SYSTEM and uid:
        bibcat_resp = BIBCATALOG_SYSTEM.check_system(uid)
        if bibcat_resp == "":
            # add available owners
            users = []
            users_list = list_registered_users()
            for user_tuple in users_list:
                try:
                    user = {'username': get_user_preferences(user_tuple[0])['bibcatalog_username'],
                        'id': user_tuple[0]}
                except KeyError:
                    continue
                users.append(user)
            response['users'] = users
            # add available queues
            response['queues'] = BIBCATALOG_SYSTEM.get_queues(uid)
            # add user email
            response['email'] = get_email(uid)
            # TODO try catch
            response['ticketTemplates'] = load_ticket_templates(recId)
            response['resultCode'] = 1
        else:
            # put something in the tickets container, for debug
            response['description'] = "Error connecting to RT<!--" + bibcat_resp + "-->"
    return response
Example #3
0
def task_check_options():
    """ Reimplement this method for having the possibility to check options
    before submitting the task, in order for example to provide default
    values. It must return False if there are errors in the options.
    """
    if not task_get_option('new') \
            and not task_get_option('modified') \
            and not task_get_option('recids') \
            and not task_get_option('collections')\
            and not task_get_option('reportnumbers'):
        print >>sys.stderr, 'Error: No records specified, you need' \
            ' to specify which records to run on'
        return False

    ticket_plugins = {}
    all_plugins, error_messages = load_ticket_plugins()

    if error_messages:
        # We got broken plugins. We alert only for now.
        print >>sys.stderr, "\n".join(error_messages)

    if task_get_option('tickets'):
        # Tickets specified
        for ticket in task_get_option('tickets'):
            if ticket not in all_plugins.get_enabled_plugins():
                print ticket
                print >>sys.stderr, 'Error: plugin %s is broken or does not exist'
                return False
            ticket_plugins[ticket] = all_plugins[ticket]
    elif task_get_option('all-tickets'):
        ticket_plugins = all_plugins.get_enabled_plugins()
    else:
        print >>sys.stderr, 'Error: No tickets specified, you need' \
            ' to specify at least one ticket type to create'
        return False

    task_set_option('tickets', ticket_plugins)

    if not BIBCATALOG_SYSTEM:
        print >>sys.stderr, 'Error: no cataloging system defined'
        return False

    res = BIBCATALOG_SYSTEM.check_system()
    if res:
        print >>sys.stderr, 'Error while checking cataloging system: %s' % \
            (res,)
    return True
Example #4
0
def task_check_options():
    """ Reimplement this method for having the possibility to check options
    before submitting the task, in order for example to provide default
    values. It must return False if there are errors in the options.
    """
    if not task_get_option('new') \
            and not task_get_option('modified') \
            and not task_get_option('recids') \
            and not task_get_option('collections')\
            and not task_get_option('reportnumbers'):
        print >>sys.stderr, 'Error: No records specified, you need' \
            ' to specify which records to run on'
        return False

    ticket_plugins = {}
    all_plugins, error_messages = load_ticket_plugins()

    if error_messages:
        # We got broken plugins. We alert only for now.
        print >>sys.stderr, "\n".join(error_messages)

    if task_get_option('tickets'):
        # Tickets specified
        for ticket in task_get_option('tickets'):
            if ticket not in all_plugins.get_enabled_plugins():
                print ticket
                print >>sys.stderr, 'Error: plugin %s is broken or does not exist'
                return False
            ticket_plugins[ticket] = all_plugins[ticket]
    elif task_get_option('all-tickets'):
        ticket_plugins = all_plugins.get_enabled_plugins()
    else:
        print >>sys.stderr, 'Error: No tickets specified, you need' \
            ' to specify at least one ticket type to create'
        return False

    task_set_option('tickets', ticket_plugins)

    if not BIBCATALOG_SYSTEM:
        print >>sys.stderr, 'Error: no cataloging system defined'
        return False

    res = BIBCATALOG_SYSTEM.check_system()
    if res:
        print >>sys.stderr, 'Error while checking cataloging system: %s' % \
            (res,)
    return True
Example #5
0
    def tmpl_your_tickets(self, uid, ln=CFG_SITE_LANG, start=1):
        """ make a pretty html body of tickets that belong to the user given as param """
        ln = wash_language(ln)
        _ = gettext_set_language(ln)
        if BIBCATALOG_SYSTEM is None:
            return _("Error: No BibCatalog system configured.")
        #errors? tell what happened and get out
        bibcat_probs = BIBCATALOG_SYSTEM.check_system(uid)
        if bibcat_probs:
            return _("Error")+" "+bibcat_probs

        tickets = BIBCATALOG_SYSTEM.ticket_search(uid, owner=uid) # get ticket id's
        lines = "" # put result here
        i = 1

        lines += (_("You have %(x_num)i tickets.", x_num=len(tickets))) + "<br/>"

        #make a prev link if needed
        if (start > 1):
            newstart = start - self.SHOW_MAX_TICKETS
            if (newstart < 1):
                newstart = 1
            lines += '<a href="/yourtickets/display?start='+str(newstart)+'">'+_("Previous")+'</a>'
        lines += """<table border="1">"""
        lastshown = len(tickets) # what was the number of the last shown ticket?
        for ticket in tickets:
            #get info and show only for those that within the show range
            if (i >= start) and (i < start+self.SHOW_MAX_TICKETS):
                ticket_info = BIBCATALOG_SYSTEM.ticket_get_info(uid, ticket)
                subject = ticket_info['subject']
                status = ticket_info['status']
                text = ""
                if 'text' in ticket_info:
                    text = ticket_info['text']
                display = '<a href="'+ticket_info['url_display']+'">'+_("show")+'</a>'
                close = '<a href="'+ticket_info['url_close']+'">'+_("close")+'</a>'
                lines += "<tr><td>"+str(ticket)+"</td><td>"+subject+" "+text+"</td><td>"+status+"</td><td>"+display+"</td><td>"+close+"</td></tr>\n"
                lastshown = i
            i = i+1
        lines += "</table>"

        #make next link if needed
        if (len(tickets) > lastshown):
            newstart = lastshown+1
            lines += '<a href="/yourtickets/display?start='+str(newstart)+'">'+_("Next")+'</a>'
        return lines