예제 #1
0
def token_register(request, slug, token):
    event = get(Event, slug=slug)
    print "Token: " + token
    contact = get(Contact, token=token)

    if request.method == 'POST':
        form = EventReRegistrationForm(request.POST)

        if form.is_valid():
            registrant = form.save(event = event, contact = contact)
            pending_signal.send(sender=registrant, contact=registrant.contact, event=event)

            return render_to_response('registration_pending.html', locals())
        else:
            return render_to_response('event_register.html', locals())

    else:
        data = {'first_name':contact.first_name,
                'middle_initial':contact.middle_initial,
                'last_name':contact.last_name,
                'title':contact.title,
                'email':contact.email,
                'phone1':contact.phone1,
                'addr1_row1':contact.addr1_row1,
                'addr1_row2':contact.addr1_row2,
                'addr1_city':contact.addr1_city,
                'addr1_state':contact.addr1_state,
                'addr1_zip':contact.addr1_zip,
                'addr1_country':contact.addr1_country,
                }
        form = EventReRegistrationForm(data)
        
        return render_to_response('event_register.html', locals())
예제 #2
0
def register(request, slug):
    event = get(Event, slug=slug)
    if request.method == 'POST':
        form = EventRegistrationForm(request.POST)

        if form.is_valid():
            registrant = form.save(event = event)
            pending_signal.send(sender=registrant, contact=registrant.contact, event=event)

            return render_to_response('registration_pending.html', locals())
        else:
            return render_to_response('event_register.html', locals())

    else:
        form = EventRegistrationForm()
        return render_to_response('event_register.html', locals())
예제 #3
0
def display(request, id):
    report = Report.objects.get(id=id)
    # perform advanced search and return contacts (make a function)
    contacts = makeadvfilter(report)
    # somehow get the attr names and variables to display in the template
    displayfields = [] # list of (field_name, verbose_name) for each field to be displayed
    displaydata = []   # list of (field_name, data) for each contact
    reportdata = []
    tmp = []
    for f in Report._meta.fields:
        if f.get_internal_type() == 'BooleanField' and f.value_from_object(report):
            displayfields.append((f.name, f.verbose_name))
            tmp.append(f.verbose_name)
    reportdata.append(tmp)
    for c in contacts:
        newcontact = []
        tmp = []
        for f in displayfields:
            newcontact.append((f[0], getattr(c, f[0])))
            tmp.append(getattr(c, f[0]))
        reportdata.append(tmp)
        displaydata.append(newcontact)
    request.session['reportname'] = report.name
    request.session['report'] = reportdata
    request.session['reportpagesize'] = (8.5, 11)   # Portrait size
    if report.page_size == "Landscape":
        request.session['reportpagesize'] = (11, 8.5)

    can_export = request.user.has_perm('reports.can_export')

    return render_to_response('reports/display.html', locals())
예제 #4
0
def create_email(request):
    savedsearches = ContactSavedSearch.objects.filter(user=request.user).order_by("-event_date")
    if request.method == "POST":
        form = CreateEmail(request.POST, request.FILES, user=request.user)
        if form.is_valid():
            url = '/emails/update/%d'
            status = ""
            if request.POST['Submit'] == "Save as draft":
                status = "draft"
            elif request.POST['Submit'] == "Save as template":
                status = "template"
            elif request.POST['Submit'] == "Send":
                status = "sent mail"
                url = '/emails/sent/'
            else:
                print "in apps/emails/views.py>create_email.  Template has changed" +\
                      " and view has not been updated.  You getting database errors?"
            e = form.save(extra_attrs={'user': request.user, 'status': status})
            if request.POST['Submit'] == "Send":
                send_email(e)
                return HttpResponseRedirect(url)
            return HttpResponseRedirect(url % e.id)
    else:
        # Check if an event was stuck in the get from the invite interface
        event = request.GET.get('event', None)
        form = CreateEmail(user=request.user)
    return render_to_response('emails/email_form.html', locals())
