예제 #1
0
def claim_sponsor(request, mess_string):
    sponsor_id = mess.decode(mess_string)
    # try:
    s = NewSponsor.objects.get(id=int(mess_string))
    # except ObjectDoesNotExist:
    #     s = None
    result = {}
    name = request.GET.get('name')
    cellphone = request.GET.get('cellphone')
    email = request.GET.get('email')
    message = request.GET.get('message')
    if not s or \
     not name or \
     not cellphone or \
     not email:
        result['success'] = False
    else:
        NewOrderMessage.objects.create(event_id = sponsor_id, \
                                        event_name = s.name, \
                                        msg_name = name, \
                                        msg_tel = cellphone, \
                                        msg_email = email, \
                                        msg_content = message, \
                                        msg_addtime = time.time(), \
                                        type=6)
        result['success'] = True
    return HttpResponse(json.dumps(result))
예제 #2
0
파일: sponsor.py 프로젝트: sureboy/xiaorizi
def claim_sponsor(request, mess_string):
    sponsor_id = mess.decode(mess_string)
    try:
        s = NewSponsor.objects.get(pk=sponsor_id)
    except ObjectDoesNotExist:
        s = None
    result = {}
    name = request.POST.get('name', None)
    cellphone = request.POST.get('cellphone', None)
    email = request.POST.get('email', None)
    message = request.POST.get('message', None)
    if not s or \
    not name or \
    not cellphone or \
    not email or \
    not message:
        result['success'] = False
    else:
        NewOrderMessage.objects.create(event_id = sponsor_id, \
                                        event_name = s.name, \
                                        msg_name = name, \
                                        msg_tel = cellphone, \
                                        msg_email = email, \
                                        msg_content = message, \
                                        msg_addtime = time.time(), \
                                        type=6)
        result['success'] = True
    return HttpResponse(json.dumps(result))
예제 #3
0
def view_sponsor(request, mess_string):
    try:
        s = NewSponsor.objects.get(pk=mess.decode(mess_string))
    except ObjectDoesNotExist:
        s = None

    head = {}
    head['title'] = u"未找到指定主办方"

    if s is None:
        events = None
        old_events = None
    else:
        s.intro = s.intro.replace('\n', '<br/>')
        if s.like_count == None:
            s.like_count = 0
        try:
            s.pic_url = s.pic.server.name + s.pic.urls
        except AttributeError:
            s.pic_url = ""

        def calculate(e):
            """
            try:
                #只选取第一个关联地址为展示的地址
                e.place = e.city.all()[0].district_name
            except IndexError:
                e.place = ""
            if e.begin_time and e.end_time:
                e.time_range = str(e.begin_time.month) + "." + str(e.begin_time.day) + "-" + str(e.end_time.day)
            else:
                e.time_range = ''
            return e
            """
            return NewformatEvent(None, e.old_event_id)

        #now = datetime.datetime.now()
        now = timezone.now()
        #检索所有未过期活动,性能假设:每年活动不超过50个
        new_events = s.events.filter(end_time__gt=now) \
                            .filter(isshow_id__in=[1, 8]) \
                            .all().order_by('begin_time')
        events = map(calculate, new_events)
        #检索所有过期活动,可能会过滤一部分
        old_events = map(calculate, s.events.filter(end_time__lt=now) \
                                            .filter(isshow_id__in=[1, 8]) \
                                            .all().order_by('begin_time') \
                                            .reverse())
        s.event_count = s.events.count()

        head = common.sponsor_page_head(s.name, s.intro)

    return render_to_response( \
        'sponsor.html', \
        {'sponsor': s, 'events': events, \
		'old_events': old_events, 'head': head}, \
        context_instance=RequestContext(request)
        )
