Example #1
0
def face_search(request):
    """
    Search photos related to the face(s) in given photo.
    """
    latest_tag_list = dbControl.get_latest_tags()
    email = common.get_email(request)
    if request.method == 'POST':
        latest_tag_list = [r'none for now']
        form = forms.photo_file_form(request.POST or None, request.FILES)
        if form.is_valid():
            photo_file = request.FILES['face_photo_file'].read()
            # upload photo
            photo_url = storage.objUpload(photo_file, tag)
            thumbnail_url = common.get_thumbnail_url(
                photo_url, size='c_fit,w_750')
            # add face to faceset
            person_id_list = faceControl.add_faces(
                method='url', urlOrPath=thumbnail_url)
            photo_list = dbControl.get_related_photos(person_id_list)
            return_dict = {'photo_list': photo_list,
                          'user_Email': email,
                          'latest_tag_list': latest_tag_list}
            return render(request, u'index.html', return_dict)
        else:
            pass

    return_dict = {'user_Email': email,
                  'latest_tag_list': latest_tag_list}
    return render(request, u'face.html', return_dict)
Example #2
0
def upload(request):
    """
    Upload photo and infomation.
    """
    if request.user.is_authenticated():
        latest_tag_list = dbControl.get_latest_tags()
        email = common.get_email(request)

        # after upload
        if request.method == 'POST':
            form = forms.photo_info_form(request.POST or None, request.FILES)
            if form.is_valid():
                photo_file = request.FILES['photo_file'].read()
                description = request.POST['description']
                tag = request.POST['tag']
                permission = request.POST['permission']
                photo_info = common.upload_photo(
                    photo_file, description, tag, permission, email)

                return_dict = {'latest_tag_list': latest_tag_list,
                              'user_Email': email,
                              'photo_info': photo_info}
                return render(request, 'photo.html', return_dict)
            else:
                pass
        # before upload
        else:
            return_dict = {'latest_tag_list': latest_tag_list,
                          'user_Email': email}
            return render(request, u'upload.html', return_dict)
    else:
        return HttpResponseRedirect(reverse('users_login'))
Example #3
0
def homepage(request):
    """
    Homepage of the website.
    """

    latest_tag_list = dbControl.get_latest_tags()
    email = common.get_email(request)

    if request.user.is_authenticated():
        # if search
        if request.method == 'POST':
            form = forms.search_form(request.POST or None)
            if form.is_valid():
                search_word = request.POST['search_word']
                photo_list = dbControl.get_photos_of_tag(search_word)
            else:
                pass
        # not search, get photos may be interested in
        else:
            search_word = ''
            photo_list = dbControl.get_interested_photos(email=email)
    # not login
    else:
        search_word = ''
        photo_list = dbControl.get_latest_photos()

    return_dict = {'photo_list': photo_list,
                  'search_word': search_word,
                  'latest_tag_list': latest_tag_list,
                  'user_Email': email}
    return render(request, u'index.html', return_dict)
Example #4
0
def user_info(request):
    """ Show infomation of user. """
    if request.user.is_authenticated():
        email = common.get_email(request)
        info = dbControl.get_user_info(email)

        return_dict = {
                'user_Email': email,
                'info': info,
                }
        return render(request, 'user_info.html', return_dict)
    else:
        return HttpResponseRedirect(reverse('users_login'))
Example #5
0
def tag(request, search_word):
    """
    Search by tag (it's search_word here).
    """

    latest_tag_list = dbControl.get_latest_tags()
    email = common.get_email(request)
    photo_list = dbControl.get_photos_of_tag(search_word)

    return_dict = {'photo_list': photo_list,
                  'search_word': search_word,
                  'user_Email': email,
                  'latest_tag_list': latest_tag_list}
    return render(request, u'index.html', return_dict)
Example #6
0
def collect_delete(request):
    """ Cancel collect. """
    return_dict = {}
    if request.user.is_authenticated():
        email = common.get_email(request)
        if request.method == 'GET':
            photo_id = int(request.GET['p_id'])
            return_dict['SUC'] = dbControl.add_collect(email, photo_id)
            return_dict['collected_times'] = dbControl.get_collected_times(photo_id)
            return_dict['info'] = ''
    else:
        return_dict['SUC'] = False
        return_dict['info'] = u'未登录'
    return JsonResponse(return_dict)