예제 #5
0
def index(request):
    form = BasicSearch()
    recentsearches = ContactSavedSearch.objects.filter(user=request.user).order_by("-event_date")[:3]
    recentdrafts = Email.objects.filter(user=request.user, status="draft").order_by("-last_edited")[:3]
    recentupdates = ContactEditHistory.objects.all().order_by("-event_date")[:3]
    recentunsubs = ContactEditHistory.objects.filter(message = "The contact has unsubscribed.").order_by("-event_date")[:3]
    return render_to_response('home.html', locals())
예제 #6
0
def contactdetails(request, id):
    contact = Contact.objects.get(id=id)
    cdata = []
    for f in Contact._meta.fields:
        if f.verbose_name != "ID" and f.name != "token":
            cdata = cdata + [(f.verbose_name, f.value_from_object(contact))]
    cdata.insert(3 ,('Tags', contact.tag_list))
    chistory = ContactEditHistory.objects.filter(contact=contact)
    return render_to_response('contacts/detail.html', locals())
예제 #7
0
def add(request):
    if request.method == 'POST':
        form = EventForm(request.POST)
        if form.is_valid():
            event = form.save()
            return HttpResponseRedirect(reverse('event-edit', args=[event.id])+'?after_add=1')
    else:
        form = EventForm()

    return render_to_response('event_add.html', locals())
예제 #8
0
def email_register(request, slug):
    if request.method == 'POST':
        contact = get(Contact, email=request.POST.get('email', None))
        event = get(Event, slug=slug)
        registrant = Registrant(contact = contact, event = event, pending = True, discount_code = request.POST.get('discount_code', None))
        try:
            registrant.save()
        except ValueError, e:
            if str(e) == 'Already Registered':
                error = 'That email address is already registered'
                return render_to_response('event_email_register.html', locals())
            else:
                print e
                raise

        from django.core.mail import EmailMultiAlternatives


            

        incorrect_link = "http://"+DOMAIN+reverse('event-register-token', kwargs={'slug':slug,'token':contact.get_token()})+"/"

        message = render_to_string("email_register_message.txt", locals())
        html_message = render_to_string("email_register_message.html", locals())
        
        mail = EmailMultiAlternatives("Registration Confirmation for %s" %(event, ),
                                      message,
                                      FROM_EMAIL,
                                      ['"%s %s" <%s>' % (contact.first_name, contact.last_name, contact.email)]
                                      )

        mail.attach_alternative(html_message, "text/html")
        mail.send()
        email_log.info("Sent Email To:%s - From:%s - Subject:%s" % (contact.email, FROM_EMAIL, "Registration Confirmation For %s" %(event, )))
        
        
        return render_to_response('registration_pending.html', locals())
예제 #9
0
def edit(request, id):
    instance = get(Event, pk=id)

    after_add = request.GET.get('after_add', None)

    pricing = instance.pricing_set.all()
    
    if request.method == 'POST':
        form = EventForm(request.POST, instance = instance)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('events'))
    else:
        form = EventForm(instance = instance)

    return render_to_response('event_edit.html', locals())
예제 #10
0
def deletecontact(request, id):
    contact = Contact.objects.get(id__exact=id)
    if request.method == "POST":
        if request.POST['submit'] == "Yes, delete the contact":
            # delete the contact and their history.
            ch = ContactEditHistory.objects.filter(contact=contact)
            for item in ch:
                item.delete()
            contact.delete()
            return HttpResponseRedirect('/contacts/search/results/')
        else:
            # This post is not from the confirm page, or they didn't click the confirm button. 
            return HttpResponseRedirect('/contacts/edit/%d' % (contact.id))
    else:
        # display the confirmation page
        return render_to_response('contacts/delete_confirm.html', locals())
예제 #11
0
def editcontact(request, id):
    contact = Contact.objects.get(id=id)  # re-get the contact from the db to make sure it's the current data.
    if request.method == "POST":
        form = AddContact(request.POST, instance=contact)
        if form.is_valid():
            # TODO: If state is set and nothing else in the address is set, set the state blank.
            # Update the contact
            contact = form.save()
            # log it in the history
            contacteditlog(request, contact, "Contact updated.")
            # return to this form, or to the search results.
            if request.POST['submit'] == "Save and close":
                return HttpResponseRedirect("/contacts/search/results")
            # else, return to this form (meaning, render it as if it hadn't been a post, but with error messages)
    else:  # request.method == GET
        form = AddContact(instance=contact)
    cform = form
    return render_to_response('contacts/edit.html', locals())
