def add_users(self, request, farm_object): added_users = request.POST.getlist('added_user') removed_added_users = request.POST.getlist('removed_added_user') for u in added_users: if u in removed_added_users: continue # Can't remember why the need to strip here, but if really needed, # then probably needed for removed_added_users as well. u = u.strip() try: user = User.objects.get(email = u) farm_object.users.add(user) farm_object.save() except: # User does not exist try: invited_user = InvitedUser.objects.get(email = u) except: # New user. Must send email send_invitation_email(u, request.user, farm_object) invited_user = InvitedUser(email = u) invited_user.save() invited_user.farms.add(farm_object) invited_user.save()
if host=='irrigatorpro': if "test" in PROJECT_ROOT: VIRTUAL_ENV_ROOT = '/www/VirtualEnvs/test/' else: VIRTUAL_ENV_ROOT = '/www/VirtualEnvs/irrigator_pro/' else: VIRTUAL_ENV_ROOT = os.path.join( PROJECT_ROOT, 'VirtualEnvs', 'irrigator_pro') print "VIRTUAL_ENV_ROOT='%s'" % VIRTUAL_ENV_ROOT activate_this = os.path.join(VIRTUAL_ENV_ROOT, 'bin', 'activate_this.py') execfile(activate_this, dict(__file__=activate_this)) # Get settings os.environ.setdefault("DJANGO_SETTINGS_MODULE", "irrigator_pro.settings") from django.contrib.auth.models import User import django django.setup() from farms.invited_user_email import send_invitation_email from farms.models import Farm user = User.objects.get(email='*****@*****.**') farm = Farm.objects.get(name="HHERC") #send_invitation_email("*****@*****.**", user, farm) send_invitation_email("*****@*****.**", user, farm) #send_invitation_email("*****@*****.**", user, farm) #send_invitation_email("*****@*****.**", user, farm)