Example #7
0
def photo_delete(request, p_id):
    """ Delete photo, don't check owner now. """
    latest_tag_list = dbControl.get_latest_tags()
    email = common.get_email(request)
    if request.user.is_authenticated():
        p_id = int(p_id)
        is_deleted = dbControl.delete(p_id)
    else:
        is_deleted = False

    return_dict = {'user_Email': email,
                  'latest_tag_list': latest_tag_list,
                  'is_deleted': is_deleted}
    return render(request, 'delete.html', return_dict)
Example #8
0
def photo_manage(request):
    """ Manage user's photo. """
    if request.user.is_authenticated():
        latest_tag_list = dbControl.get_latest_tags()
        email = common.get_email(request)
        photo_list = dbControl.get_owned_photos(email)

        return_dict = {'photo_list': photo_list,
                      'owner': email,
                      'user_Email': email,
                      'latest_tag_list': latest_tag_list}
        return render(request, u'index.html', return_dict)
    else:
        return HttpResponseRedirect(reverse('users_login'))
Example #9
0
def photo(request):
    """
    Show infomation of photo. Don't check the p_id temporary
    """
    latest_tag_list = dbControl.get_latest_tags()
    email = common.get_email(request)
    p_id = int(request.GET['photo'])
    if request.user.is_authenticated():
        is_collected = dbControl.is_collected(email, p_id)
    else:
        is_collected = False
    photo_info = dbControl.get_photo_info(p_id, method='p_id')
    return_dict = {'user_Email': email,
                  'latest_tag_list': latest_tag_list,
                  'is_collected': is_collected,
                  'photo_info': photo_info}
    return render(request, 'photo.html', return_dict)
Example #10
0
def extract2(html):
    soup = BeautifulSoup(html, 'html.parser')
    try:
        job_name = soup.find('h1').get('title')
    except:
        job_name = ''
    try:
        job_year = soup.find('em', {'class': 'i1'}).next_element
    except:
        job_year = 0
    try:
        job_degree = soup.find('em', {'class': 'i2'}).next_element
    except:
        job_degree = ''
    try:
        job_date = soup.find('em', {'class': 'i4'}).next_element
    except:
        job_date = ''
    try:
        company_inurl = soup.find('p', {'class': 'cname'}).a.get('href')
        job_company = soup.find('p', {'class': 'cname'}).a.get('title')
    except:
        company_inurl = ''
        job_company = ''
    p = re.compile('co\d+')
    aa = re.search(p, company_inurl)
    if aa:
        company_id = aa.group()
    else:
        company_id = ''
    print job_year, job_name, job_degree
    try:
        job_salary = soup.find('div', {'class': 'cn'}).strong.get_text()
        job_l = re.findall(r'\d+', job_salary)
        job_low = job_l[0]
        job_high = job_l[1]
    except:
        job_low = ''
        job_high = ''
    print job_low, job_high
    try:
        job_addr = soup.find('div', {'class': 'bmsg inbox'}).p.contents[2].strip()
    except:
        job_addr = ''
    print job_addr
    job_str = soup.find('div', {'class': 'bmsg job_msg inbox'}).contents[2]
    job_describe = job_str.get_text().split(u'职能类别:')[0]
    job_input = soup.find_all('div', {'class': 'tBorderTop_box'})
    phone = common.get_phone(job_describe)
    email = common.get_email(job_describe)
    company_info = soup.find('div', {'class': 'tmsg inbox'}).get_text()
    company_url = common.get_url(job_describe)
    if len(phone) == 0:
        phone = common.get_phone(company_info)
    if len(email) == 0:
        email = common.get_email(company_info)
    if len(company_url) == 0:
        company_url = common.get_url(company_info)
    try:
        job_type = job_str.find('p', {'class': 'fp f2'}).find_all('span', {'class': 'el'})
        job_type = ','.join([i.get_text() for i in job_type])
    except:
        job_type = ''

    job_area = soup.find('span', {'class': 'lname'}).get_text()
    print job_area
    job_dict = {'job_name':job_name, 'job_addr': job_addr, 'job_low': job_low, 'job_high': job_high,
                'job_des': job_describe, 'job_type': job_type, 'job_area': job_area, 'company_id': company_id,
                'job_year': job_year, 'job_degree': job_degree, 'email': email, 'phone': phone, 'job_date': job_date,
                'company_inurl': company_inurl, 'company_url': company_url, 'job_company': job_company}
    return job_dict