Example #1
0
def settings_edit(request, response_format='html'):
    "Settings"

    if not request.user.profile.is_admin('anaf.services'):
        return user_denied(
            request,
            message=
            "You don't have administrator access to the Service Support module"
        )

    if request.POST:
        if 'cancel' not in request.POST:
            form = SettingsForm(request.user.profile, request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('services_settings_view'))
        else:
            return HttpResponseRedirect(reverse('services_settings_view'))
    else:
        form = SettingsForm(request.user.profile)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('services/settings_edit',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Example #2
0
def save_settings(request, cid):
    print 'update_settings request.method = %s' % request.method
    if request.method == 'POST':
        con = get_construct(request.user, cid)
        if not con:
            return JsonResponse({
                'errors': {
                    'all': "Construct with id '%s' not found",
                },
            } % cid, ERROR)
        form = SettingsForm(request.POST, instance=con.settings)
        if form.is_valid():
            form.save()
            con.reset()
            data = {}
            for key, value in form.cleaned_data.items():
                data[key] = str(value)
            return JsonResponse({
                'modified': con.last_modified(),
                'fields': data
            })
        return JsonResponse({
            'errors': form.errors,
        }, ERROR)
    raise Http404
Example #3
0
def settings(request):
    if request.POST:
        settingsForm = SettingsForm(request.POST, instance=request.user)
        if settingsForm.is_valid():
            settingsForm.save()
            messages.info(request, 'User settings saved.')
            return redirect('dashboard')
    else:
        settingsForm = SettingsForm(instance=request.user)
    return render(request, 'settings.html', {'settingsForm': settingsForm})
Example #4
0
def settings(request):
    if request.POST:
        settingsForm = SettingsForm(request.POST, instance=request.user)
        if settingsForm.is_valid():
            settingsForm.save()
            messages.info(request, 'User settings saved.')
            return redirect('dashboard')
    else:
        settingsForm = SettingsForm(instance=request.user)
    return render(request, 'settings.html', {'settingsForm': settingsForm})
Example #5
0
def settings(request, user_id):
    user = get_object_or_404(User, id=user_id)
    if request.user != user and not request.user.is_superuser:
        return HttpResponseForbidden("Forbidden operation.")
    form = SettingsForm(data=request.POST or None,
                        initial={"email": user.email, "intro": user.get_profile().intro})
    if request.method == "POST" and form.is_valid():
        form.save(user)
        return redirect(reverse("user_profile", kwargs={"user_id": user_id}))
    return render(request, "settings.html",
                  {"form": form, "settings_user": user})
Example #6
0
	def post(self):
		args = self.request.arguments()
		post_data = {}
		for arg in args:
			d = self.request.get(arg)
			post_data[arg] = d

		form = SettingsForm(post_data)
		if form.is_valid():
			form.save()

		self.get(form=form)
Example #7
0
def edit_settings(request):
    context = {}
    settings = Settings.get_by_user(request.user)

    if request.method == "POST":
        form = SettingsForm(request.POST, instance=settings)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/settings")
    else:
        form = SettingsForm(instance=settings)

    context["form"] = form
    return r2r(request, "edit_settings", context)
Example #8
0
def edit_settings(request):
    context = {}
    settings = Settings.get_by_user(request.user)

    if request.method == "POST":
        form = SettingsForm(request.POST, instance=settings)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect("/settings")
    else:
        form = SettingsForm(instance=settings)

    context["form"] = form
    return r2r(request, "edit_settings", context)
Example #9
0
def settings_edit(request, response_format='html'):
    "Settings"

    if request.POST:
        form = SettingsForm(request.user.profile, request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('changes_settings_view'))
    else:
        form = SettingsForm(request.user.profile)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('changes/settings_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
Example #10
0
def settings(request, user_id):
    user = get_object_or_404(User, id=user_id)
    if request.user != user and not request.user.is_superuser:
        return HttpResponseForbidden("Forbidden operation.")
    form = SettingsForm(data=request.POST or None,
                        initial={
                            "email": user.email,
                            "intro": user.get_profile().intro
                        })
    if request.method == "POST" and form.is_valid():
        form.save(user)
        return redirect(reverse("user_profile", kwargs={"user_id": user_id}))
    return render(request, "settings.html", {
        "form": form,
        "settings_user": user
    })
Example #11
0
def settings(request):

    context_vars = {}
    context_vars.update(csrf(request))

    if request.method == 'POST':
        form = SettingsForm(request.POST, request.FILES, instance=request.user.profile)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('profile', kwargs={"username": request.user.username}))
    else:
        form = SettingsForm(instance=request.user.profile)

    context_vars.update({'form': form})
    template = 'settings.html'
    context = RequestContext(request)
    return render_to_response(template, context_vars, context_instance=context)
Example #12
0
def settings_edit(request, response_format='html'):
    "Settings"

    if request.POST:
        form = SettingsForm(request.user.profile, request.POST)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(reverse('changes_settings_view'))
    else:
        form = SettingsForm(request.user.profile)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('changes/settings_edit',
                              context,
                              context_instance=RequestContext(request),
                              response_format=response_format)
Example #13
0
def settings_edit(request, response_format='html'):
    "Settings edit"

    if request.POST:
        if 'cancel' not in request.POST:
            form = SettingsForm(request.user.profile, request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('account_settings_view'))
        else:
            return HttpResponseRedirect(reverse('account_settings_view'))
    else:
        form = SettingsForm(request.user.profile)

    return render_to_response('account/settings_edit',
                              {'form': Markup(form.as_ul())},
                              context_instance=RequestContext(request),
                              response_format=response_format)
Example #14
0
def save_settings(request, cid):
	print 'update_settings request.method = %s' % request.method
	if request.method == 'POST':
		con = get_construct(request.user, cid)
		if not con:
			return JsonResponse({
				'errors': {
					'all':"Construct with id '%s' not found",
					},} % cid, ERROR)
		form = SettingsForm(request.POST, instance=con.settings)
		if form.is_valid():
			form.save()
			con.reset()
			data = {}
			for key,value in form.cleaned_data.items():
				data[key] = str(value);
			return JsonResponse({'modified': con.last_modified(), 'fields': data})
		return JsonResponse({'errors': form.errors,}, ERROR)
	raise Http404
Example #15
0
def settings_edit(request, response_format='html'):
    "Settings edit"

    if request.POST:
        if 'cancel' not in request.POST:
            form = SettingsForm(
                request.user.profile, request.POST, request.FILES)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('core_settings_view'))
        else:
            return HttpResponseRedirect(reverse('core_settings_view'))

    else:
        form = SettingsForm(request.user.profile)

    return render_to_response('core/administration/settings_edit',
                              {
                                  'form': form,
                              },
                              context_instance=RequestContext(request), response_format=response_format)
