def default(request): data = {} if request.user.is_authenticated(): user = request.user user_data = {} user_data.update({ 'username': user.username.encode('utf8'), 'email': user.email.encode('utf8'), 'id': user.id, 'img_not_found': '/images/team/houssem.jpg'.encode('utf8'), 'thamb_img_url': get_file_media_url(user.profile, 'cover'), 'studentsCount': 54, 'coursesCount': 4, 'collaboratorsCount': 12, 'tasksCount': 12, 'invitationsCount': 2, }) data = json.dumps(user_data, encoding="utf-8", cls=MeeMJSONEncoder) return render(request, 'home/in.html', {'userdata': data}) else: account_reset_password = reverse_lazy("account_student_reset_password") return render(request, 'home/out.html', { 'userdata': data, 'account_reset_password': account_reset_password })
def get_item(request, id): try: course = Course.objects.get(author=request.user.id, pk=id) data = model_to_dict(course, fields=course_fields) data.update( model_to_dict(course.informations, fields=course_informations)) data['about'] = data['about'].replace('/media', 'http://127.0.0.1:8000/media') data['cover'] = '' if course.informations.cover is not None: data['cover'] = get_file_media_url(course.informations, 'cover') return data except Course.DoesNotExist: raise Http404
def default(request): data ={} if request.user.is_authenticated (): user = request.user user_data = {} user_data.update({ 'username' : user.username.encode('utf8'), 'email' : user.email.encode('utf8'), 'id' : user.id , 'img_not_found' : '/images/team/houssem.jpg'.encode('utf8'), 'thamb_img_url' : get_file_media_url(user.profile, 'cover'), 'studentsCount' : 54, 'coursesCount' : 4 , 'collaboratorsCount' : 12, 'tasksCount' : 12, 'invitationsCount' : 2, }); data = json.dumps(user_data, encoding="utf-8", cls=MeeMJSONEncoder) return render(request,'home/in.html', { 'userdata' : data}) else : account_reset_password = reverse_lazy("account_student_reset_password") return render(request,'home/out.html', { 'userdata' : data, 'account_reset_password' : account_reset_password})
def default(request): if request.user.is_authenticated (): userid = request.user.id user = User.objects.select_related().get(pk=userid) model = model_to_dict(user, ['username', 'email']) invitations_count = CollaboratorInvitation.objects.filter(fromuser=user.id).count() invitations_recieved = CollaboratorInvitation.objects.filter(usermail=user.email).count() studentCount = 0 course_count = 0 courses = user.courses.all () for course in courses : studentCount = studentCount + course.students.count () course_count = course_count + 1 staff_count = Team.objects.annotate(staff_count=Count('members')).filter(owner=user).values ('staff_count') staff_count = staff_count[0]['staff_count'] """ collaborations = user.my_collaborators.select_related().all() other_collaborations = user.my_collaborators_with_others.select_related().all() """ collaborators = Collaborator.objects.filter(source=user).all () member_in_teams = TeamMemberShip.objects.filter(member__in=collaborators).select_related('team', 'assigned_tasks').all () tasks_count = 0 todos = [] # FIXME for item in member_in_teams : tasks_count += item.team.assigned_tasks.count() for task in item.team.tasks.all() : task_ = model_to_dict(task, ['id', 'start', 'end', 'title']) if getattr(task, 'label', False): task_.update({ 'color' : task.label.color}) else : task_.update({ 'color' : '#ccc'}) todos.append(task_) model.update({ 'id' : user.id , 'username' : user.email, 'img_not_found' : '/images/team/houssem.jpg', 'thamb_img_url' : get_file_media_url (user.profile.cover, 'location'), 'studentsCount' : studentCount, 'coursesCount' : course_count , 'collaboratorsCount' : staff_count, 'tasksCount' : tasks_count, 'invitations_sent_count' : invitations_count, 'invitations_recieved_count' : invitations_recieved, 'progress' : get_profile_progress(user), }); recents = user.history.all() paginator = Paginator(recents, 10) recents_activities = paginator.page(1) recents_activities_list = [] for item in recents_activities : item_ = model_to_dict(item, fields=['id', 'action_time', 'object_id']) item_.update({'model' : item.content_type.model}) recents_activities_list.append(item_) #.push(item_) model.update({'history' : recents_activities_list}) model.update({'todos' : todos}) return render_json(request, json.dumps(model, encoding="utf-8", cls=MeeMJSONEncoder)) else : return dump_and_render_json(request, None)
def default(request): if request.user.is_authenticated(): userid = request.user.id user = User.objects.select_related().get(pk=userid) model = model_to_dict(user, ['username', 'email']) invitations_count = CollaboratorInvitation.objects.filter( fromuser=user.id).count() invitations_recieved = CollaboratorInvitation.objects.filter( usermail=user.email).count() studentCount = 0 course_count = 0 courses = user.courses.all() for course in courses: studentCount = studentCount + course.students.count() course_count = course_count + 1 staff_count = Team.objects.annotate( staff_count=Count('members')).filter( owner=user).values('staff_count') staff_count = staff_count[0]['staff_count'] """ collaborations = user.my_collaborators.select_related().all() other_collaborations = user.my_collaborators_with_others.select_related().all() """ collaborators = Collaborator.objects.filter(source=user).all() member_in_teams = TeamMemberShip.objects.filter( member__in=collaborators).select_related('team', 'assigned_tasks').all() tasks_count = 0 todos = [] # FIXME for item in member_in_teams: tasks_count += item.team.assigned_tasks.count() for task in item.team.tasks.all(): task_ = model_to_dict(task, ['id', 'start', 'end', 'title']) if getattr(task, 'label', False): task_.update({'color': task.label.color}) else: task_.update({'color': '#ccc'}) todos.append(task_) model.update({ 'id': user.id, 'username': user.email, 'img_not_found': '/images/team/houssem.jpg', 'thamb_img_url': get_file_media_url(user.profile.cover, 'location'), 'studentsCount': studentCount, 'coursesCount': course_count, 'collaboratorsCount': staff_count, 'tasksCount': tasks_count, 'invitations_sent_count': invitations_count, 'invitations_recieved_count': invitations_recieved, 'progress': get_profile_progress(user), }) recents = user.history.all() paginator = Paginator(recents, 10) recents_activities = paginator.page(1) recents_activities_list = [] for item in recents_activities: item_ = model_to_dict(item, fields=['id', 'action_time', 'object_id']) item_.update({'model': item.content_type.model}) recents_activities_list.append(item_) #.push(item_) model.update({'history': recents_activities_list}) model.update({'todos': todos}) return render_json( request, json.dumps(model, encoding="utf-8", cls=MeeMJSONEncoder)) else: return dump_and_render_json(request, None)
def get_profile_infos(request): user = User.objects.get(id=request.user.id) data = model_to_dict(user, fields=user_fields) data.update(model_to_dict(user.profile, fields=profile_fields)) data['cover'] = get_file_media_url(user.profile, 'cover') return data
def get_profile_infos(request): user = User.objects.get(id=request.user.id) data = model_to_dict(user, fields = user_fields) data.update(model_to_dict(user.profile, fields = profile_fields)) data['cover'] = get_file_media_url(user.profile, 'cover') return data
def upload_cover(request): profile = helper.upload_cover(request) return JsonResponse({'cover': get_file_media_url(profile, 'cover')})
def hydrate_student(student): item = model_to_dict(student, fields=['username', 'id', 'email']) item['thumb'] = get_file_media_url(student.profile, 'cover') return item
def upload_cover(request, id): courseinfo = helper.upload_cover(request, id) data = {'url': get_file_media_url(courseinfo, 'cover')} data = json.dumps(data, encoding="utf-8", cls=MeeMJSONEncoder) return render_json(request, data)
def upload_image(request, id): document = helper.upload_file(request, id) data = {'url': get_file_media_url(document)} data = json.dumps(data, encoding="utf-8", cls=MeeMJSONEncoder) return render_json(request, data)
def upload_cover(request, id): courseinfo = helper.upload_cover (request, id) data = {'url' : get_file_media_url (courseinfo, 'cover')} data = json.dumps(data, encoding="utf-8", cls=MeeMJSONEncoder) return render_json(request, data)
def upload_image(request, id): document = helper.upload_file (request, id) data = {'url' : get_file_media_url (document)} data = json.dumps(data, encoding="utf-8", cls=MeeMJSONEncoder) return render_json(request, data)
def upload_cover(request): profile = helper.upload_cover(request) return JsonResponse ({'cover' : get_file_media_url(profile, 'cover')})