Show More
@@ -744,6 +744,32 b' def is_svn_without_proxy(repository):' | |||||
744 | return False |
|
744 | return False | |
745 |
|
745 | |||
746 |
|
746 | |||
|
747 | def discover_user(author): | |||
|
748 | """ | |||
|
749 | Tries to discover RhodeCode User based on the autho string. Author string | |||
|
750 | is typically `FirstName LastName <email@address.com>` | |||
|
751 | """ | |||
|
752 | ||||
|
753 | # if author is already an instance use it for extraction | |||
|
754 | if isinstance(author, User): | |||
|
755 | return author | |||
|
756 | ||||
|
757 | # Valid email in the attribute passed, see if they're in the system | |||
|
758 | _email = author_email(author) | |||
|
759 | if _email != '': | |||
|
760 | user = User.get_by_email(_email, case_insensitive=True, cache=True) | |||
|
761 | if user is not None: | |||
|
762 | return user | |||
|
763 | ||||
|
764 | # Maybe it's a username, we try to extract it and fetch by username ? | |||
|
765 | _author = author_name(author) | |||
|
766 | user = User.get_by_username(_author, case_insensitive=True, cache=True) | |||
|
767 | if user is not None: | |||
|
768 | return user | |||
|
769 | ||||
|
770 | return None | |||
|
771 | ||||
|
772 | ||||
747 | def email_or_none(author): |
|
773 | def email_or_none(author): | |
748 | # extract email from the commit string |
|
774 | # extract email from the commit string | |
749 | _email = author_email(author) |
|
775 | _email = author_email(author) | |
@@ -765,30 +791,13 b' def email_or_none(author):' | |||||
765 | return None |
|
791 | return None | |
766 |
|
792 | |||
767 |
|
793 | |||
768 | def discover_user(author): |
|
|||
769 | # if author is already an instance use it for extraction |
|
|||
770 | if isinstance(author, User): |
|
|||
771 | return author |
|
|||
772 |
|
||||
773 | # Valid email in the attribute passed, see if they're in the system |
|
|||
774 | _email = email(author) |
|
|||
775 | if _email != '': |
|
|||
776 | user = User.get_by_email(_email, case_insensitive=True, cache=True) |
|
|||
777 | if user is not None: |
|
|||
778 | return user |
|
|||
779 |
|
||||
780 | # Maybe it's a username? |
|
|||
781 | _author = author_name(author) |
|
|||
782 | user = User.get_by_username(_author, case_insensitive=True, |
|
|||
783 | cache=True) |
|
|||
784 | if user is not None: |
|
|||
785 | return user |
|
|||
786 |
|
||||
787 | return None |
|
|||
788 |
|
||||
789 |
|
||||
790 | def link_to_user(author, length=0, **kwargs): |
|
794 | def link_to_user(author, length=0, **kwargs): | |
791 | user = discover_user(author) |
|
795 | user = discover_user(author) | |
|
796 | # user can be None, but if we have it already it means we can re-use it | |||
|
797 | # in the person() function, so we save 1 intensive-query | |||
|
798 | if user: | |||
|
799 | author = user | |||
|
800 | ||||
792 | display_person = person(author, 'username_or_name_or_email') |
|
801 | display_person = person(author, 'username_or_name_or_email') | |
793 | if length: |
|
802 | if length: | |
794 | display_person = shorter(display_person, length) |
|
803 | display_person = shorter(display_person, length) | |
@@ -803,11 +812,9 b' def link_to_user(author, length=0, **kwa' | |||||
803 |
|
812 | |||
804 |
|
813 | |||
805 | def person(author, show_attr="username_and_name"): |
|
814 | def person(author, show_attr="username_and_name"): | |
806 | # attr to return from fetched user |
|
|||
807 | person_getter = lambda usr: getattr(usr, show_attr) |
|
|||
808 | user = discover_user(author) |
|
815 | user = discover_user(author) | |
809 | if user: |
|
816 | if user: | |
810 |
return |
|
817 | return getattr(user, show_attr) | |
811 | else: |
|
818 | else: | |
812 | _author = author_name(author) |
|
819 | _author = author_name(author) | |
813 | _email = email(author) |
|
820 | _email = email(author) |
General Comments 0
You need to be logged in to leave comments.
Login now