예제 #4
0
파일: sponsor.py 프로젝트: sureboy/xiaorizi
def view_sponsor(request, mess_string):
    try:
        s = NewSponsor.objects.get(pk=mess.decode(mess_string))
    except ObjectDoesNotExist:
        s = None

    head = {}
    head['title'] = u"未找到指定主办方"

    if s is None:
        events = None
        old_events = None
    else:
        s.intro = s.intro.replace('\n', '<br/>')
        if s.like_count == None:
            s.like_count = 0
        try:
            s.pic_url = s.pic.server.name + s.pic.urls
        except AttributeError:
            s.pic_url = ""

        def calculate(e):
            """
            try:
                #只选取第一个关联地址为展示的地址
                e.place = e.city.all()[0].district_name
            except IndexError:
                e.place = ""
            if e.begin_time and e.end_time:
                e.time_range = str(e.begin_time.month) + "." + str(e.begin_time.day) + "-" + str(e.end_time.day)
            else:
                e.time_range = ''
            return e
            """
            return NewformatEvent(None, e.old_event_id)

        #now = datetime.datetime.now()
        now = timezone.now()
        #检索所有未过期活动,性能假设:每年活动不超过50个
        new_events = s.events.filter(end_time__gt=now) \
                            .filter(isshow_id__in=[1, 8]) \
                            .all().order_by('begin_time')
        events = map(calculate, new_events)
        #检索所有过期活动,可能会过滤一部分
        old_events = map(calculate, s.events.filter(end_time__lt=now) \
                                            .filter(isshow_id__in=[1, 8]) \
                                            .all().order_by('begin_time') \
                                            .reverse())
        s.event_count = s.events.count()

        head = common.sponsor_page_head(s.name, s.intro)

    return render_to_response( \
        'sponsor.html', \
        {'sponsor': s, 'events': events, \
		'old_events': old_events, 'head': head}, \
        context_instance=RequestContext(request)
        )
예제 #5
0
def view_venue(request, mess_string):
    try:
        v = NewVenue.objects.get(pk=mess.decode(mess_string))
    except ObjectDoesNotExist:
        v = None

    head = {}
    head['title'] = u"未找到指定场馆"

    if v is None:
        events = None
        old_events = None
    else:
        if v.content is not None:
            v.content = v.content.replace('\n', '<br/>')
        else:
            v.content = ''
        '''
        try:
            s.pic_url = s.pic.server.name + s.pic.urls
        except AttributeError:
            s.pic_url = ""
        '''
        def calculate(e):
            return NewformatEvent(None, e.old_event_id)

        now = timezone.now()
        #检索所有未过期活动,性能假设:每年活动不超过50个
        new_events = v.neweventtable_set.filter(end_time__gt=now) \
                                        .filter(isshow_id__in=[1, 8]) \
                                        .all().order_by('begin_time')

        events = map(calculate, new_events)
        #检索所有过期活动,可能会过滤一部分
        old_events = map(calculate, \
                v.neweventtable_set.filter(end_time__lt=now) \
                .filter(end_time__gte='2014-01-01') \
                .filter(isshow_id__in=[1, 8]) \
                .all().order_by('begin_time') \
                .reverse())

        head = common.venue_page_head(v.title, v.content)

    return render_to_response( \
        'venue.html', \
        {'venue': v, 'events': events, \
  'old_events': old_events, 'head': head}, \
        context_instance=RequestContext(request)
        )
예제 #6
0
파일: venue.py 프로젝트: sureboy/xiaorizi
def view_venue(request, mess_string):
    try:
        v = NewVenue.objects.get(pk=mess.decode(mess_string))
    except ObjectDoesNotExist:
        v = None

    head = {}
    head['title'] = u"未找到指定场馆"

    if v is None:
        events = None
        old_events = None
    else:
        if v.content is not None:
            v.content = v.content.replace('\n', '<br/>')
        else:
            v.content = ''
        '''
        try:
            s.pic_url = s.pic.server.name + s.pic.urls
        except AttributeError:
            s.pic_url = ""
        '''
        def calculate(e):
            return NewformatEvent(None, e.old_event_id)

        now = timezone.now()
        #检索所有未过期活动,性能假设:每年活动不超过50个
        new_events = v.neweventtable_set.filter(end_time__gt=now) \
                                        .filter(isshow_id__in=[1, 8]) \
                                        .all().order_by('begin_time')

        events = map(calculate, new_events)
        #检索所有过期活动,可能会过滤一部分
        old_events = map(calculate, \
                v.neweventtable_set.filter(end_time__lt=now) \
                .filter(end_time__gte='2014-01-01') \
                .filter(isshow_id__in=[1, 8]) \
                .all().order_by('begin_time') \
                .reverse())

        head = common.venue_page_head(v.title, v.content)

    return render_to_response( \
        'venue.html', \
        {'venue': v, 'events': events, \
		'old_events': old_events, 'head': head}, \
        context_instance=RequestContext(request)
        )
