def comment_json(comment, **kwargs): return { 'pk': comment.pk, 'date': comment.timelineitem.date.strftime('%Y-%m-%d %H:%M:%S'), 'text': comment.text, 'user': user_json(comment.user), }
def restore_point_json(restore_point, **kwargs): return { 'pk': restore_point.pk, 'date': restore_point.timelineitem.date.strftime('%Y-%m-%d %H:%M:%S'), 'description': restore_point.description, 'user': user_json(restore_point.user), }
def get_queryset(self): try: search_term = self.request.GET['q'] users = find_users(name=search_term)[:5] except KeyError: users = User.objects.filter(is_active=True) return [user_json(u) for u in users]
def restore_point_json(restore_point,**kwargs): return { 'pk': restore_point.pk, 'date': restore_point.timelineitem.date.strftime('%Y-%m-%d %H:%M:%S'), 'description': restore_point.description, 'user': user_json(restore_point.user), }
def get_queryset(self): try: search_term = self.request.GET['q'] users = find_users(name=search_term)[:5] except KeyError: users = User.objects.all() return [user_json(u) for u in users]
def comment_json(comment,**kwargs): return { 'pk': comment.pk, 'date': comment.timelineitem.date.strftime('%Y-%m-%d %H:%M:%S'), 'text': comment.text, 'user': user_json(comment.user), }
def stamp_json(stamp,**kwargs): return { 'pk': stamp.pk, 'date': stamp.timelineitem.date.strftime('%Y-%m-%d %H:%M:%S'), 'status': stamp.status, 'status_display': stamp.get_status_display(), 'user': user_json(stamp.user), }
def stamp_json(stamp, **kwargs): if stamp.pk is None: return { 'pk': None, 'status': 'draft', 'status_display': 'Draft', 'user': None, } else: return { 'pk': stamp.pk, 'date': stamp.timelineitem.date.strftime('%Y-%m-%d %H:%M:%S'), 'status': stamp.status, 'status_display': stamp.get_status_display(), 'user': user_json(stamp.user), }
def get_queryset(self): search_term = self.request.GET['q'] items = [] most_of_each = 5 users = find_users(name=search_term)[:most_of_each] items += [user_json(u) for u in users] projects = Project.objects.filter(Project.filter_can_be_viewed_by(self.request.user)).filter(name__icontains=search_term)[:most_of_each] for p in projects: items.append({ 'id': p.pk, 'profile': reverse('project_index',args=(p.pk,)), 'name': p.name, 'autocomplete_entry': get_template('autocomplete/project.html').render({'project':p}), }) return items
def get_context_data(self, **kwargs): context = super(BaseUpdateView, self).get_context_data(**kwargs) self.object.editoritem.get_parsed_content() context['item_type'] = self.object.editoritem.item_type context['editable'] = self.editable context['can_delete'] = self.can_delete context['can_copy'] = self.can_copy context['project'] = self.object.editoritem.project context['access_rights'] = [{'user': user_json(a.user), 'access_level': a.access} for a in Access.objects.filter(item=self.object.editoritem)] licences = [licence.as_json() for licence in Licence.objects.all()] taxonomies = [{'pk':taxonomy.pk, 'name': taxonomy.name, 'description': taxonomy.description, 'nodes': taxonomy.json} for taxonomy in Taxonomy.objects.all()] self.item_json = context['item_json'] = { 'itemJSON': self.object.edit_dict(), 'editable': self.editable, 'item_type': self.object.editoritem.item_type, 'licences': licences, 'taxonomies': taxonomies, 'ability_frameworks': [editor.views.generic.ability_framework_json(af) for af in editor.models.AbilityFramework.objects.all()], 'previewURL': reverse('{}_preview'.format(self.object.editoritem.item_type), args=(self.object.pk, self.object.editoritem.slug)), 'previewWindow': str(calendar.timegm(time.gmtime())), 'current_stamp': editor.views.generic.stamp_json(self.object.editoritem.get_current_stamp()), } if self.editable: self.item_json['public_access'] = self.object.editoritem.public_access self.item_json['access_rights'] = context['access_rights'] context['versions'] = [] # reversion.get_for_object(self.object) context['stamp_choices'] = editor.models.STAMP_STATUS_CHOICES context['preferred_locale'] = self.request.user.userprofile.language if not self.request.user.is_anonymous else 'en-GB' context['locale_files'] = [code for name, code in settings.GLOBAL_SETTINGS['NUMBAS_LOCALES']] return context
def get_context_data(self, **kwargs): context = super(BaseUpdateView, self).get_context_data(**kwargs) self.object.editoritem.get_parsed_content() context['item_type'] = self.object.editoritem.item_type context['editable'] = self.editable context['can_delete'] = self.can_delete context['can_copy'] = self.can_copy context['project'] = self.object.editoritem.project context['access_rights'] = [{'user': user_json(a.user), 'access_level': a.access} for a in Access.objects.filter(item=self.object.editoritem)] licences = [licence.as_json() for licence in Licence.objects.all()] self.item_json = context['item_json'] = { 'itemJSON': self.object.edit_dict(), 'editable': self.editable, 'item_type': self.object.editoritem.item_type, 'licences': licences, 'subjects': [editor.views.generic.subject_json(subject) for subject in editor.models.Subject.objects.all()], 'topics': [editor.views.generic.topic_json(topic) for topic in editor.models.Topic.objects.all()], 'ability_frameworks': [editor.views.generic.ability_framework_json(af) for af in editor.models.AbilityFramework.objects.all()], 'previewURL': reverse('{}_preview'.format(self.object.editoritem.item_type), args=(self.object.pk, self.object.editoritem.slug)), 'previewWindow': str(calendar.timegm(time.gmtime())), 'current_stamp': editor.views.generic.stamp_json(self.object.editoritem.current_stamp) if self.object.editoritem.current_stamp else None, } if self.editable: self.item_json['public_access'] = self.object.editoritem.public_access self.item_json['access_rights'] = context['access_rights'] context['versions'] = [] # reversion.get_for_object(self.object) context['stamp_choices'] = editor.models.STAMP_STATUS_CHOICES context['preferred_locale'] = self.request.user.userprofile.language if not self.request.user.is_anonymous() else 'en-GB' context['locale_files'] = [code for name,code in settings.GLOBAL_SETTINGS['NUMBAS_LOCALES']] return context