def ready(self): # WARNING: AS THIS IS NOT A FUNCTIONAL PROGRAMMING LANGUAGE, # OPERATIONS MAY HAVE SIDE EFFECTS. # DO NOT REMOVE THINKING THE IMPORT IS UNUSED. # noinspection PyUnresolvedReferences from . import signals, jinja2 from django.contrib.flatpages.models import FlatPage from django.contrib.flatpages.admin import FlatPageAdmin from django.contrib import admin from reversion.admin import VersionAdmin class FlatPageVersionAdmin(VersionAdmin, FlatPageAdmin): pass admin.site.unregister(FlatPage) admin.site.register(FlatPage, FlatPageVersionAdmin) from judge.models import Language, Profile from django.contrib.auth.models import User try: lang = Language.get_python2() for user in User.objects.filter(profile=None): # These poor profileless users profile = Profile(user=user, language=lang) profile.save() except DatabaseError: pass
def __init__(self): lang = Language.get_python2() for user in User.objects.filter(profile=None): # These poor profileless users profile = Profile(user=user, language=lang) profile.save() raise MiddlewareNotUsed
def ready(self): # WARNING: AS THIS IS NOT A FUNCTIONAL PROGRAMMING LANGUAGE, # OPERATIONS MAY HAVE SIDE EFFECTS. # DO NOT REMOVE THINKING THE IMPORT IS UNUSED. # noinspection PyUnresolvedReferences from . import signals, jinja2 # noqa: F401, imported for side effects from django.contrib.flatpages.models import FlatPage from django.contrib.flatpages.admin import FlatPageAdmin from django.contrib import admin admin.site.unregister(FlatPage) admin.site.register(FlatPage, FlatPageAdmin) from judge.models import Language, Profile from django.contrib.auth.models import User try: lang = Language.get_python3() for user in User.objects.filter(profile=None): # These poor profileless users profile = Profile(user=user, language=lang) profile.save() except DatabaseError: pass
def __init__(self): lang = Language.objects.get_or_create(key='PY2', name='Python 2')[0] # Create a default language for user in User.objects.filter(profile=None): # These poor profileless users profile = Profile(user=user, language=lang) profile.save() raise MiddlewareNotUsed
def ready(self): # WARNING: AS THIS IS NOT A FUNCTIONAL PROGRAMMING LANGUAGE, # OPERATIONS MAY HAVE SIDE EFFECTS. # DO NOT REMOVE THINKING THE IMPORT IS UNUSED. # noinspection PyUnresolvedReferences from . import signals, jinja2 from django.contrib.flatpages.models import FlatPage from django.contrib.flatpages.admin import FlatPageAdmin from django.contrib import admin from django.contrib.auth.models import User from admin.user import MyUserAdmin from reversion.admin import VersionAdmin class FlatPageVersionAdmin(VersionAdmin, FlatPageAdmin): suit_form_size = { 'fields': { 'content': apps.SUIT_FORM_SIZE_FULL }, } admin.site.unregister(FlatPage) admin.site.register(FlatPage, FlatPageVersionAdmin) admin.site.unregister(User) admin.site.register(User, MyUserAdmin) from judge.models import Language, Profile try: lang = Language.get_python2() for user in User.objects.filter(profile=None): # These poor profileless users profile = Profile(user=user, language=lang) profile.save() except DatabaseError: pass
def test_get_user_css_class(self): self.assertEqual( Profile.get_user_css_class(display_rank='abcdef', rating=None, rating_colors=True), 'rating rate-none abcdef', ) self.assertEqual( Profile.get_user_css_class(display_rank='admin', rating=1200, rating_colors=True), 'rating rate-expert admin', ) self.assertEqual( Profile.get_user_css_class(display_rank=1111, rating=1199, rating_colors=True), 'rating rate-amateur 1111', ) self.assertEqual( Profile.get_user_css_class(display_rank='random', rating=1199, rating_colors=False), 'random', )
def handle(self, *args, **options): usr = User(username=options['name'], email=options['email'], is_active=True) usr.set_password(options['password']) usr.is_superuser = options['superuser'] usr.is_staff = options['staff'] usr.save() profile = Profile(user=usr) profile.language = Language.objects.get(key=options['language']) profile.save()
def main(): for line in sys.stdin: student_id, name = [word.strip(' \t\n\r') for word in line.split(',')] # create user, with its password being the same as its student ID, # and its email being its NTU mail user = User.objects.create_user(username=student_id, email=(student_id + '@ntu.edu.tw'), password=student_id) user.save() # create its corresponding profile profile = Profile(user=user, name=name) profile.save()
class UserResource(resources.ModelResource): name = fields.Field(attribute='profile__name') about = fields.Field(attribute='profile__about') organizations = fields.Field(widget=widgets.ManyToManyWidget(model=Organization, field='key'), attribute='profile__organizations') _profile = Profile() def init_instance(self, row=None): usr = super(UserResource, self).init_instance(row) usr.is_active = True self._profile.language = Language.objects.get(key=DEFAULT_USER_LANGUAGE) usr.profile = self._profile return usr def before_save_instance(self, instance, using_transactions, dry_run): if not using_transactions and dry_run: # we don't have transactions and we want to do a dry_run pass else: instance.set_password(instance.password) def after_save_instance(self, instance, using_transactions, dry_run): if not using_transactions and dry_run: # we don't have transactions and we want to do a dry_run pass else: Profile.objects.update_or_create(user=instance, defaults=self._profile) class Meta: model = User fields = ('username', 'password', 'email',) export_order = ('username', 'email', 'name', 'about', 'organizations') import_id_fields = ('username',)
def main(): for line in sys.stdin: student_id, name = line.split(',') # wipe out the trailing '\n' name = name[:-1] # create user, with its password being the same as its student ID, # and its email being its NTU mail user = User.objects.create_user(username=student_id, email=(student_id + '@ntu.edu.tw'), password=student_id) user.save() # create its corresponding profile profile = Profile(user=user, name=name) profile.save()
def make_profile(backend, user, response, is_new=False, *args, **kwargs): if is_new: if not hasattr(user, 'profile'): profile = Profile(user=user) profile.language = Language.get_python2() if backend.name == 'google-oauth2': profile.name = response['displayName'] elif backend.name in ('github', 'facebook') and 'name' in response: profile.name = response['name'] else: logger.info('Info from %s: %s', backend.name, response) profile.save() form = ProfileForm(instance=profile, user=user) else: data = backend.strategy.request_data() logger.info(data) form = ProfileForm(data, instance=user.profile, user=user) if form.is_valid(): with transaction.atomic(), revisions.create_revision(): form.save() revisions.set_user(user) revisions.set_comment('Updated on registration') return return render(backend.strategy.request, 'registration/profile_creation.jade', { 'title': 'Create your profile', 'form': form })
def ready(self): # WARNING: AS THIS IS NOT A FUNCTIONAL PROGRAMMING LANGUAGE, # OPERATIONS MAY HAVE SIDE EFFECTS. # DO NOT REMOVE THINKING THE IMPORT IS UNUSED. # noinspection PyUnresolvedReferences from . import signals, jinja2 from judge.models import Language, Profile from django.contrib.auth.models import User try: lang = Language.get_python2() for user in User.objects.filter(profile=None): # These poor profileless users profile = Profile(user=user, language=lang) profile.save() except DatabaseError: pass
def get_user(username, data): if not data: element = Element('span') element.text = username return element element = Element('span', {'class': Profile.get_user_css_class(*data)}) link = Element('a', {'href': reverse('user_page', args=[username])}) link.text = username element.append(link) return element
def make_profile(backend, user, response, is_new=False, *args, **kwargs): if is_new: if not hasattr(user, 'profile'): profile = Profile(user=user) profile.language = Language.get_python2() logger.info('Info from %s: %s', backend.name, response) profile.save() return # form = ProfileForm(instance=profile, user=user) else: data = backend.strategy.request_data() logger.info(data) return form = ProfileForm(data, instance=user.profile, user=user) if form.is_valid(): with transaction.atomic(), revisions.create_revision(): form.save() revisions.set_user(user) revisions.set_comment('Updated on registration') return
def make_profile(backend, user, response, is_new=False, *args, **kwargs): if is_new: if not hasattr(user, 'profile'): profile = Profile(user=user) profile.language = Language.get_python2() logger.info('Info from %s: %s', backend.name, response) profile.save() form = ProfileForm(instance=profile, user=user) else: data = backend.strategy.request_data() logger.info(data) form = ProfileForm(data, instance=user.profile, user=user) if form.is_valid(): with transaction.atomic(), revisions.create_revision(): form.save() revisions.set_user(user) revisions.set_comment('Updated on registration') return return render(backend.strategy.request, 'registration/profile_creation.html', { 'title': 'Create your profile', 'form': form })
def make_profile(backend, user, response, is_new=False, *args, **kwargs): if is_new: if not hasattr(user, "profile"): profile = Profile(user=user) profile.language = Language.get_python2() if backend.name == "google-oauth2": profile.name = response["displayName"] elif backend.name in ("github", "facebook") and "name" in response: profile.name = response["name"] else: logger.info("Info from %s: %s", backend.name, response) profile.save() form = ProfileForm(instance=profile, user=user) else: data = backend.strategy.request_data() logger.info(data) form = ProfileForm(data, instance=user.profile, user=user) if form.is_valid(): with transaction.atomic(), revisions.create_revision(): form.save() revisions.set_user(user) revisions.set_comment("Updated on registration") return return render( backend.strategy.request, "registration/profile_creation.jade", {"title": "Create your profile", "form": form}, )
def make_profile(backend, user, response, is_new=False, *args, **kwargs): if is_new: if not hasattr(user, 'profile'): profile = Profile(user=user) profile.language = Language.get_python3() logger.info('Info from %s: %s', backend.name, response) profile.save() form = ProfileForm(instance=profile, user=user) else: data = backend.strategy.request_data() logger.info(data) form = ProfileForm(data, instance=user.profile, user=user) if form.is_valid(): with transaction.atomic(): form.save() return return render(backend.strategy.request, 'registration/profile_creation.html', { 'title': 'Create your profile', 'form': form, })
def __call__(self, request): path_match = admin_change_re.match(request.path) if path_match: try: user_id = int(path_match.group(1)) user_obj = User.objects.get(id=user_id) if user_obj: user_profile = Profile.objects.filter(user=user_obj).first() if user_profile is None: Profile(user=user_obj, language=admin_change_default_lang).save() except: pass response = self.get_response(request) return response
def css_class(self): return Profile.get_user_css_class(self.display_rank, self.rating)