예제 #7
0
def like_sponsor(request, mess_string):
    try:
        s = NewSponsor.objects.get(pk=mess.decode(mess_string))
    except ObjectDoesNotExist:
        s = None
    result = {}
    if s is None:
        result['success'] = False
    else:
        if s.like_count == None:
            s.like_count = 0
        s.like_count += 1
        s.save()
        result['success'] = True
        result['like'] = s.like_count
    return HttpResponse(json.dumps(result))
예제 #8
0
파일: dig.py 프로젝트: hooops/sponser_hdj
def like_sponsor(request, mess_string):
    try:
        s = NewSponsor.objects.get(pk=mess.decode(mess_string))
        s.pic_url = s.pic.urls
    except ObjectDoesNotExist:
        s = None
    result = {}
    if s is None:
        result['success'] = False
    else:
        if s.like_count == None:
            s.like_count = 0
        s.like_count += 1
        s.save()
        result['success'] = True
    return HttpResponse(json.dumps(result), mimetype="application/json")
예제 #9
0
파일: dig.py 프로젝트: sureboy/xiaorizi
def like_sponsor(request, mess_string):
    try:
        s = NewSponsor.objects.get(pk=mess.decode(mess_string))
        s.pic_url = s.pic.urls
    except ObjectDoesNotExist:
        s = None
    result = {}
    if s is None:
        result['success'] = False
    else:
        if s.like_count == None:
            s.like_count = 0
        s.like_count += 1
        s.save()
        result['success'] = True
    return HttpResponse(json.dumps(result), mimetype="application/json")
예제 #10
0
파일: sponsor.py 프로젝트: sureboy/xiaorizi
def like_sponsor(request, mess_string):
    try:
        s = NewSponsor.objects.get(pk=mess.decode(mess_string))
    except ObjectDoesNotExist:
        s = None
    result = {}
    if s is None:
        result['success'] = False
    else:
        if s.like_count == None:
            s.like_count = 0
        s.like_count += 1
        s.save()
        result['success'] = True
        result['like'] = s.like_count
    return HttpResponse(json.dumps(result))
예제 #11
0
파일: dig.py 프로젝트: hooops/sponser_hdj
def dig_show_sponsor(request, mess_string):
    sponsor_id = mess.decode(mess_string)
    #从缓存中读取主办方信息
    is_cached = True
    #
    s = cache.get('dig_sponsor_%d' % sponsor_id)
    if not s:
        #缓存标志
        is_cached = False
        try:
            s = NewSponsor.objects.get(pk=sponsor_id)
        except ObjectDoesNotExist:
            s = None

    e = {}
    events = None
    old_events = None
    possible_event_from = []
    froms = None
    if s is not None:
        action = request.REQUEST.get('action', None)
        if action == 'count' and not is_cached:
            #关系发现
            #
            #
            #
            #检索所有
            all_events = s.events.all()
            events = all_events
            #关联的来源
            froms = s.event_from.all()

            f_visited = []
            #根据关联来源生成主办方特征
            sf = sponsor_feature()
            picker = contact_picker()
            picker.init_char_set()
            for f in froms:
                res = picker.pick(f.content)
                for email in res[contact_picker.email_address]:
                    sf.add_item('email', email)
                for phone in res[contact_picker.phone_number]:
                    sf.add_item('phone', phone)
                f_visited.append(f.id)
            
            s.feature = unicode(sf)
            s.save()

            #匹配所有的来源
            for f in NewEventFrom.objects.all():
                if f.id in f_visited:
                    continue
                
                res = picker.pick(f.content)
                sf_f = sponsor_feature()
                for email in res[contact_picker.email_address]:
                    sf_f.add_item('email', email)
                for phone in res[contact_picker.phone_number]:
                    sf_f.add_item('phone', phone)

                if sf.similarity(sf_f) >= 0.5:
                    possible_event_from.append(f)
                f_visited.append(f.id)

            #取出可能来源的相关活动
            def show_linked_event(froms):
                for f in froms:
                    f.linked_event = []
                    for le in f.neweventtable_set.all():
                        f.linked_event.append(le)

            show_linked_event(froms)
            show_linked_event(possible_event_from)
            e['content'] = json.dumps(s.feature)

        elif action == 'count':
            if is_cached:
                e =  cache.get('dig_sponsor_env_%d' % sponsor_id)
                events =  cache.get('dig_sponsor_events_%d' % sponsor_id)
                froms =  cache.get('dig_sponsor_froms_%d' % sponsor_id)
                possible_event_from = cache.get('dig_sponsor_pef_%d' % sponsor_id)

        e['target'] = s.name
        #e['content'] = s.intro

    e['title'] = 'dig system' 
    
    #进行缓存,前提是没有缓存,以及主办方存在
    if not is_cached and s:
        timeout = 60 * 5
        cache.set('dig_sponsor_%d' % sponsor_id, s, timeout)
        cache.set('dig_sponsor_env_%d' % sponsor_id, e, timeout)
        cache.set('dig_sponsor_events_%d' % sponsor_id, events, timeout)
        cache.set('dig_sponsor_froms_%d' % sponsor_id, froms, timeout)
        cache.set('dig_sponsor_pef_%d' % sponsor_id, possible_event_from, timeout)

    return render_to_response( \
        'dashboard.html', \
        {'env': e, 'events': events, 'froms': froms,\
        'possible_froms': possible_event_from}, \
        context_instance=RequestContext(request)
        )
