Ejemplo n.º 1
0
def my_account(request, action=None, conn=None, **kwargs):
    template = "webadmin/myaccount.html"

    experimenter, defaultGroup, otherGroups, isLdapUser, hasAvatar = prepare_experimenter(
        conn)
    try:
        defaultGroupId = defaultGroup.id
    except:
        defaultGroupId = None

    ownedGroups = ownedGroupsInitial(conn)

    password_form = ChangePassword()

    form = None
    if action == "save":
        if request.method != 'POST':
            return HttpResponseRedirect(
                reverse(viewname="wamyaccount", args=["edit"]))
        else:
            email_check = conn.checkEmail(request.REQUEST.get('email'),
                                          experimenter.email)
            form = MyAccountForm(data=request.POST.copy(),
                                 initial={'groups': 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']
                defaultGroupId = form.cleaned_data['default_group']
                conn.updateMyAccount(experimenter, firstName, lastName, email,
                                     defaultGroupId, middleName, institution)
                return HttpResponseRedirect(reverse("wamyaccount"))

    else:
        form = MyAccountForm(
            initial={
                'omename': experimenter.omeName,
                'first_name': experimenter.firstName,
                'middle_name': experimenter.middleName,
                'last_name': experimenter.lastName,
                'email': experimenter.email,
                'institution': experimenter.institution,
                'default_group': defaultGroupId,
                'groups': otherGroups
            })

    photo_size = conn.getExperimenterPhotoSize()

    context = {
        'form': form,
        'ldapAuth': isLdapUser,
        'experimenter': experimenter,
        'ownedGroups': ownedGroups,
        'password_form': password_form
    }
    context['template'] = template
    return context
Ejemplo n.º 2
0
def my_account(request, action=None, conn=None, **kwargs):
    template = "webadmin/myaccount.html"

    experimenter, defaultGroup, otherGroups, isLdapUser, hasAvatar = \
        prepare_experimenter(conn)
    try:
        defaultGroupId = defaultGroup.id
    except:
        defaultGroupId = None

    ownedGroups = ownedGroupsInitial(conn)

    password_form = ChangePassword()

    form = None
    if action == "save":
        if request.method != 'POST':
            return HttpResponseRedirect(reverse(viewname="wamyaccount",
                                                args=["edit"]))
        else:
            email_check = conn.checkEmail(request.REQUEST.get('email'),
                                          experimenter.email)
            form = MyAccountForm(data=request.POST.copy(),
                                 initial={'groups': 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']
                defaultGroupId = form.cleaned_data['default_group']
                conn.updateMyAccount(
                    experimenter, firstName, lastName, email, defaultGroupId,
                    middleName, institution)
                return HttpResponseRedirect(reverse("wamyaccount"))

    else:
        form = MyAccountForm(initial={
            'omename': experimenter.omeName,
            'first_name': experimenter.firstName,
            'middle_name': experimenter.middleName,
            'last_name': experimenter.lastName,
            'email': experimenter.email,
            'institution': experimenter.institution,
            'default_group': defaultGroupId,
            'groups': otherGroups})

    context = {'form': form, 'ldapAuth': isLdapUser,
               'experimenter': experimenter, 'ownedGroups': ownedGroups,
               'password_form': password_form}
    context['freeSpace'] = conn.getFreeSpace()
    context['template'] = template
    return context
Ejemplo n.º 3
0
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))