示例#1
0
文件: utils.py 项目: pratz/Code
def get_organization(organization_domain=SITE_DOMAIN):
    """ Function to get project domain """
    try :
        organization = DomainOrganizationModel.objects.get(domain__name=organization_domain,is_active=True)
    except Exception, e :
        LOGGER.error('Failed to get organization for domain %s.' % organization_domain + str(e))
        organization = None
示例#2
0
文件: utils.py 项目: pratz/Code
def get_entity_by_name(name=''):
    """ Function to get entity by name """
    try :
        entity_list = EntityModel.objects.filter(entitytranslationmodel__name__icontains=name,
                is_active=True,is_delete=False)
    except Exception, e :
        LOGGER.error('Failed to get entity for name %s. ' % name + str(e))
        entity_list = []
示例#3
0
文件: utils.py 项目: pratz/Code
def get_token_by_exhibitor(organization=None,language=None,exhibitor=None) :
    """ Function to get exhibitor tokens by exhibitor """
    status = True
    try :
        exhibitor_token = ExhibitorTokenModel.objects.get(exhibitor=exhibitor)
    except Exception, e :
        LOGGER.error('Failed to get exhibitor tokens.' + str(e))
        status = False
        exhibitor_token = None
示例#4
0
文件: utils.py 项目: pratz/Code
def get_language(code=LANGUAGE_CODE) :
    """ Fucntion to get project language """

    try :
        language = LanguageModel.objects.get(code=code)
    except Exception, e :
        LOGGER.error('Failed to get language for language code %s.' % code + str(e))
        language = None
        sys.exit(1)
示例#5
0
文件: args.py 项目: pratz/Code
def check_option(option):
    """ Function to check if give option is as per python standards """
    status = True
    try:
        request_option = eval(option)
    except Exception, e:
        LOGGER.error("Failed to covert to Python standards.")
        status = False
        request_option = []
示例#6
0
文件: utils.py 项目: pratz/Code
def get_exhibitor_by_event_n_entity(organization=None,language=None,event=None,entity=None) :
    """ Function to get exhibitor by event and entity """

    status = True
    try :
        exhibitor = ExhibitorModel.objects.get(event=event,entity=entity,
                is_active=True,is_delete=False)
    except Exception, e :
        LOGGER.error('Failed to get Exhibitor. ' + str(e))
        status = False
示例#7
0
文件: utils.py 项目: pratz/Code
def get_event_by_id(organization=None,language=None,event_id=EVENT_ID) :
    """ Function to get event with id """

    try :
        event = EventModel.objects.get(id=event_id,is_active=True,
                event_name__organization=organization)
    except Exception, e :
        LOGGER.error('Failed to get event with id %s. ' % event_id + str(e))
        event = None
        sys.exit(1)
示例#8
0
文件: args.py 项目: pratz/Code
def args_three(args_list):
    """ Function to return element three of sys args """

    status = True
    try:
        three = args_list[3]
    except Exception, e:
        LOGGER.error("Failed to get element 3 for sys args")
        three = ""
        status = False
示例#9
0
文件: args.py 项目: pratz/Code
def args_two(args_list):
    """ Function to return element two of sys args """

    status = True
    try:
        two = args_list[2]
    except Exception, e:
        LOGGER.error("Failed to get element 2 for sys args")
        two = ""
        status = False
示例#10
0
文件: utils.py 项目: pratz/Code
def open_file(file,mode='r'):
    """ Function to open a file """
    status = True
    try :
        file_object = open(file,mode)
    except :
        LOGGER.error('Failed to open File.')
        file_object = None
        status = False

    return status, file_object
示例#11
0
文件: args.py 项目: pratz/Code
def check_number(option):
    """ Function to check ranges """
    status = True
    try:
        for tup in option:
            if not len(tup) == 2:
                status = False
            if tup[0] > tup[1]:
                status = False
    except Exception, e:
        LOGGER.error("Token Ranges not proper.")
        status = False
示例#12
0
文件: connection.py 项目: pratz/Code
def connect(path=PROJECT_PATH,settings=PROJECT_SETTINGS):
    """ Function to set system path and django settings module """

    # check for empty settings
    check_path(path)
    check_settings(settings)

    try :
        sys.path.append(path)
        sys.path.append(os.path.abspath(os.path.join(os.path.abspath(path),os.path.pardir)))
    except Exception, e :
        LOGGER.error("Failed to set project path in OS sys path. " + str(e))
        sys.exit(1)
示例#13
0
文件: args.py 项目: pratz/Code
def check_format(option):
    """ Function to check format """

    status = True
    try:
        if not isinstance(option, ListType):
            status = False

        for tup in option:
            if not isinstance(tup, TupleType):
                status = False
            if not isinstance(tup[0], IntType) or not isinstance(tup[1], IntType):
                status = False

    except Exception, e:
        LOGGER.error("Formatting error.")
        status = False
        request_option = []
示例#14
0
文件: utils.py 项目: pratz/Code
def add_token_to_exhibitor(organization=None,language=None,exhibitor_token=None,token_range=[]):
    """ Function to add exhibitor_token """

    range_dict = {}
    status = True
    try :
        current_tokens = json.loads(exhibitor_token.tokens)

        for i in token_range :
            for x in range(i[0],i[1]+1) :
                range_dict.update({ x: 0})

        current_tokens = dict( current_tokens.items() + range_dict.items() )
        exhibitor_token.tokens = json.dumps(current_tokens)
        exhibitor_token.save()

    except Exception,e :
        LOGGER.error('Failed to add exhibitor token.' + str(e))
        status = False
示例#15
0
文件: connection.py 项目: pratz/Code
# Connecting / Settings up system path and django settings module

# python imports
import os, sys

# project imports
from standalone.config import PROJECT_PATH, PROJECT_SETTINGS, LOGGER
from standalone.validation import check_path, check_settings


def connect(path=PROJECT_PATH,settings=PROJECT_SETTINGS):
    """ Function to set system path and django settings module """

    # check for empty settings
    check_path(path)
    check_settings(settings)

    try :
        sys.path.append(path)
        sys.path.append(os.path.abspath(os.path.join(os.path.abspath(path),os.path.pardir)))
    except Exception, e :
        LOGGER.error("Failed to set project path in OS sys path. " + str(e))
        sys.exit(1)

    try :
        os.environ['DJANGO_SETTINGS_MODULE'] = settings
    except Exception, e :
        LOGGER.error("Failed to set project settings in OS environment. " + str(e))
        sys.exit(1)