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
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
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, })
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, })
def messages_context_processor(request): return get_profile(reuqest.user).pull_messages()
def __init__(self, request): self.profile = get_profile(request.user)
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, })
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('')