예제 #1
0
def GroupAddPage(request,account=None):
    name = request.REQUEST.get('name','')
    short_name = name.replace(' ','_').lower()
    member_names = request.REQUEST.get('member_names','')
    auto_gen = request.REQUEST.get('auto_gen',None)
    
    errors = []
    
    if 'POST' == request.method:
        if auto_gen:
            return render_to_response('group-add.html', {
                                                        "user": account,
                                                        "member_names":member_names,
                                                        }, context_instance=RequestContext(request))
        group = Group.by_short_name_and_user(short_name, account)
        if group:
            return render_to_response('group-add.html', {
                                                        "errors":['A group by the short_name \'' + short_name + '\' already exists for you. Please try another.'], 
                                                        "user": account, 
                                                        "short_name":short_name, 
                                                        "name":name,
                                                        "member_names":member_names,
                                                        }, context_instance=RequestContext(request))
        people = []
        if len(short_name) < 1:
            errors.append("Please ensure the group name is atleast 1 character long.")
        for member in member_names.strip().split(','):
            person = Person.by_screen_name(member)
            if not person:
                person = collector.person(member,account)
            if person:
                people.append(person)
                tasks.updatePersonTweets(person,account)
            else:
                errors.append("Could not find a user named: " + member)
        if len(errors) > 0:
            return render_to_response('group-add.html', {
                                                        "errors":errors, 
                                                        "user": account, 
                                                        "short_name":short_name, 
                                                        "name":name,
                                                        "member_names":member_names,
                                                        }, context_instance=RequestContext(request))
        else:
            group = Group.objects.create(short_name=short_name, user=account, name=name)
            for person in people:
                group.members.add(person)
            group.save()
            return HttpResponseRedirect('/group')
    return render_to_response('group-add.html', {
                                            'user': account, 
                                            },context_instance=RequestContext(request))
예제 #2
0
def GroupTweets(request,short_name,account=None):
    group = Group.by_short_name_and_user(short_name, account)
    terms = None
    filters = {}
    if request.REQUEST.get('start'):
        filters['created_at__gte'] = datetime.strptime(request.REQUEST.get('start'),"%Y-%m-%d")
    if request.REQUEST.get('end'):
        filters['created_at__lt'] = datetime.strptime(request.REQUEST.get('end'),"%Y-%m-%d")
    if request.REQUEST.get('q'):
        terms = request.REQUEST.get('q').split()
    statuses = group.statuses(20,0,query=terms,**filters)
    encodeURLs(statuses, account)
    return render_to_response('group-tweets.html', {'name':group.name, 'statuses':statuses})
예제 #3
0
def GroupTweetsAdditional(request,short_name,loadCount=0,account=None):
    group = Group.by_short_name_and_user(short_name, account)
    filters = {}
    terms = None
    tweetCount = 20
    loadCount = tweetCount * int(loadCount)
    if request.REQUEST.get('start'):
        filters['created_at__gte'] = datetime.strptime(request.REQUEST.get('start'),"%Y-%m-%d")
    if request.REQUEST.get('end'):
        filters['created_at__lt'] = datetime.strptime(request.REQUEST.get('end'),"%Y-%m-%d")
    if request.REQUEST.get('q'):
        terms = request.REQUEST.get('q').split()
    statuses = group.statuses(tweetCount,loadCount,query=terms,**filters)
    encodeURLs(statuses, account)
    return render_to_response('group-tweets-additional.html', {'statuses':statuses})
예제 #4
0
def GroupTweetsAdditional(request, short_name, loadCount=0, account=None):
    group = Group.by_short_name_and_user(short_name, account)
    filters = {}
    terms = None
    tweetCount = 20
    loadCount = tweetCount * int(loadCount)
    if request.REQUEST.get('start'):
        filters['created_at__gte'] = datetime.strptime(
            request.REQUEST.get('start'), "%Y-%m-%d")
    if request.REQUEST.get('end'):
        filters['created_at__lt'] = datetime.strptime(
            request.REQUEST.get('end'), "%Y-%m-%d")
    if request.REQUEST.get('q'):
        terms = request.REQUEST.get('q').split()
    statuses = group.statuses(tweetCount, loadCount, query=terms, **filters)
    encodeURLs(statuses, account)
    return render_to_response('group-tweets-additional.html',
                              {'statuses': statuses})
