def conversation(database, user, admin_user): conversation = Conversation(user_id=user.id, from_user_id=user.id, to_user_id=admin_user.id, shared_id=uuid.uuid4()) conversation.save() return conversation
def start_new_conversation_from_profile(request, recipent_pk): recipent = get_user_model().objects.get(pk=recipent_pk) if request.method == 'POST': form = forms.StartNewConversationFromProfile(request.POST) if form.is_valid(): new_conversation = Conversation( subject=form.cleaned_data['subject'], initiator=request.user, recipent=recipent) new_conversation.save() first_message = Message(coversation=new_conversation, sender=request.user, receiver=recipent, content=form.cleaned_data['message']) first_message.save() return redirect('conversations:conversation_panel', conversation_pk=new_conversation.pk) else: # TODO add error page print('error creating conversation - need to have page here') elif request.method == 'GET': form = forms.StartNewConversationFromProfile() return render(request, 'conversations/start_new_conversation.html', context={ 'recipent': recipent, 'form': form })
def more_conversations(request): start_at = int(request.POST["start_at"]) try: recent_conversations = Conversation.objects_by_account(request.account).all()[start_at:start_at+5] return HttpResponse(simplejson.dumps( {"fragments":{"more_conversations":render_to_string("dashboard/_recent_conversations.html", locals())}})) except: return HttpResponse(simplejson.dumps( {"fragments":{"more_conversations":""}}))
def _account_numbers_dict(account): start_of_this_year = datetime.date(month=1, day=1, year=datetime.date.today().year) total_donations = Donation.objects_by_account(account).filter(date__gte=start_of_this_year).count() if not total_donations: total_donations = 0 total_donors = Donation.objects_by_account(account).filter(date__gte=start_of_this_year).order_by().all().aggregate(Count('donor', distinct=True))["donor__count"] if not total_donors: total_donors = 0 total_donation_amount = Donation.objects_by_account(account).filter(date__gte=start_of_this_year).order_by().all().aggregate(Sum('amount'))["amount__sum"] if not total_donation_amount: total_donation_amount = 0 average_donation = Donation.objects_by_account(account).filter(date__gte=start_of_this_year).order_by().all().aggregate(Avg('amount'))["amount__avg"] if not average_donation: average_donation = 0 total_volunteer_hours = CompletedShift.objects_by_account(account).filter(date__gte=start_of_this_year).order_by().all().aggregate(Sum('duration'))["duration__sum"] if not total_volunteer_hours: total_volunteer_hours = 0 total_people = Person.objects_by_account(account).count() total_orgs = Organization.objects_by_account(account).count() total_groups = Group.objects_by_account(account).count() total_tags = Tag.objects_by_account(account).count() total_taggeditems = TaggedItem.objects_by_account(account).count() recent_conversations = Conversation.objects_by_account(account).all()[:5] return locals()