def show_list(request, post_objects, is_show_post=True, message = None):
    form = search_form(request.POST or None, request.FILES or None)
    
    try : # 검색자가 시터인지 아닌지 파악 - 글쓰기 버튼 활성화
        Sitter.objects.get(user_id = get_user(request))
        is_sitter = True
    except: #(TypeError, AttributeError, ObjectDoesNotExist):
        is_sitter = False
    
    posts = []
    for post_obj in post_objects:
        sitter = post_obj.author
        
        post = post_obj.__dict__
        post['author'] = sitter.__dict__
        post['author']['name'] = str(sitter)
        post['author']['photo'] = myModule.get_userimg(sitter)
        post['author']['score'] = myModule.get_sitter_score(sitter)
        post['author']['score'] = myModule.get_sitter_score(sitter)
        post['author']['number_of_animal'] = myModule.get_number_of_pet(sitter)
        posts.append(post)
    
    return render(request, 'posting/post_list.html', {
        'posts': posts,
        'form': form,
        'is_sitter' : is_sitter,
        'is_show_post' : is_show_post,
        'message' : message,
        
    } )
def showPost(request, post_id):
    post_obj = Post.objects.get(id = int(post_id))
    form = ContactForm(request.POST or None, request.FILES or None, post_id = post_obj)

    if request.method == 'POST' and form.is_valid():
        return create_contact(request, form, post_obj)

    # GET or invalid form
    sitter_obj = post_obj.author
    post = post_obj.__dict__
    post['species_of_animal'] = Species.objects.all().filter(post = post_id)
    post['number_of_animal'] = myModule.get_number_of_pet(sitter_obj.user_id)
    try:
        Bookmark.objects.get(user = get_user(request), post = post_obj)
        post['marked'] = True
    except:
        post['marked'] = False

    sitter = sitter_obj.__dict__
    sitter['name'] = str(sitter_obj)
    sitter['score'] = myModule.get_sitter_score(sitter_obj)
    sitter['photo'] = myModule.get_userimg(sitter_obj)

    return render(request, 'posting/post_detail.html', {
        'post' : post, 
        'sitter':sitter, 
        'form':form,
    } )
Example #3
0
def show_conatct_as_owner(request, message=None):
    try:
        Sitter.objects.get(user_id=get_user(request))
        is_sitter = True
    except:
        is_sitter = False

    print("메세지", message)

    contacts = Contact.objects.filter(owner=get_user(request))

    contact_info = []
    for contact in contacts:
        temp = contact.__dict__
        temp['photo'] = myModule.get_userimg(contact.sitter)
        temp['sitter'] = contact.sitter
        temp['score'] = myModule.get_sitter_score(contact.sitter)
        contact_info.append(temp)

    return render(
        request, 'contact/contact_list.html', {
            'contacts': contact_info,
            'owner_contact': True,
            'is_sitter': is_sitter,
            'message': message,
        })
def show_conatct_as_sitter(request):
    contacts = Contact.objects.filter(sitter=Sitter.objects.get(
        user_id=get_user(request)))
    contact_info = []
    for contact in contacts:
        temp = contact.__dict__
        temp['photo'] = myModule.get_userimg(contact.sitter)
        temp['sitter'] = contact.sitter
        temp['score'] = myModule.get_sitter_score(contact.sitter)
        temp['species_of_animal'] = [
            str(i) for i in Species.objects.filter(contact=contact.id)
        ]
        contact_info.append(temp)
    return render(request, 'contact/contact_list.html', {
        'contacts': contact_info,
        'is_sitter': True,
    })