def my_account(request, action=None, **kwargs): myaccount = True template = "webadmin/myaccount.html" conn = None try: conn = kwargs["conn"] except: logger.error(traceback.format_exc()) info = {'today': _("Today is %(tday)s") % {'tday': datetime.date.today()}, 'myaccount':myaccount} eventContext = {'userId':conn.getEventContext().userId,'userName':conn.getEventContext().userName, 'isAdmin':conn.getEventContext().isAdmin, 'version': request.session.get('version')} myaccount = BaseExperimenter(conn) myaccount.getMyDetails() myaccount.getOwnedGroups() edit_mode = False photo_size = None form = None form_file = UploadPhotoForm() if action == "save": if request.method != 'POST': return HttpResponseRedirect(reverse(viewname="wamyaccount", args=["edit"])) else: email_check = conn.checkEmail(request.REQUEST.get('email'), myaccount.experimenter.email) form = MyAccountForm(data=request.POST.copy(), initial={'groups':myaccount.otherGroups}, email_check=email_check) if form.is_valid(): firstName = form.cleaned_data['first_name'] middleName = form.cleaned_data['middle_name'] lastName = form.cleaned_data['last_name'] email = form.cleaned_data['email'] institution = form.cleaned_data['institution'] defaultGroup = form.cleaned_data['default_group'] myaccount.updateMyAccount(firstName, lastName, email, defaultGroup, middleName, institution) return HttpResponseRedirect(reverse("wamyaccount")) elif action == "upload": if request.method == 'POST': form_file = UploadPhotoForm(request.POST, request.FILES) if form_file.is_valid(): controller = BaseUploadFile(conn) controller.attach_photo(request.FILES['photo']) return HttpResponseRedirect(reverse("wamyaccount")) elif action == "crop": x1 = long(request.REQUEST.get('x1')) x2 = long(request.REQUEST.get('x2')) y1 = long(request.REQUEST.get('y1')) y2 = long(request.REQUEST.get('y2')) box = (x1,y1,x2,y2) conn.cropExperimenterPhoto(box) return HttpResponseRedirect(reverse("wamyaccount")) elif action == "editphoto": form = MyAccountForm(initial={'omename': myaccount.experimenter.omeName, 'first_name':myaccount.experimenter.firstName, 'middle_name':myaccount.experimenter.middleName, 'last_name':myaccount.experimenter.lastName, 'email':myaccount.experimenter.email, 'institution':myaccount.experimenter.institution, 'default_group':myaccount.defaultGroup, 'groups':myaccount.otherGroups}) photo_size = conn.getExperimenterPhotoSize() if photo_size is not None: edit_mode = True photo_size = conn.getExperimenterPhotoSize() form = MyAccountForm(initial={'omename': myaccount.experimenter.omeName, 'first_name':myaccount.experimenter.firstName, 'middle_name':myaccount.experimenter.middleName, 'last_name':myaccount.experimenter.lastName, 'email':myaccount.experimenter.email, 'institution':myaccount.experimenter.institution, 'default_group':myaccount.defaultGroup, 'groups':myaccount.otherGroups}) context = {'info':info, 'eventContext':eventContext, 'form':form, 'form_file':form_file, 'ldapAuth': myaccount.ldapAuth, 'edit_mode':edit_mode, 'photo_size':photo_size, 'myaccount':myaccount} t = template_loader.get_template(template) c = Context(request,context) return HttpResponse(t.render(c))
def manage_experimenter(request, action, eid=None, **kwargs): experimenters = True template = "webadmin/experimenter_form.html" conn = None try: conn = kwargs["conn"] except: logger.error(traceback.format_exc()) info = {'today': _("Today is %(tday)s") % {'tday': datetime.date.today()}, 'experimenters':experimenters} if kwargs['firsttime']: info['message'] = kwargs["msg"] eventContext = {'userName':conn.getEventContext().userName, 'isAdmin':conn.getEventContext().isAdmin, 'version': request.session.get('version')} controller = BaseExperimenter(conn, eid) if action == 'new': form = ExperimenterForm(initial={'with_password':True, 'active':True, 'available':controller.otherGroupsInitialList()}) context = {'info':info, 'eventContext':eventContext, 'form':form} elif action == 'create': if request.method != 'POST': return HttpResponseRedirect(reverse(viewname="wamanageexperimenterid", args=["new"])) else: name_check = conn.checkOmeName(request.REQUEST.get('omename')) email_check = conn.checkEmail(request.REQUEST.get('email')) initial={'with_password':True} exclude = list() if len(request.REQUEST.getlist('other_groups')) > 0: others = controller.getSelectedGroups(request.REQUEST.getlist('other_groups')) initial['others'] = others initial['default'] = [(g.id, g.name) for g in others] exclude.extend([g.id for g in others]) available = controller.otherGroupsInitialList(exclude) initial['available'] = available form = ExperimenterForm(initial=initial, data=request.REQUEST.copy(), name_check=name_check, email_check=email_check) if form.is_valid(): logger.debug("Create experimenter form:" + str(form.cleaned_data)) omename = form.cleaned_data['omename'] firstName = form.cleaned_data['first_name'] middleName = form.cleaned_data['middle_name'] lastName = form.cleaned_data['last_name'] email = form.cleaned_data['email'] institution = form.cleaned_data['institution'] admin = toBoolean(form.cleaned_data['administrator']) active = toBoolean(form.cleaned_data['active']) defaultGroup = form.cleaned_data['default_group'] otherGroups = form.cleaned_data['other_groups'] password = form.cleaned_data['password'] controller.createExperimenter(omename, firstName, lastName, email, admin, active, defaultGroup, otherGroups, password, middleName, institution) return HttpResponseRedirect(reverse("waexperimenters")) context = {'info':info, 'eventContext':eventContext, 'form':form} elif action == 'edit' : initial={'omename': controller.experimenter.omeName, 'first_name':controller.experimenter.firstName, 'middle_name':controller.experimenter.middleName, 'last_name':controller.experimenter.lastName, 'email':controller.experimenter.email, 'institution':controller.experimenter.institution, 'administrator': controller.experimenter.isAdmin(), 'active': controller.experimenter.isActive(), 'default_group': controller.defaultGroup, 'other_groups':controller.otherGroups} initial['default'] = controller.default others = controller.others initial['others'] = others if len(others) > 0: exclude = [g.id.val for g in others] else: exclude = [controller.defaultGroup] available = controller.otherGroupsInitialList(exclude) initial['available'] = available form = ExperimenterForm(initial=initial) context = {'info':info, 'eventContext':eventContext, 'form':form, 'eid': eid, 'ldapAuth': controller.ldapAuth} elif action == 'save': if request.method != 'POST': return HttpResponseRedirect(reverse(viewname="wamanageexperimenterid", args=["edit", controller.experimenter.id])) else: name_check = conn.checkOmeName(request.REQUEST.get('omename'), controller.experimenter.omeName) email_check = conn.checkEmail(request.REQUEST.get('email'), controller.experimenter.email) initial={'active':True} exclude = list() if len(request.REQUEST.getlist('other_groups')) > 0: others = controller.getSelectedGroups(request.REQUEST.getlist('other_groups')) initial['others'] = others initial['default'] = [(g.id, g.name) for g in others] exclude.extend([g.id for g in others]) available = controller.otherGroupsInitialList(exclude) initial['available'] = available form = ExperimenterForm(initial=initial, data=request.POST.copy(), name_check=name_check, email_check=email_check) if form.is_valid(): logger.debug("Update experimenter form:" + str(form.cleaned_data)) omename = form.cleaned_data['omename'] firstName = form.cleaned_data['first_name'] middleName = form.cleaned_data['middle_name'] lastName = form.cleaned_data['last_name'] email = form.cleaned_data['email'] institution = form.cleaned_data['institution'] admin = toBoolean(form.cleaned_data['administrator']) active = toBoolean(form.cleaned_data['active']) defaultGroup = form.cleaned_data['default_group'] otherGroups = form.cleaned_data['other_groups'] controller.updateExperimenter(omename, firstName, lastName, email, admin, active, defaultGroup, otherGroups, middleName, institution) return HttpResponseRedirect(reverse("waexperimenters")) context = {'info':info, 'eventContext':eventContext, 'form':form, 'eid': eid, 'ldapAuth': controller.ldapAuth} elif action == "delete": controller.deleteExperimenter() return HttpResponseRedirect(reverse("waexperimenters")) else: return HttpResponseRedirect(reverse("waexperimenters")) t = template_loader.get_template(template) c = Context(request, context) rsp = t.render(c) return HttpResponse(rsp)