Example #1
0
func (cdb ComplaintDB) getComplaintsByQuery(q *datastore.Query, memKey string) ([]types.Complaint, error) {
	keys, complaints, err := cdb.getMaybeCachedComplaintsByQuery(q, memKey)
	if err != nil {
		return nil, err
	}

	// Data fixups !
	for i, _ := range complaints {
		FixupComplaint(&complaints[i], keys[i])
	}

	sort.Sort(types.ComplaintsByTimeDesc(complaints))

	return complaints, nil
}
Example #2
0
func GenerateEmail(c appengine.Context, cap types.ComplaintsAndProfile) (*mail.Message, error) {
	buf := new(bytes.Buffer)
	err := templates.ExecuteTemplate(buf, "email-bundle", cap)
	if err != nil {
		return nil, err
	}

	var bcc = []string{
		fmt.Sprintf("*****@*****.**"), //, cap.Profile.CallerCode),
	}
	var dests = []string{
		cap.Profile.EmailAddress,
	}
	//if cap.Profile.CcSfo == true {
	//	dests = append(dests, kOfficalComplaintEmail)
	//}

	// In ascending order
	sort.Sort(sort.Reverse(types.ComplaintsByTimeDesc(cap.Complaints)))

	subject := fmt.Sprintf("Daily report summary for %s", cap.Profile.FullName)
	if cap.Profile.CallerCode != "" {
		subject = fmt.Sprintf("Daily report summary for [%s]", cap.Profile.CallerCode)
	}

	msg := &mail.Message{
		ReplyTo:  cap.Profile.EmailAddress,
		Sender:   kSenderEmail, // cap.Profile.EmailAddress,
		To:       dests,
		Bcc:      bcc,
		Subject:  subject,
		HTMLBody: buf.String(),
	}

	return msg, nil
}