Example #16
0
def settings_edit(request, response_format='html'):
    "Settings"

    if not request.user.profile.is_admin('anaf.services'):
        return user_denied(request,
                           message="You don't have administrator access to the Service Support module")

    if request.POST:
        if 'cancel' not in request.POST:
            form = SettingsForm(request.user.profile, request.POST)
            if form.is_valid():
                form.save()
                return HttpResponseRedirect(reverse('services_settings_view'))
        else:
            return HttpResponseRedirect(reverse('services_settings_view'))
    else:
        form = SettingsForm(request.user.profile)

    context = _get_default_context(request)
    context.update({'form': form})

    return render_to_response('services/settings_edit', context,
                              context_instance=RequestContext(request), response_format=response_format)
Example #17
0
def settings(request):
    settings_form = SettingsForm()
    next = request.REQUEST.get('next')
    if request.method == 'POST':
        settings_form = SettingsForm(request.POST)
        if settings_form.is_valid():
            username = settings_form.save()
            request.session['username'] = username
            if next:
                return HttpResponseRedirect(next)
            return HttpResponseRedirect('/')

    context = {
        'settings_form': settings_form,
        'next': next,
    }
    return render_to_response('settings.html', context,
        context_instance=RequestContext(request))
Example #18
0
def settings(request):
    settings_form = SettingsForm()
    next = request.REQUEST.get('next')
    if request.method == 'POST':
        settings_form = SettingsForm(request.POST)
        if settings_form.is_valid():
            username = settings_form.save()
            request.session['username'] = username
            if next:
                return HttpResponseRedirect(next)
            return HttpResponseRedirect('/')

    context = {
        'settings_form': settings_form,
        'next': next,
    }
    return render_to_response('settings.html',
                              context,
                              context_instance=RequestContext(request))
Example #19
0
def cms_settings(request):
    config = None
    message = get_messages(request)
    config = lookup_settings(request)
    
    if request.method == 'POST':
        form = SettingsForm(request.POST)
        if form.is_valid():
            email = request.user.email
            delete_settings(email=email)
            config = form.save()
            config.email = request.user.email
            config.save()
            message = "Settings saved."
            request.session['cms_email'] = config.email
            return HttpResponseRedirect(settings.ROOT_URL+'options/')
    else:
        form = SettingsForm(instance=config)
    
    
    return direct_to_template(request, 'settings.html', 
        {'config': config, 'message': message, 'form': form, })
