def relation_begin(request): # TODO We should use Django forms, or better: use sweet Ajax d = {} for t in ('who', 'with', 'how'): if t not in request.POST: raise ValueError, "Missing attr %s" % t if t == 'how' and request.POST[t] == 'null': d[t] = None else: d[t] = _id(request.POST[t]) if not Es.user_may_begin_relation(request.user, d['who'], d['with'], d['how']): raise PermissionDenied # Check whether such a relation already exists dt = now() ok = False try: next(Es.query_relations(who=d['who'], _with=d['with'], how=d['how'], _from=dt, until=DT_MAX)) except StopIteration: ok = True if not ok: raise ValueError, "This relation already exists" # Add the relation! Es.add_relation(d['who'], d['with'], d['how'], dt, DT_MAX) giedo.sync() return redirect_to_referer(request)
def relation_begin(request): # TODO We should use Django forms, or better: use sweet Ajax d = {} for t in ("who", "with", "how"): if t not in request.POST: raise ValueError, "Missing attr %s" % t if t == "how" and (not request.POST[t] or request.POST[t] == "null"): d[t] = None else: d[t] = _id(request.POST[t]) if not Es.user_may_begin_relation(request.user, d["who"], d["with"], d["how"]): raise PermissionDenied # Check whether such a relation already exists dt = now() ok = False try: next(Es.query_relations(who=d["who"], _with=d["with"], how=d["how"], _from=dt, until=DT_MAX)) except StopIteration: ok = True if not ok: raise ValueError, _("Deze relatie bestaat al") # Add the relation! relation_id = Es.add_relation(d["who"], d["with"], d["how"], dt, DT_MAX) # Notify informacie # TODO (rik) leave out 'als lid' Es.notify_informacie("relation_begin", request.user, relation=relation_id) giedo.sync_async(request) return redirect_to_referer(request)
def relation_begin(request): # TODO We should use Django forms, or better: use sweet Ajax d = {} for t in ('who', 'with', 'how'): if t not in request.POST: raise ValueError, "Missing attr %s" % t if t == 'how' and (not request.POST[t] or request.POST[t] == 'null'): d[t] = None else: d[t] = _id(request.POST[t]) if not Es.user_may_begin_relation(request.user, d['who'], d['with'], d['how']): raise PermissionDenied # Check whether such a relation already exists dt = now() ok = False try: next(Es.query_relations(who=d['who'], _with=d['with'], how=d['how'], _from=dt, until=DT_MAX)) except StopIteration: ok = True if not ok: raise ValueError, "This relation already exists" # Add the relation! Es.add_relation(d['who'], d['with'], d['how'], dt, DT_MAX) # Notify informacie if request.user._id == d['who']: Es.notify_informacie("%s heeft zich ingeschreven als %s %s" % ( request.user.full_name, Es.by_id(d['how']).humanName if d['how'] else 'lid', Es.by_id(d['with']).humanName.genitive)) else: # TODO (rik) leave out 'als lid' Es.notify_informacie("%s is nu %s %s" % ( Es.by_id(d['who']).humanName, Es.by_id(d['how']).humanName if d['how'] else 'lid', Es.by_id(d['with']).humanName.genitive)) giedo.sync_async(request) return redirect_to_referer(request)
def relation_begin(request): # TODO We should use Django forms, or better: use sweet Ajax d = {} for t in ('who', 'with', 'how'): if t not in request.POST: raise ValueError("Missing attr %s" % t) if t == 'how' and (not request.POST[t] or request.POST[t] == 'null'): d[t] = None else: d[t] = _id(request.POST[t]) if not Es.user_may_begin_relation(request.user, d['who'], d['with'], d['how']): raise PermissionDenied # Check whether such a relation already exists dt = now() ok = False try: next( Es.query_relations(who=d['who'], _with=d['with'], how=d['how'], _from=dt, until=DT_MAX)) except StopIteration: ok = True if not ok: messages.info(request, _("Deze relatie bestaat al")) return redirect_to_referer(request) # Add the relation! relation_id = Es.add_relation(d['who'], d['with'], d['how'], dt, DT_MAX) # Notify informacie # TODO (rik) leave out 'als lid' Es.notify_informacie('relation_begin', request.user, relation=relation_id) giedo.sync_async(request) return redirect_to_referer(request)
def secr_add_user(request): if 'secretariaat' not in request.user.cached_groups_names: raise PermissionDenied if request.method == 'POST': form = AddUserForm(request.POST) if form.is_valid(): fd = form.cleaned_data # First, create the entity. u = Es.User({ 'types': ['user'], 'names': [fd['username']], 'humanNames': [{ 'human': fd['first_name'] + ' ' + fd['last_name'] }], 'person': { 'titles': [], 'nick': fd['first_name'], 'given': None, 'family': fd['last_name'], 'dateOfBirth': date_to_dt(fd['dateOfBirth']) }, 'email': fd['email'], 'address': { 'street': fd['addr_street'], 'number': fd['addr_number'], 'zip': fd['addr_zip'], 'city': fd['addr_city'] }, 'telephone': fd['telephone'], 'studies': [{ 'institute': _id(fd['study_inst']), 'study': _id(fd['study']), 'from': DT_MIN, 'until': DT_MAX, 'number': fd['study_number'] }], 'is_active': True, 'password': None }) logging.info("Added user %s" % fd['username']) u.save() # Then, add the relations. groups = ['leden'] if fd['incasso']: groups.append('incasso') else: groups.append('geen-incasso') for group in groups: Es.add_relation(u, Es.id_by_name(group, use_cache=True), _from=date_to_dt(fd['dateJoined'])) for l in fd['addToList']: Es.add_relation(u, Es.id_by_name(l, use_cache=True), _from=now()) # Let giedo synch. to create the e-mail adresses, unix user, etc. # TODO use giedo.async() and let giedo send the welcome e-mail giedo.sync() # Create a new password and send it via e-mail pwd = pseudo_randstr() u.set_password(pwd) giedo.change_password(str(u.name), pwd, pwd) render_then_email("leden/set-password.mail.html", u, { 'user': u, 'password': pwd }) # Send the welcome e-mail render_then_email("leden/welcome.mail.html", u, {'u': u}) Es.notify_informacie('adduser', request.user, entity=u._id) return HttpResponseRedirect( reverse('user-by-name', args=(fd['username'], ))) else: form = AddUserForm() return render(request, 'leden/secr_add_user.html', {'form': form})
def secr_add_user(request): if 'secretariaat' not in request.user.cached_groups_names: raise PermissionDenied if request.method == 'POST': form = AddUserForm(request.POST) if form.is_valid(): fd = form.cleaned_data nm = find_name_for_user(fd['first_name'], fd['last_name']) u = Es.User({ 'types': ['user'], 'names': [nm], 'humanNames': [{'human': fd['first_name']+' '+ fd['last_name']}], 'person': { 'titles': [], 'nick': fd['first_name'], 'given': None, 'family': fd['last_name'], 'gender': fd['sex'], 'dateOfBirth': date_to_dt( fd['dateOfBirth']) }, 'emailAddresses': [ {'email': fd['email'], 'from': DT_MIN, 'until': DT_MAX}], 'addresses': [ {'street': fd['addr_street'], 'number': fd['addr_number'], 'zip': fd['addr_zip'], 'city': fd['addr_city'], 'from': DT_MIN, 'until': DT_MAX}], 'telephones': [ {'number': fd['telephone'], 'from': DT_MIN, 'until': DT_MAX}], 'studies': [ {'institute': _id(fd['study_inst']), 'study': _id(fd['study']), 'from': DT_MIN, 'until': DT_MAX, 'number': fd['study_number']}], 'is_active': True, 'password': None }) logging.info("Added user %s" % nm) u.save() Es.add_relation(u, Es.id_by_name('leden', use_cache=True), _from=date_to_dt(fd['dateJoined'])) for l in fd['addToList']: Es.add_relation(u, Es.id_by_name(l, use_cache=True), _from=now()) Es.notify_informacie("%s is ingeschreven als lid." % ( u.humanName)) giedo.sync_async(request) request.user.push_message("Gebruiker toegevoegd. "+ "Let op: hij heeft geen wachtwoord "+ "en hij moet nog gemaild worden.") return HttpResponseRedirect(reverse('user-by-name', args=(nm,))) else: form = AddUserForm() return render_to_response('leden/secr_add_user.html', {'form': form}, context_instance=RequestContext(request))
def secr_add_user(request): if 'secretariaat' not in request.user.cached_groups_names: raise PermissionDenied if request.method == 'POST': form = AddUserForm(request.POST) if form.is_valid(): fd = form.cleaned_data # First, create the entity. u = Es.User({ 'types': ['user'], 'names': [fd['username']], 'humanNames': [{'human': fd['first_name'] + ' ' + fd['last_name']}], 'person': { 'titles': [], 'nick': fd['first_name'], 'given': None, 'family': fd['last_name'], 'dateOfBirth': date_to_dt( fd['dateOfBirth']) }, 'emailAddresses': [ {'email': fd['email'], 'from': DT_MIN, 'until': DT_MAX}], 'addresses': [ {'street': fd['addr_street'], 'number': fd['addr_number'], 'zip': fd['addr_zip'], 'city': fd['addr_city'], 'from': DT_MIN, 'until': DT_MAX}], 'telephones': [ {'number': fd['telephone'], 'from': DT_MIN, 'until': DT_MAX}], 'studies': [ {'institute': _id(fd['study_inst']), 'study': _id(fd['study']), 'from': DT_MIN, 'until': DT_MAX, 'number': fd['study_number']}], 'is_active': True, 'password': None }) logging.info("Added user %s" % fd['username']) u.save() # Then, add the relations. groups = ['leden'] if fd['incasso']: groups.append('incasso') else: groups.append('geen-incasso') for group in groups: Es.add_relation(u, Es.id_by_name(group, use_cache=True), _from=date_to_dt(fd['dateJoined'])) for l in fd['addToList']: Es.add_relation(u, Es.id_by_name(l, use_cache=True), _from=now()) # Let giedo synch. to create the e-mail adresses, unix user, etc. # TODO use giedo.async() and let giedo send the welcome e-mail giedo.sync() # Create a new password and send it via e-mail pwd = pseudo_randstr() u.set_password(pwd) giedo.change_password(str(u.name), pwd, pwd) render_then_email("leden/set-password.mail.txt", u, { 'user': u, 'password': pwd}) # Send the welcome e-mail render_then_email("leden/welcome.mail.txt", u, { 'u': u}) Es.notify_informacie('adduser', request.user, entity=u._id) return HttpResponseRedirect(reverse('user-by-name', args=(fd['username'],))) else: form = AddUserForm() return render_to_response('leden/secr_add_user.html', {'form': form}, context_instance=RequestContext(request))
def secr_add_user(request): if "secretariaat" not in request.user.cached_groups_names: raise PermissionDenied if request.method == "POST": form = AddUserForm(request.POST) if form.is_valid(): fd = form.cleaned_data # First, create the entity. u = Es.User( { "types": ["user"], "names": [fd["username"]], "humanNames": [{"human": fd["first_name"] + " " + fd["last_name"]}], "person": { "titles": [], "nick": fd["first_name"], "given": None, "family": fd["last_name"], "gender": fd["gender"], "dateOfBirth": date_to_dt(fd["dateOfBirth"]), }, "emailAddresses": [{"email": fd["email"], "from": DT_MIN, "until": DT_MAX}], "addresses": [ { "street": fd["addr_street"], "number": fd["addr_number"], "zip": fd["addr_zip"], "city": fd["addr_city"], "from": DT_MIN, "until": DT_MAX, } ], "telephones": [{"number": fd["telephone"], "from": DT_MIN, "until": DT_MAX}], "studies": [ { "institute": _id(fd["study_inst"]), "study": _id(fd["study"]), "from": DT_MIN, "until": DT_MAX, "number": fd["study_number"], } ], "is_active": True, "password": None, } ) logging.info("Added user %s" % fd["username"]) u.save() # Then, add the relations. groups = ["leden"] groups.append({"m": "mannen", "v": "vrouwen"}.get(fd["gender"])) if fd["incasso"]: groups.append("incasso") else: groups.append("geen-incasso") for group in groups: Es.add_relation(u, Es.id_by_name(group, use_cache=True), _from=date_to_dt(fd["dateJoined"])) for l in fd["addToList"]: Es.add_relation(u, Es.id_by_name(l, use_cache=True), _from=now()) # Let giedo synch. to create the e-mail adresses, unix user, etc. # TODO use giedo.async() and let giedo send the welcome e-mail giedo.sync() # Create a new password and send it via e-mail pwd = pseudo_randstr() u.set_password(pwd) giedo.change_password(str(u.name), pwd, pwd) render_then_email("leden/set-password.mail.txt", u, {"user": u, "password": pwd}) # Send the welcome e-mail render_then_email("leden/welcome.mail.txt", u, {"u": u}) Es.notify_informacie("adduser", request.user, entity=u._id) return HttpResponseRedirect(reverse("user-by-name", args=(fd["username"],))) else: form = AddUserForm() return render_to_response("leden/secr_add_user.html", {"form": form}, context_instance=RequestContext(request))