예제 #5
0
def GroupTweets(request, short_name, account=None):
    group = Group.by_short_name_and_user(short_name, account)
    terms = None
    filters = {}
    if request.REQUEST.get('start'):
        filters['created_at__gte'] = datetime.strptime(
            request.REQUEST.get('start'), "%Y-%m-%d")
    if request.REQUEST.get('end'):
        filters['created_at__lt'] = datetime.strptime(
            request.REQUEST.get('end'), "%Y-%m-%d")
    if request.REQUEST.get('q'):
        terms = request.REQUEST.get('q').split()
    statuses = group.statuses(20, 0, query=terms, **filters)
    encodeURLs(statuses, account)
    return render_to_response('group-tweets.html', {
        'name': group.name,
        'statuses': statuses
    })
예제 #6
0
def GroupTweetsBackground(request,short_name,account=None):
    output = {}
    group = Group.by_short_name_and_user(short_name, account)

    output['num_statuses'] = group.status_count()
    
    complete = not group.isUpdating()
      
    output['complete'] = complete
    
    if group.oldestStatus():
        output['oldest_date'] = group.oldestStatus().status_date()
    if group.latestStatus():
        output['latest_date'] = group.latestStatus().status_date()
    
    if account:
        output['api_calls'] = account.rate_remaining
    response = HttpResponse()
    response.write(simplejson.dumps(output))
    return response    
예제 #7
0
def GroupTweetsBackground(request, short_name, account=None):
    output = {}
    group = Group.by_short_name_and_user(short_name, account)

    output['num_statuses'] = group.status_count()

    complete = not group.isUpdating()

    output['complete'] = complete

    if group.oldestStatus():
        output['oldest_date'] = group.oldestStatus().status_date()
    if group.latestStatus():
        output['latest_date'] = group.latestStatus().status_date()

    if account:
        output['api_calls'] = account.rate_remaining
    response = HttpResponse()
    response.write(simplejson.dumps(output))
    return response
예제 #8
0
def GroupPage(request,short_name,account=None):
    group = Group.by_short_name_and_user(short_name, account)
    for member in group.members.all():
        tasks.updatePersonTweets(member, account)
    return render_to_response('group.html',{'group':group,
                                      'user':account})
예제 #9
0
def GroupListPage(request,account=None):
    groups = Group.by_user(account)
    return render_to_response('group-list.html', {'user':account,
                                             'groups':groups,
                                             })
예제 #10
0
def GroupPage(request, short_name, account=None):
    group = Group.by_short_name_and_user(short_name, account)
    for member in group.members.all():
        tasks.updatePersonTweets(member, account)
    return render_to_response('group.html', {'group': group, 'user': account})
예제 #11
0
def GroupAddPage(request, account=None):
    name = request.REQUEST.get('name', '')
    short_name = name.replace(' ', '_').lower()
    member_names = request.REQUEST.get('member_names', '')
    auto_gen = request.REQUEST.get('auto_gen', None)

    errors = []

    if 'POST' == request.method:
        if auto_gen:
            return render_to_response('group-add.html', {
                "user": account,
                "member_names": member_names,
            },
                                      context_instance=RequestContext(request))
        group = Group.by_short_name_and_user(short_name, account)
        if group:
            return render_to_response('group-add.html', {
                "errors": [
                    'A group by the short_name \'' + short_name +
                    '\' already exists for you. Please try another.'
                ],
                "user":
                account,
                "short_name":
                short_name,
                "name":
                name,
                "member_names":
                member_names,
            },
                                      context_instance=RequestContext(request))
        people = []
        if len(short_name) < 1:
            errors.append(
                "Please ensure the group name is atleast 1 character long.")
        for member in member_names.strip().split(','):
            person = Person.by_screen_name(member)
            if not person:
                person = collector.person(member, account)
            if person:
                people.append(person)
                tasks.updatePersonTweets(person, account)
            else:
                errors.append("Could not find a user named: " + member)
        if len(errors) > 0:
            return render_to_response('group-add.html', {
                "errors": errors,
                "user": account,
                "short_name": short_name,
                "name": name,
                "member_names": member_names,
            },
                                      context_instance=RequestContext(request))
        else:
            group = Group.objects.create(short_name=short_name,
                                         user=account,
                                         name=name)
            for person in people:
                group.members.add(person)
            group.save()
            return HttpResponseRedirect('/group')
    return render_to_response('group-add.html', {
        'user': account,
    },
                              context_instance=RequestContext(request))
예제 #12
0
def GroupListPage(request, account=None):
    groups = Group.by_user(account)
    return render_to_response('group-list.html', {
        'user': account,
        'groups': groups,
    })