Exemple #1
0
 def clean_contacts(self):
     me = get_profile(self.instance.client)
     profiles = []
     for contact in self.cleaned_data['contacts']:
         try:
             p = Userprofile.index.get(username=contact)
         except DoesNotExist as e:
             logger.warn(contact)
             raise ValidationError("Can't be connected to {0}".format(contact))
         if not me.knows.is_connected(p):
             raise ValidationError("Can't be connected to {0}".format(contact))
         profiles.append(p)
     return profiles
Exemple #2
0
 def clean_contacts(self):
     me = get_profile(self.instance.client)
     profiles = []
     for contact in self.cleaned_data['contacts']:
         try:
             p = Userprofile.index.get(username=contact)
         except DoesNotExist as e:
             logger.warn(contact)
             raise ValidationError(
                 "Can't be connected to {0}".format(contact))
         if not me.knows.is_connected(p):
             raise ValidationError(
                 "Can't be connected to {0}".format(contact))
         profiles.append(p)
     return profiles
Exemple #3
0
def create_campaign(request):
    if request.method == 'POST':
        campaign = Campaign(client=request.user)
        form = CampaignForm(request.POST, request.FILES, instance=campaign)
        if form.is_valid():
            campaign = form.save()
            if campaign.id:
                return redirect('client_index')
    if request.method == 'GET':
        form = CampaignForm()
    form.fields[
        'contacts'].widget = django.forms.widgets.CheckboxSelectMultiple(
            choices=((c.username, c.username)
                     for c in get_profile(request.user).knows.all()))
    transaction.commit()
    return render(request, 'new_campaign.html', {
        'form': form,
    })
Exemple #4
0
def contacts(request):
    me = get_profile(request.user)     
    template_name = 'client_contacts.html' if me.is_client else 'user_contacts.html'   
    errors = False
    text_emails = ''
    if request.POST:
        data_type = request.POST['data_type']
        text_emails = request.POST.get('emails', '')
        data_parser = data_parsers[data_type](request)
        try:
            data_parser.save()    
        except CustomValidationError as e:
            errors = e        
        else:
            return redirect('contacts')
    return render(request, template_name, {
        'contacts': me.knows.all(),
        'errors': errors,
        'text_emails': text_emails,
        })
Exemple #5
0
def messages_context_processor(request):
    return get_profile(reuqest.user).pull_messages()
Exemple #6
0
 def __init__(self, request):
     self.profile = get_profile(request.user)
Exemple #7
0
def create_campaign(request):
    if request.method == 'POST':
        campaign = Campaign(client=request.user)
        form = CampaignForm(request.POST, request.FILES, instance=campaign)
        if form.is_valid():
            campaign = form.save()
            if campaign.id:
                return redirect('client_index')
    if request.method == 'GET':
        form = CampaignForm()
    form.fields['contacts'].widget = django.forms.widgets.CheckboxSelectMultiple(choices=((c.username, c.username) for c in get_profile(request.user).knows.all())) 
    transaction.commit()
    return render(request, 'new_campaign.html', {
            'form': form,
        })
Exemple #8
0
def delete_contact(request):
    username = request.POST['username']
    to_disconnect = Userprofile.index.get(username=request.POST['username'])
    get_profile(request.user).knows.disconnect(to_disconnect)
    return HttpResponse('')
Exemple #9
0
def messages_context_processor(request):
    return get_profile(reuqest.user).pull_messages()
Exemple #10
0
 def __init__(self, request):
     self.profile = get_profile(request.user)