예제 #12
0
def deletereport(request, id):
    report = Report.objects.get(id__exact=id)
    if request.method == "POST":
        if request.POST['submit'] == "Yes, delete the report":
            # delete the report and it's search.
            st = SearchTerms.objects.filter(report = report)
            for item in st:
                item.delete()
            report.delete()
            return HttpResponseRedirect('/reports/list/')
        elif request.POST['submit'] == "No, go back":
            return HttpResponseRedirect('/reports/list/')
        else:
            # This post is not from the confirm page.
            return HttpResponseRedirect('/reports/delete/%s/' % (report.id))
    else:
        # display the confirmation page
        return render_to_response('reports/delete_confirm.html', locals())
예제 #13
0
def add(request):
    # initialize session data
    request.session['newcontacts'] = []
    request.session['newcontactscsv'] = []
    request.session['existingcontacts'] = []
    request.session['existingcontactscsv'] = []
    request.session['badcontacts'] = []
    request.session['badcontactscsv'] = []

    if (request.method == "POST"):
        form = AddContact(request.POST)
        if form.is_valid():
            # add the contact and redirect to /contacts/new
            line = copy.deepcopy(form.cleaned_data)
            savecontact(request, form, line)
            return HttpResponseRedirect('/contacts/new/')
    else:
        form = AddContact()
    return render_to_response('contacts/add.html', locals())
예제 #14
0
def import_from_file(request):
    # XXX column names need to be documented!  This is a user interface component.
    # initialize session data
    request.session['newcontacts'] = []
    request.session['newcontactscsv'] = []
    request.session['existingcontacts'] = []
    request.session['existingcontactscsv'] = []
    request.session['badcontacts'] = []
    request.session['badcontactscsv'] = []

    if request.method == "POST":
        form = ImportContactFile(request.POST, request.FILES)
        if form.is_valid():
            # parse file and add contacts, then redirect to /contacts/new
            r = csv.DictReader(cStringIO.StringIO(request.FILES['file'].read()))
            for line in r:
                # Create a contact record with this data.
                cform = AddContact(line)
                savecontact(request, cform, line)
            return HttpResponseRedirect('/contacts/new/')
    else:
        form = ImportContactFile()
    return render_to_response('contacts/import.html', locals())
예제 #15
0
def create(request):
    if request.method == "POST":
        form = CreateReport(request.POST)
        if form.is_valid():     # else is dropping through to the render_to_resposne
            r = form.save()
            # process advanced search here too
            contacts = Contact.objects.all()
            attribute = request.POST.getlist('attribute')
            condition = request.POST.getlist('condition')
            query = request.POST.getlist('query')
            operator = request.POST.getlist('operator')
            for i in xrange(0, len(attribute)):
                s = SearchTerms(field=attribute[i], 
                                condition=condition[i],
                                query=query[i],
                                order=i,
                                report=r)

                if i > 0:
                    try:
                        s.operator = operator[i-1]
                    except IndexError:
                        s.operator = 'and'
                else:
                    print("Default And %s" % (i,))
                    s.operator = 'and'
                    
                s.save()
                r.searchterms.add(s)
            r.save()
            return HttpResponseRedirect('/reports/display/%s' % r.id)
    else:
        form = CreateReport()

    context = locals().copy()
    context['contactattrs'] = contactattrs
    return render_to_response('reports/create.html', context)
