def register(request): if request.method == 'POST': user_form = RASUserCreationForm(request.POST) if user_form.is_valid(): new_user = user_form.save() send_localized_mail( new_user, _('Subscription to R.A.S.'), 'RandoAmisSecours/account/register_email.html', { 'URL': request.build_absolute_uri( reverse('accounts.register.confirm', args=[new_user.pk, new_user.profile.hash_id])), 'fullname': new_user.get_full_name() }) return render(request, 'RandoAmisSecours/account/register_end.html') else: messages.error(request, _("Some information are missing or mistyped")) else: user_form = RASUserCreationForm() return render(request, 'RandoAmisSecours/account/register.html', {'user_form': user_form})
def accept(request, request_id): friend_request = get_object_or_404(FriendRequest, pk=request_id, to=request.user) new_friend = get_object_or_404(Profile, user=friend_request.user) # Add the friend request.user.profile.friends.add(new_friend) friend_request.delete() send_localized_mail( new_friend.user, _('[R.A.S.] Friend request accepted'), 'RandoAmisSecours/friends/request_accepted_email.html', { 'from': request.user.get_full_name(), 'to': new_friend.user.get_full_name() }) messages.success( request, _("«%(name)s» added to your friends") % ({ 'name': new_friend.user.get_full_name() })) return HttpResponseRedirect(reverse('accounts.profile'))
def invite(request, user_id): # Cannot invite ourself if request.user.pk == int(user_id): raise Http404 # Find the friend to request new_friend = get_object_or_404(Profile, user__pk=user_id) # Create the friend request friend_request = FriendRequest(user=request.user, to=new_friend.user) friend_request.save() # Alert the requester and the requested send_localized_mail( new_friend.user, _('[R.A.S.] Friend request'), 'RandoAmisSecours/friends/request_email.html', { 'from': friend_request.user.get_full_name(), 'to': friend_request.to.get_full_name(), 'accept': request.build_absolute_uri( reverse('friends.accept', args=[friend_request.pk])), 'refuse': request.build_absolute_uri( reverse('friends.refuse', args=[friend_request.pk])) }) messages.success( request, _("Friend request sent to «%(name)s»") % ({ 'name': new_friend.user.get_full_name() })) return HttpResponseRedirect(reverse('friends.search'))
def accept(request, request_id): friend_request = get_object_or_404(FriendRequest, pk=request_id, to=request.user) new_friend = get_object_or_404(Profile, user=friend_request.user) # Add the friend request.user.profile.friends.add(new_friend) friend_request.delete() send_localized_mail(new_friend.user, _('[R.A.S.] Friend request accepted'), 'RandoAmisSecours/friends/request_accepted_email.html', {'from': request.user.get_full_name(), 'to': new_friend.user.get_full_name()}) messages.success(request, _("«%(name)s» added to your friends") % ({'name': new_friend.user.get_full_name()})) return HttpResponseRedirect(reverse('accounts.profile'))
def register(request): if request.method == 'POST': user_form = RASUserCreationForm(request.POST) if user_form.is_valid(): new_user = user_form.save() send_localized_mail(new_user, _('Subscription to R.A.S.'), 'RandoAmisSecours/account/register_email.html', {'URL': request.build_absolute_uri(reverse('accounts.register.confirm', args=[new_user.pk, new_user.profile.hash_id])), 'fullname': new_user.get_full_name()}) return render(request, 'RandoAmisSecours/account/register_end.html') else: messages.error(request, _("Some information are missing or mistyped")) else: user_form = RASUserCreationForm() return render(request, 'RandoAmisSecours/account/register.html', {'user_form': user_form})
def handle(self, *args, **kwargs): if kwargs.get('base_url', None) is None: raise CommandError('url option is required') self.stdout.write("Listing alerting outings") self.stdout.write("Interval %d" % (kwargs['interval'])) now = datetime.utcnow().replace(tzinfo=utc) outings = Outing.objects.filter(status=CONFIRMED, ending__lt=now) for outing in outings: self.stdout.write(" - %s" % (outing.name)) # Late outings if outing.ending <= now and now < outing.alert: minutes = (now - outing.alert).seconds / 60.0 minutes = minutes % kwargs['alert'] if 0 <= minutes and minutes < kwargs['interval']: self.stdout.write("Sending mail to owner") # send a mail to the user, translated into the right language send_localized_mail(outing.user, _('[R.A.S] Alert'), 'RandoAmisSecours/alert/late.html', {'URL': "%s%s" % (kwargs['base_url'], reverse('outings.details', args=[outing.pk])), 'SAFE_URL': "%s%s" % (kwargs['base_url'], reverse('outings.finish', args=[outing.pk]))}) # Alerting outings elif outing.alert <= now: minutes = (now - outing.alert).seconds / 60.0 minutes = minutes % kwargs['alert'] self.stdout.write(" minutes: %d" % (minutes)) if 0 <= minutes and minutes < kwargs['interval']: self.stdout.write("emailing friends") # Send on mail per user translated into the right language for friend_profile in outing.user.profile.friends.all(): send_localized_mail(friend_profile.user, _('[R.A.S] Alert'), 'RandoAmisSecours/alert/alert.html', {'fullname': outing.user.get_full_name(), 'URL': "%s%s" % (kwargs['base_url'], reverse('outings.details', args=[outing.pk])), 'name': outing.name, 'ending': outing.ending})
def invite(request, user_id): # Cannot invite ourself if request.user.pk == int(user_id): raise Http404 # Find the friend to request new_friend = get_object_or_404(Profile, user__pk=user_id) # Create the friend request friend_request = FriendRequest(user=request.user, to=new_friend.user) friend_request.save() # Alert the requester and the requested send_localized_mail(new_friend.user, _('[R.A.S.] Friend request'), 'RandoAmisSecours/friends/request_email.html', {'from': friend_request.user.get_full_name(), 'to': friend_request.to.get_full_name(), 'accept': request.build_absolute_uri(reverse('friends.accept', args=[friend_request.pk])), 'refuse': request.build_absolute_uri(reverse('friends.refuse', args=[friend_request.pk]))}) messages.success(request, _("Friend request sent to «%(name)s»") % ({'name': new_friend.user.get_full_name()})) return HttpResponseRedirect(reverse('friends.search'))