예제 #12
0
파일: dig.py 프로젝트: sureboy/xiaorizi
def dig_show_sponsor(request, mess_string):
    sponsor_id = mess.decode(mess_string)
    #从缓存中读取主办方信息
    is_cached = True
    #
    s = cache.get('dig_sponsor_%d' % sponsor_id)
    if not s:
        #缓存标志
        is_cached = False
        try:
            s = NewSponsor.objects.get(pk=sponsor_id)
        except ObjectDoesNotExist:
            s = None

    e = {}
    events = None
    old_events = None
    possible_event_from = []
    froms = None
    if s is not None:
        action = request.REQUEST.get('action', None)
        if action == 'count' and not is_cached:
            #关系发现
            #
            #
            #
            #检索所有
            all_events = s.events.all()
            events = all_events
            #关联的来源
            froms = s.event_from.all()

            f_visited = []
            #根据关联来源生成主办方特征
            sf = sponsor_feature()
            picker = contact_picker()
            picker.init_char_set()
            for f in froms:
                res = picker.pick(f.content)
                for email in res[contact_picker.email_address]:
                    sf.add_item('email', email)
                for phone in res[contact_picker.phone_number]:
                    sf.add_item('phone', phone)
                f_visited.append(f.id)

            s.feature = unicode(sf)
            s.save()

            #匹配所有的来源
            for f in NewEventFrom.objects.all():
                if f.id in f_visited:
                    continue

                res = picker.pick(f.content)
                sf_f = sponsor_feature()
                for email in res[contact_picker.email_address]:
                    sf_f.add_item('email', email)
                for phone in res[contact_picker.phone_number]:
                    sf_f.add_item('phone', phone)

                if sf.similarity(sf_f) >= 0.5:
                    possible_event_from.append(f)
                f_visited.append(f.id)

            #取出可能来源的相关活动
            def show_linked_event(froms):
                for f in froms:
                    f.linked_event = []
                    for le in f.neweventtable_set.all():
                        f.linked_event.append(le)

            show_linked_event(froms)
            show_linked_event(possible_event_from)
            e['content'] = json.dumps(s.feature)

        elif action == 'count':
            if is_cached:
                e = cache.get('dig_sponsor_env_%d' % sponsor_id)
                events = cache.get('dig_sponsor_events_%d' % sponsor_id)
                froms = cache.get('dig_sponsor_froms_%d' % sponsor_id)
                possible_event_from = cache.get('dig_sponsor_pef_%d' %
                                                sponsor_id)

        e['target'] = s.name
        #e['content'] = s.intro

    e['title'] = 'dig system'

    #进行缓存,前提是没有缓存,以及主办方存在
    if not is_cached and s:
        timeout = 60 * 5
        cache.set('dig_sponsor_%d' % sponsor_id, s, timeout)
        cache.set('dig_sponsor_env_%d' % sponsor_id, e, timeout)
        cache.set('dig_sponsor_events_%d' % sponsor_id, events, timeout)
        cache.set('dig_sponsor_froms_%d' % sponsor_id, froms, timeout)
        cache.set('dig_sponsor_pef_%d' % sponsor_id, possible_event_from,
                  timeout)

    return render_to_response( \
        'dashboard.html', \
        {'env': e, 'events': events, 'froms': froms,\
        'possible_froms': possible_event_from}, \
        context_instance=RequestContext(request)
        )