예제 #16
0
def update_email(request, object_id):
    email = Email.objects.get(pk=object_id)
    extra_attrs = {}
    if request.method == "POST":
        request.session['lasteditedemail'] = 0

        if "draft" in request.POST['Submit']:
            if email.status == "draft":
                # update the email
                form = CreateEmail(request.POST, request.FILES, instance=email, user=request.user)
                if form.is_valid():
                    form.save()
                    return HttpResponseRedirect('/emails/list/draft/')
            else:
                # create new email from form as "draft"
                form = CreateEmail(request.POST, request.FILES, user=request.user)
                if form.is_valid():
                    extra_attrs['status'] = "draft"
                    extra_attrs['user'] = request.user
                    new_email = form.save(extra_attrs=extra_attrs)
                    # Copy recipients
                    for contact in email.recipients.all():
                        new_email.recipients.add(contact)

                    return HttpResponseRedirect('/emails/list/draft/')

        elif "template" in request.POST['Submit']:
            # If it's a sent mail make a new template, else just turn it into a template
            if email.status == "sent mail":
                form = CreateEmail(request.POST, request.FILES, user=request.user)
            else:
                form = CreateEmail(request.POST, request.FILES, instance=email, user=request.user)

            if form.is_valid():
                # change the status to "template"
                extra_attrs['status'] = "template"
                extra_attrs['user'] = request.user

                new_email = form.save(extra_attrs=extra_attrs)
                                # If new copy recipients
                if email.id != new_email.id:
                    for contact in email.recipients.all():
                        new_email.recipients.add(contact)

                return HttpResponseRedirect('/emails/list/template/')
        elif "Send" in request.POST['Submit']:
            # update the email
            if email.status == 'draft':
                form = CreateEmail(request.POST, request.FILES, instance=email, user=request.user)
            else:
                form = CreateEmail(request.POST, request.FILES, user=request.user)

            if form.is_valid():
                # change the status to "sent mail"
                extra_attrs['status'] = "sent mail"
                extra_attrs['user'] = request.user
                new_email = form.save(extra_attrs=extra_attrs)
                
                # If new copy recipients and attachment
                if email.id != new_email.id:
                    for contact in email.recipients.all():
                        new_email.recipients.add(contact)

                    if new_email.attachment in (None, ''):
                        new_email.attachment = email.attachment
                        print "attachment copied: %s" % (email.attachment,)
                        new_email.save()
                # send the email
                send_email(new_email)
                return HttpResponseRedirect('/emails/sent/')

    elif request.method == "GET":
        request.session['lasteditedemail'] = email.id
        form = CreateEmail(instance=email, user=request.user)


    savedsearches = ContactSavedSearch.objects.filter(user=request.user).order_by("-event_date")
    atchfilename = email.attachment.name.split("/")[-1]

    return render_to_response('emails/email_form.html',locals())
예제 #17
0
def emails(request, id):
    event = get(Event, pk=id)
    emails = Email.objects.filter(event = event)
    return render_to_response('event_emails.html', locals())
예제 #18
0
def new(request):
    newcontacts = request.session.get('newcontacts', [])
    existingcontacts = request.session.get('existingcontacts', [])
    badcontacts = request.session.get('badcontacts', [])
    return render_to_response('contacts/new.html', locals())
예제 #19
0
def dumppost(request):
    post = request.POST
    return render_to_response('dumppost.html', locals())
예제 #20
0
def events(request, id):
    contact = get_object_or_404(Contact, pk=id)
    events = contact.registrant_set.all()
    return render_to_response('contacts/events.html', locals())
예제 #21
0
def search(request):
    if request.method == 'GET':
        return render_to_response('event_search.html', locals())
