我看到它的方式,我将不得不编写一个自定义视图/表单,以便能够从仪表板执行此 *** 作,并具有待处理的帐户注册源.
任何指针将不胜感激.
相关代码:
import loggingfrom django.vIEws import genericfrom django.contrib.auth.models import Userfrom django.contrib import messagesfrom django.core.mail import send_mailfrom django import httpfrom django.core.urlresolvers import reversefrom django.template.loader import get_templatefrom django.template import Contextfrom apps.gateway import formsfrom oscar.apps.customer.forms import generate_usernamelogger = logging.getLogger('gateway')class GatewayVIEw(generic.FormVIEw): template_name = 'gateway/form.HTML' form_class = forms.GatewayForm def form_valID(self,form): real_email = form.cleaned_data['email'] username = generate_username() password = generate_username() email = 'dashboard-user-%s@oscarcommerce.com' % username user = self.create_dashboard_user(username,email,password) self.send_confirmation_email(real_email,user,password) logger.info("Created dashboard user #%d for %s",user.ID,real_email) messages.success( self.request,"The credentials for a dashboard user have been sent to %s" % real_email) return http.httpResponseRedirect(reverse('gateway')) def create_dashboard_user(self,username,password): user = User.objects.create_user(username,password) user.is_staff = True user.save() return user def send_confirmation_email(self,real_email,password): msg = get_template('gateway/email.txt').render(Context({ 'email': user.email,'password': password })) send_mail('Dashboard access to Oscar sandBox',msg,'blackhole@latest.oscarcommerce.com',[real_email])
https://github.com/django-oscar/django-oscar/blob/master/sites/sandbox/apps/gateway/views.py
只要电子邮件有效,这只会自动创建一个is_staff用户.
django.contrib.auth.mIDdleware.AuthenticationMIDdleware
它可以访问用户模型.
我在网关电子邮件请求模板form.HTML中放置了一个if块:
{% if user.is_authenticated %} {% if user.is_superuser %} <email form> {% else %} <insufficIEnt user privileges partial template> {% endif %} <not logged in partial template> {% endif %}
同样对于零售访问,我用过
{% if user.is_authenticated %} {% if user.is_staff%} <email form> {% else %} <insufficIEnt user privileges partial template> {% endif %} <not logged in partial template> {% endif %}
这样,只有超级用户才能创建员工,工作人员和超级用户都可以创建零售帐户.
总结以上是内存溢出为你收集整理的python – 限制仪表板用户Django-Oscar(沙盒网关应用程序)全部内容,希望文章能够帮你解决python – 限制仪表板用户Django-Oscar(沙盒网关应用程序)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)