Example #20
0
def render_settings(request):
    user = User.objects.get(pk=request.user.id)
    delete_account_request = False
    try:
        delete_request = DeleteAccountRequest.objects.filter(user=user).first()
        if delete_request:
            delete_account_request = True
    except ObjectDoesNotExist:
        delete_account_request = False
    try:
        settings = UserProfile.objects.get(user=user)
        user_groups = user.groups.all()
        group_list = []
        for g in user_groups:
            group_list.append({
                'id': g.id,
                'name': g.name,
                'receive_updates': settings.get_group_notification_preference(g.id)
            })
    except UserProfile.DoesNotExist:
        settings = None
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=user)
        if settings:
            settings_form = SettingsForm(request.POST, instance=settings)
        else:
            settings_form = SettingsForm(request.POST)
        if user_form.is_valid() and settings_form.is_valid():
            user = user_form.save()
            settings = settings_form.save(commit=False)
            settings.user_id = request.user.id
            settings.save()
            settings_form.save_m2m()
            # update the interface language
            if settings.interface_lang:
                translation.activate(settings.interface_lang)
                request.LANGUAGE_CODE = translation.get_language()

            # get group update settings
            for g in group_list:
                gets_notif = True if request.POST.get('group_notif_' + str(g.get('id'))) else False
                settings.set_group_notification_preference(g.get('id'), gets_notif)
                g['receive_updates'] = gets_notif

            # check for delete account requests
            if request.POST.get('delete_account_option') == 'delete':
                DeleteAccountRequest.objects.create(user=user)
                delete_account_request = True
                settings.set_active(False)
                ctx = {
                    "user": user,
                }
                html = render_to_string('emails/delete_account_request.html', ctx)
                email = EmailMessage('Delete user account request',
                                     html,
                                     constance.config.NO_REPLY_EMAIL,
                                     [config.ACTIVATE_USER_EMAIL])
                email.content_subtype = "html"
                email.send()
            else:
                if delete_account_request:
                    DeleteAccountRequest.objects.filter(user=user).delete()
                    delete_account_request = False
                    settings.set_active(True)
            messages.add_message(request, messages.SUCCESS, 'Profile Update Successful.')
    else:
        user_form = UserForm(instance=request.user)
        settings_form = SettingsForm(instance=settings)

    errors = dict(user_form.errors)
    errors.update(settings_form.errors)

    interest_types = {'languages': [(lang.id, lang.name) for lang in Language.objects.all()],
                      'interests': [(interest.id, interest.name) for interest in Interest.objects.all()],
                      'regions': [(region.id, region.name) for region in Region.objects.all()]}

    return render_to_response('users/user_settings_v2.html',
                              {
                                'settings_form': settings_form,
                                'user_form': user_form,
                                'group_list': group_list,
                                'interest_types': interest_types,
                                'has_password': user.has_usable_password(),
                                'errors': errors,
                                'delete_account_request': delete_account_request,
                              },
                              context_instance=RequestContext(request))
Example #21
0
def render_settings(request):
    user = User.objects.get(pk=request.user.id)
    delete_account_request = False
    try:
        delete_request = DeleteAccountRequest.objects.filter(user=user).first()
        if delete_request:
            delete_account_request = True
    except ObjectDoesNotExist:
        delete_account_request = False
    try:
        settings = UserProfile.objects.get(user=user)
        user_groups = user.groups.all()
        group_list = []
        for g in user_groups:
            group_list.append({
                'id':
                g.id,
                'name':
                g.name,
                'receive_updates':
                settings.get_group_notification_preference(g.id)
            })
    except UserProfile.DoesNotExist:
        settings = None
    if request.method == 'POST':
        user_form = UserForm(request.POST, instance=user)
        if settings:
            settings_form = SettingsForm(request.POST, instance=settings)
        else:
            settings_form = SettingsForm(request.POST)
        if user_form.is_valid() and settings_form.is_valid():
            user = user_form.save()
            settings = settings_form.save(commit=False)
            settings.user_id = request.user.id
            settings.save()
            settings_form.save_m2m()
            # update the interface language
            if settings.interface_lang:
                translation.activate(settings.interface_lang)
                request.LANGUAGE_CODE = translation.get_language()

            # get group update settings
            for g in group_list:
                gets_notif = True if request.POST.get(
                    'group_notif_' + str(g.get('id'))) else False
                settings.set_group_notification_preference(
                    g.get('id'), gets_notif)
                g['receive_updates'] = gets_notif

            # check for delete account requests
            if request.POST.get('delete_account_option') == 'delete':
                DeleteAccountRequest.objects.create(user=user)
                delete_account_request = True
                settings.set_active(False)
                ctx = {
                    "user": user,
                }
                html = render_to_string('emails/delete_account_request.html',
                                        ctx)
                email = EmailMessage('Delete user account request', html,
                                     constance.config.NO_REPLY_EMAIL,
                                     [config.ACTIVATE_USER_EMAIL])
                email.content_subtype = "html"
                email.send()
            else:
                if delete_account_request:
                    DeleteAccountRequest.objects.filter(user=user).delete()
                    delete_account_request = False
                    settings.set_active(True)
            messages.add_message(request, messages.SUCCESS,
                                 'Profile Update Successful.')
    else:
        user_form = UserForm(instance=request.user)
        settings_form = SettingsForm(instance=settings)

    errors = dict(user_form.errors)
    errors.update(settings_form.errors)

    interest_types = {
        'languages': [(lang.id, lang.name) for lang in Language.objects.all()],
        'interests':
        [(interest.id, interest.name) for interest in Interest.objects.all()],
        'regions':
        [(region.id, region.name) for region in Region.objects.all()]
    }

    return render_to_response('users/user_settings_v2.html', {
        'settings_form': settings_form,
        'user_form': user_form,
        'group_list': group_list,
        'interest_types': interest_types,
        'has_password': user.has_usable_password(),
        'errors': errors,
        'delete_account_request': delete_account_request,
    },
                              context_instance=RequestContext(request))