예제 #22
0
def search(request, results="new", page=1, paginate_by=10, rtemplate="contacts/results.html"):
    '''
    Search algorithm. Cululative. Each search is applied to the current grouping unless "New Search" is clicked.
    '''
    
    page = int(request.GET.get('page', request.session.get('searchpage', 1)))
    profile = getprofile(request.user)
    sortby = request.GET.get('sortby', request.session.get('sortby', ''))
    request.session['sortby'] = sortby
    paginate_by = int(request.POST.get('pagingprefs', profile.pagingprefs))
    
    if results == "new":    # This is the first hit on the search page, there's no contacts or post data to be presented.
        bform = BasicSearch()
        # add attributes
        context = locals().copy()
        context['contactattrs'] = contactattrs
        return render_to_response('contacts/search.html', context)

    if (request.method == "POST"):  # They've submitted a query, filter the contacts
        if request.POST.get('search', None) in ('New search', 'Search'):
            contacts = Contact.objects.all()    # Brand new search results
	else:
            session_contacts = request.session.get('searchresults', [])
            cids = [c.id for c in session_contacts]
            contacts = Contact.objects.filter(id__in=cids)

        request.session['checked_contacts'] = []

        if "searchtype" in request.POST:        # if they're performing a search of any kind, go back to page 1
            page = 1

        form = BasicSearch(request.POST)
        if form.is_valid():
            # filter contacts based on values in form
            if form.cleaned_data['first_name']:
                contacts = contacts.filter(first_name__search = form.cleaned_data['first_name'])
                
            if form.cleaned_data['last_name']:
                contacts = contacts.filter(last_name__search = form.cleaned_data['last_name'])

            if form.cleaned_data['email']:
                contacts = contacts.filter(email__search = '"'+form.cleaned_data['email']+'"')

            if form.cleaned_data['tags']:
                qstagquery = tagutils.get_tag_list(form.cleaned_data['tags'])
                contacts = TaggedItem.objects.get_by_model(Contact, [tag.name for tag in qstagquery])
                #contacts = contacts.filter(id__in = [c.id for c in taggedcontacts])

        else:   # BasicSearch form is not valid
            bform = form
            return render_to_response('contacts/search.html', locals())

        # save search results in the session
        request.session['searchresults'] = contacts
        request.session['searchpage'] = page
        profile = getprofile(request.user)
        profile.pagingprefs = paginate_by
        profile.save()
        #request.session['pagingprefs'] = paginate_by
        # redirect to /contacts/search/results/
        #return HttpResponseRedirect('/contacts/search/results/')  # commented this out when updating this view for email recipient stuff.  It seems to work normally still.

    # request.method == "GET"
    if results == "results":
        # get the search result set from the session
        contacts = request.session.get('searchresults', [])
        cids = [c.id for c in contacts]
        qscontacts = Contact.objects.filter(id__in=cids)
    else:
        css = ContactSavedSearch.objects.get(pk=results)
        qscontacts = css.contact_list.all()
    if sortby != '':
        qscontacts = qscontacts.order_by(sortby)
    form = BasicSearch()
    sharedtags = getsharedtags(qscontacts)
    unsharedtags = [t.name for t in Tag.objects.exclude(name__in=sharedtags)]
    # render the results page

    checked_contacts = request.session.get('checked_contacts', [])

    print("%s" % (checked_contacts))

    return object_list(request, qscontacts, paginate_by=paginate_by, page=page, template_name=rtemplate, extra_context={"checked_contacts": checked_contacts, "bform":form, "contactattrs":contactattrs, "sharedtags":sharedtags, "unsharedtags":unsharedtags})
예제 #23
0
        html_message = render_to_string("email_register_message.html", locals())
        
        mail = EmailMultiAlternatives("Registration Confirmation for %s" %(event, ),
                                      message,
                                      FROM_EMAIL,
                                      ['"%s %s" <%s>' % (contact.first_name, contact.last_name, contact.email)]
                                      )

        mail.attach_alternative(html_message, "text/html")
        mail.send()
        email_log.info("Sent Email To:%s - From:%s - Subject:%s" % (contact.email, FROM_EMAIL, "Registration Confirmation For %s" %(event, )))
        
        
        return render_to_response('registration_pending.html', locals())
    
    return render_to_response('event_email_register.html', locals())

def register(request, slug):
    event = get(Event, slug=slug)
    if request.method == 'POST':
        form = EventRegistrationForm(request.POST)

        if form.is_valid():
            registrant = form.save(event = event)
            pending_signal.send(sender=registrant, contact=registrant.contact, event=event)

            return render_to_response('registration_pending.html', locals())
        else:
            return render_to_response('event_register.html', locals())

    else:
예제 #24
0
def registrants_pending_status(request, id):
    event = get(Event, pk=id)
    registrants = event.registrant_set.all()

    return render_to_response('registrants_pending_status.html', locals())
예제 #25
0
def event_show(request, slug):
    object = get(Event, slug=slug)
    return render_to_response('event_details.html', locals())
예제 #26
0
def list(request):
    reports = Report.objects.all()
    return render_to_response('reports/list.html', locals())