def package_edit( request, package_name ): #assert False, package_name from fl.packages.forms import PackageForm package = get_object_or_404(Package, name = package_name) profile = request.user.get_profile() if request.POST: pkgform = PackageForm(request.POST, instance=package) if pkgform.is_valid(): pkgform.save() m = Meteora(True,"Package %s Saved" % package.name ) m.notebook_close_page("nbPackage","edit") m.notebook_select_page("nbPackage","index") return m.json_response() else: m = Meteora(False,"error") m.form_invalid(pkgform) return m.json_response() else: if profile.is_community(): pkgForm = PackageForm(instance=package) else: pkgForm = None statusForm = None return render_to_response("packages/package_edit.html", { "package": package,'statusform': statusForm,'packageform':pkgForm }, context_instance=RequestContext(request))
def login(request, template_name='meteora/login.html', redirect_field_name=REDIRECT_FIELD_NAME): "Displays the login form and handles the login action." redirect_to = request.REQUEST.get(redirect_field_name, '') if request.method == "POST": form = MeteoraAuthenticationForm(data=request.POST) if form.is_valid(): # Light security check -- make sure redirect_to isn't garbage. if not redirect_to or '//' in redirect_to or '' in redirect_to: from django.conf import settings redirect_to = settings.LOGIN_REDIRECT_URL print "redirect_to: %s" % redirect_to from django.contrib.auth import login login(request, form.get_user()) if request.session.test_cookie_worked(): request.session.delete_test_cookie() m = Meteora() m.redirectTo(redirect_to) return m.json_response() else: m = Meteora(False, "Invalid Form") m.form_invalid("table-login",form) return m.json_response() else: form = MeteoraAuthenticationForm(request) request.session.set_test_cookie() return render_to_response(template_name, { 'form': form, redirect_field_name: redirect_to }, context_instance=RequestContext(request))
def register(request): if request.POST: form = UserCreationForm(request.POST) if form.is_valid(): user = form.save() p = Profile.objects.create(user=user) group_community = get_object_or_404(Group, name = "community") user.groups.add(group_community) m = Meteora(True, "New user: %s register" %user.username) m.redirectTo(reverse('fl.auth.views.login')) return m.json_response() else: m = Meteora(False, "Form Invalid") m.form_invalid(form) return m.json_response() else: form = UserCreationForm() return render_to_response("registration/register.html", {'form':form})