Exemple #1
0
                                blank=True,
                                null=True,
                                choices=settings.LANGUAGES)

    def name(self):
        return self.user.first_name + ' ' + self.user.last_name

    def __unicode__(self):
        return self.name()


def createPerson(sender, user, request, **kwargs):
    Person.objects.get_or_create(user=user)


user_registered.connect(createPerson)


class PersonAdmin(admin.ModelAdmin):
    list_display = ('id', '__unicode__', 'type')
    list_filter = ('type', )
    search_fields = ('type', )
    actions = ['set_type']

    def set_type(self, request, queryset):
        queryset.update(type=1)

    set_type.short_description = "Vaihda luottamushenkilöksi"


class PersonInline(admin.StackedInline):
Exemple #2
0

def user_created(sender, user, request, **kwargs):
    """
    Called via signals when user registers. Creates different profiles and
    associations
    """
    form = MyRegistrationFormUniqueEmail(request.POST)
    # Update first and last name for user
    user.first_name = form.data['first_name']
    user.last_name = form.data['last_name']
    user.save()


from django_registration.signals import user_registered
user_registered.connect(user_created)

from rest_framework import generics, permissions, serializers

from oauth2_provider.contrib.rest_framework import TokenHasReadWriteScope, TokenHasScope


# first we define the serializers
class UserSerializer(serializers.ModelSerializer):
    class Meta:
        model = User
        fields = ('username', 'email', "first_name", "last_name")


class GroupSerializer(serializers.ModelSerializer):
    class Meta:
Exemple #3
0
from django.contrib.auth.models import Group

from django_registration.signals import user_registered

from editor.models import UserRegionalInfo


def create_userregionalinfo(sender, user, request, **kwarg):
    group, created = Group.objects.get_or_create(name='Reporters')
    user.groups.add(group)
    UserRegionalInfo.objects.create(
        user=user,
        phone=request.POST.get('phone', ''),
        information=request.POST.get('information', ''),
    )


user_registered.connect(create_userregionalinfo)
Exemple #4
0
        reports = user_reports[0:self.account_type.max_archive]
        old_reports = user_reports[self.account_type.max_archive:]

        return [reports, old_reports]

    def is_inst_admin(self):
        return self.role == 'ADMIN'

    # creates new UserProfile when new user registers


def user_registered_callback(sender, user, request, **kwargs):
    profile = UserProfile(user=user)
    profile.account_type = AccountType.objects.get(
        type_id=DEFAULT_ACCOUNT_TYPE)
    profile.org = ''
    profile.save()

    # Update first and last name for user
    user.first_name = request.POST['first_name']
    user.last_name = request.POST['last_name']
    user.save()

    wsrg = WebsiteReportGroup(title="Summary of results for " + str(user))
    wsrg.save()
    user_stats = StatsUser(user=user, ws_report_group=wsrg)
    user_stats.save()


user_registered.connect(user_registered_callback)
Exemple #5
0
from django.urls import path
from . import views
from django_registration.signals import user_registered

user_registered.connect(views.add_user_to_group_users)

urlpatterns = [
    path('', views.index, name='index'),
    path('blog/all', views.BlogListView.as_view(), name='blog-list'),
    path('blogger/all', views.BloggerListView.as_view(), name='blogger-list'),
    path('blog/<int:pk>', views.BlogDetailView.as_view(), name='blog-detail'),
    path('blogger/<int:pk>',
         views.BloggerDetailView.as_view(),
         name='blogger-detail'),
    path('blog/create', views.BlogCreate.as_view(), name='blog-create'),
    path('blogger/create',
         views.BloggerCreate.as_view(),
         name='blogger-create'),
    path('comment/create/<int:pk>',
         views.CommentCreate.as_view(),
         name='comment-create'),
]