Esempio n. 1
0
def update_tab_comment(request):
    result = dict()
    result["success"] = True
    result["message"] = "success"

    input_message = ""
    if request.method == "POST":
        if request.POST["message"]:
            input_message = smart_unicode(
                request.POST["message"], encoding="utf-8", strings_only=False, errors="strict"
            )
        if request.POST["feed_id"]:
            feed_id = request.POST["feed_id"]

    if input_message is not "":
        try:
            user = User.objects.get(username=request.user.username)
        except:
            return my_utils.return_error("Please Sign in first")

        try:
            message = TabFeed.objects.filter(id=feed_id, is_deleted=False)[0]
        except:
            return my_utils.return_error("No such Message")

        try:
            new_comment = TabComment(author=user, contents=input_message, message=message)
            new_comment.save()
            message.save()
        except:
            return my_utils.return_error("Insert Failed")

    else:
        return my_utils.return_error("Empty Message")

    try:
        item = dict()
        item["id"] = new_comment.id
        item["author"] = new_comment.author.username
        # item['author_picture']=UserProfile.objects.get(user=new_comment.author).picture.url
        item["author_picture"] = my_utils.get_user_thumbnail(new_comment.author)
        item["author_name"] = new_comment.author.last_name
        item["contents"] = parser.parse_text(new_comment.contents)
        item["reg_date"] = str(new_comment.reg_date)
        result["comment"] = item
    except Exception as e:
        print str(e)
    return HttpResponse(json.dumps(result, indent=4), mimetype="application/json")
def main(request):
    t = loader.get_template('member.html')
    context = RequestContext(request)
    my_utils.load_basic_info(request, context)
    
    context['side_list']=['search_member']
    context['page_member'] = "selected"
    my_utils.prepare_search_topic(context)
    
    try:
        keyword = request.GET.get('q', '')
        search_index = request.GET.get('index', '')
        query_type = Q()
        if keyword is not '':
            print keyword
            query_type = Q(username__icontains=keyword) | Q(last_name__icontains=keyword)
        
        if search_index is not '':
            if search_index in map(chr, range(65, 91)):
                query_type = Q(username__istartswith=search_index)
            elif search_index == 'number':
                query_type = Q(username__gt="0",username__lt="9")
            else:
                this_index,next_index=my_utils.next_search_index(search_index)
                query_type = Q(username__gt=this_index, username__lt=next_index)
        
        members = User.objects.filter(query_type, is_active=True).order_by('username')
        members_list = list()
        for member in members:
            try:
                member_profile = UserProfile.objects.get(user=member)
                member.profile = member_profile
                try:
                    member.picture = my_utils.get_user_thumbnail(member)
                except:
                    member.picture = "/media/default.png"
                if not member_profile.is_deactivated:
                    members_list.append(member)
            except:
                pass
        
        paginator = Paginator(members_list, 15)
        
        page = request.GET.get('page', 1)
        try:
            context['members'] = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            context['members'] = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            context['members'] = paginator.page(paginator.num_pages)
        
        context['index_info'] = my_utils.get_index_list(context['members'].number, paginator.num_pages)
        
    except Exception as e:
        print str(e)
        
    
    
    return HttpResponse(t.render(context))
Esempio n. 3
0
def update_comment(request):
    result=dict()
    result['success']=True
    result['message']='success'
    
    input_message=''
    if request.method == 'POST':
        if request.POST['message']:
            input_message=smart_unicode(request.POST['message'], encoding='utf-8', strings_only=False, errors='strict')
        if request.POST['feed_id']:
            feed_id = request.POST['feed_id']

    if input_message is not '':
        try:
            user = User.objects.get(username=request.user.username)
        except:
            return my_utils.return_error('Please Sign in first')
        
        try:
            message = Message.objects.filter(id=feed_id,is_deleted=False)[0]
        except:
            return my_utils.return_error('No such Message')
            
        try: 
            new_comment = Comment(author=user,contents=input_message,message=message)
            new_comment.save()
            message.save()
        except:
            return my_utils.return_error('Insert Failed')
        
        #Add To author Timeline
        try:
            author_timeline_new = UserTimeline.objects.filter(message=message,user=user)[0]
        except:
            #현재 없는 경우에만 넣는다.
            try:
                print 'hi'
                author_timeline_new = UserTimeline.objects.get_or_create(message=message,user=user)[0]
                author_timeline_new.save()
            except:
                pass
        
        try:
            related_timelines = UserTimeline.objects.filter(message=message)
            if not related_timelines:
                pass
            for timeline in related_timelines:
                try:
                    if timeline.user.username != request.user.username:
                        timeline.save()
                        
                        #SEND NOTIFICATION
                        info = dict()
                        info['from'] = request.user
                        info['to'] = timeline.user
                        info['comment'] = input_message
                        info['target_object'] = message
                        register_noti(request, "new_comment",info)
                except:
                    pass
        except Exception as e:
            print str(e)
            return my_utils.return_error('Related Timelilne Failed')
            
        #Question! Should do insert into related Topic timeline?
    else:
        return my_utils.return_error('Empty Message')
    
    try:
        item = dict()
        item['id']=new_comment.id
        item['author']=new_comment.author.username
        #item['author_picture']=UserProfile.objects.get(user=new_comment.author).picture.url
        item['author_picture']=my_utils.get_user_thumbnail(new_comment.author)
        item['author_name']=new_comment.author.last_name
        item['contents']= parser.parse_text(new_comment.contents)
        item['reg_date']= str(new_comment.reg_date)
        result['comment']=item
    except Exception as e:
        print str(e)
    return HttpResponse(json.dumps(result, indent=4), mimetype='application/json')