Esempio n. 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))
Esempio n. 2
0
def PersonPage(request,screen_name,account=None):
    if account:
        person = collector.person(screen_name,account)
    else:
        person = Person.by_screen_name(screen_name)
    if person:
        tasks.updatePersonTweets(person,account)
        num_friends = person.following_count
    else:
        num_friends = None
    return render_to_response('person.html',{'person':person,
                                      'num_friends':num_friends,
                                      'user':account})
Esempio n. 3
0
def PersonPage(request, screen_name, account=None):
    if account:
        person = collector.person(screen_name, account)
    else:
        person = Person.by_screen_name(screen_name)
    if person:
        tasks.updatePersonTweets(person, account)
        num_friends = person.following_count
    else:
        num_friends = None
    return render_to_response('person.html', {
        'person': person,
        'num_friends': num_friends,
        'user': account
    })
Esempio n. 4
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})
Esempio n. 5
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})
Esempio n. 6
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))