django.contrib.auth.models.User.objects.get.username - python examples

Here are the examples of the python api django.contrib.auth.models.User.objects.get.username taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

6 Examples 7

3 View Complete Implementation : decorators.py
Copyright Apache License 2.0
Author : PeteAndersen
def username_case_redirect(function):
    def wrap(request, *args, **kwargs):
        profile_name = kwargs.get('profile_name')
        if profile_name:
            try:
                username = User.objects.get(username__iexact=profile_name).username
                if username != profile_name:
                    kwargs['profile_name'] = username
                    return HttpResponseRedirect(reverse(request.resolver_match.view_name, kwargs=kwargs))
            except User.DoesNotExist:
                return render(request, 'herders/profile/not_found.html', status=404)
        return function(request, *args, **kwargs)

    wrap.__doc__ = function.__doc__
    wrap.__name__ = function.__name__
    return wrap

3 View Complete Implementation : models.py
Copyright GNU General Public License v2.0
Author : welliamcao
    def to_json(self):
        try:
            username = User.objects.get(id=self.script_user).username
        except Exception as ex:
            username = '未知'
        json_format = {
            "id":self.id,           
            "script_name":self.script_name,
            "script_args":self.script_args,
            "script_business":self.script_business,
            "script_user":username,
            "script_server":self.script_server,
            "script_group":self.script_group,
            "script_tags":self.script_tags,
            "script_inventory_groups":self.script_inventory_groups,
            "create_time":datetime.strftime(self.create_time, '%Y-%m-%d %H:%M:%S'),
            "update_date":datetime.strftime(self.update_date, '%Y-%m-%d %H:%M:%S'),
        }
        return  json_format 

0 View Complete Implementation : serializers.py
Copyright GNU General Public License v2.0
Author : welliamcao
    def get_manage_name(self,obj):
        try:
            return User.objects.get(id=obj.manage).username
        except:
            return "未知"

0 View Complete Implementation : models.py
Copyright GNU General Public License v2.0
Author : welliamcao
    def get_buy_user(self):
        try:
            return User.objects.get(id=self.buy_user).username
        except:
            return '未知'  

0 View Complete Implementation : models.py
Copyright GNU General Public License v2.0
Author : welliamcao
    def get_username(self):
        try:
            return User.objects.get(id=self.idle_user).username
        except:
            return "未知"

0 View Complete Implementation : models.py
Copyright GNU General Public License v2.0
Author : welliamcao
    def to_json(self):
        try:
            username = User.objects.get(id=self.playbook_user).username
        except Exception as ex:
            username = '未知'
        json_format = {
            "id":self.id,           
            "playbook_name":self.playbook_name,
            "playbook_desc":self.playbook_desc,
            "playbook_vars":self.playbook_vars,
            "playbook_type":self.playbook_type,
            "playbook_file":str(self.playbook_file),
            "playbook_business":self.playbook_business,
            "playbook_user":username,
            "playbook_server":self.playbook_server,
            "playbook_group":self.playbook_group,
            "playbook_tags":self.playbook_tags,
            "playbook_inventory_groups":self.playbook_inventory_groups,
            "create_time":datetime.strftime(self.create_time, '%Y-%m-%d %H:%M:%S'),
            "update_date":datetime.strftime(self.update_date, '%Y-%m-%d %H:%M:%S'),
        }
        return  json_format