Ejemplo n.º 1
0
def cleanup_value(value, layer_type):
    #FIXME: what about other types? location etc
    if layer_type == 'text':
        value = ox.sanitize_html(value)
    else:
        value = ox.escape_html(value)
    return value
Ejemplo n.º 2
0
 def edit(self, data, user, item=None):
     for key in data:
         if key == 'name':
             data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip()
             if not data['name']:
                 data['name'] = "Untitled"
             name = data['name']
             num = 1
             while Document.objects.filter(name=name, user=self.user, extension=self.extension).exclude(id=self.id).count()>0:
                 num += 1
                 name = data['name'] + ' [%d]' % num
             self.name = name
         elif key == 'description' and not item:
             self.description = ox.sanitize_html(data['description'])
     if item:
         p, created = ItemProperties.objects.get_or_create(item=item, document=self)
         if 'description' in data:
             p.description = ox.sanitize_html(data['description'])
             p.save()
 def edit(self, data, user, item=None):
     for key in data:
         if key == 'name':
             data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip()
             if not data['name']:
                 data['name'] = "Untitled"
             name = data['name']
             num = 1
             while Document.objects.filter(
                     name=name, user=self.user,
                     extension=self.extension).exclude(
                         id=self.id).count() > 0:
                 num += 1
                 name = data['name'] + ' [%d]' % num
             self.name = name
         elif key == 'description' and not item:
             self.description = ox.sanitize_html(data['description'])
     if item:
         p, created = ItemProperties.objects.get_or_create(item=item,
                                                           document=self)
         if 'description' in data:
             p.description = ox.sanitize_html(data['description'])
             p.save()
Ejemplo n.º 4
0
def editPage(request):
    '''
        takes {
            name: pagename
            text: text
        }
        returns {
            name:
            text:
        }
    '''
    if request.user.get_profile().capability('canEditSitePages'):
        data = json.loads(request.POST['data'])
        page, created = models.Page.objects.get_or_create(name=data['name'])
        if not created:
            page.log()
        page.text = ox.sanitize_html(data['text'])
        page.save()
        response = json_response({'name': page.name, 'text': page.text})
    else:
        response = json_response(status=403, text='permission denied')
    return render_to_json_response(response)
Ejemplo n.º 5
0
def editPage(request):
    '''
        takes {
            name: pagename
            text: text
        }
        returns {
            name:
            text:
        }
    '''
    if request.user.get_profile().capability('canEditSitePages'):
        data = json.loads(request.POST['data'])
        page, created = models.Page.objects.get_or_create(name=data['name'])
        if not created:
            page.log()
        page.text = ox.sanitize_html(data['text'])
        page.save()
        response = json_response({'name': page.name, 'text': page.text})
    else:
        response = json_response(status=403, text='permission denied')
    return render_to_json_response(response)
    def edit(self, data, user):
        for key in data:
            if key == 'status':
                value = data[key]
                if value not in self._status:
                    value = self._status[0]
                if value == 'private':
                    for user in self.subscribed_users.all():
                        self.subscribed_users.remove(user)
                    qs = Position.objects.filter(user=user,
                                                 section='section',
                                                 text=self)
                    if qs.count() > 1:
                        pos = qs[0]
                        pos.section = 'personal'
                        pos.save()
                elif value == 'featured':
                    if user.get_profile().capability('canEditFeaturedTexts'):
                        pos, created = Position.objects.get_or_create(
                            text=self, user=user, section='featured')
                        if created:
                            qs = Position.objects.filter(user=user,
                                                         section='featured')
                            pos.position = qs.aggregate(
                                Max('position'))['position__max'] + 1
                            pos.save()
                        Position.objects.filter(text=self).exclude(
                            id=pos.id).delete()
                    else:
                        value = self.status
                elif self.status == 'featured' and value == 'public':
                    Position.objects.filter(text=self).delete()
                    pos, created = Position.objects.get_or_create(
                        text=self, user=self.user, section='personal')
                    qs = Position.objects.filter(user=self.user,
                                                 section='personal')
                    pos.position = qs.aggregate(
                        Max('position'))['position__max'] + 1
                    pos.save()
                    for u in self.subscribed_users.all():
                        pos, created = Position.objects.get_or_create(
                            text=self, user=u, section='public')
                        qs = Position.objects.filter(user=u, section='public')
                        pos.position = qs.aggregate(
                            Max('position'))['position__max'] + 1
                        pos.save()

                self.status = value
            elif key == 'name':
                data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip()
                if not data['name']:
                    data['name'] = "Untitled"
                name = data['name']
                num = 1
                while Text.objects.filter(name=name, user=self.user).exclude(
                        id=self.id).count() > 0:
                    num += 1
                    name = data['name'] + ' [%d]' % num
                self.name = name
            elif key == 'description':
                self.description = ox.sanitize_html(data['description'],
                                                    global_attributes=['lang'])
            elif key == 'text':
                self.text = ox.sanitize_html(
                    data['text'], global_attributes=['data-name', 'lang'])
            elif key == 'rightslevel':
                self.rightslevel = int(data['rightslevel'])

        if 'position' in data:
            pos, created = Position.objects.get_or_create(text=self, user=user)
            pos.position = data['position']
            pos.section = 'featured'
            if self.status == 'private':
                pos.section = 'personal'
            pos.save()
        if 'type' in data:
            self.type = data['type'] == 'pdf' and 'pdf' or 'html'
        if 'posterFrames' in data:
            self.poster_frames = tuple(data['posterFrames'])
        if 'embeds' in data:
            self.embeds = tuple(data['embeds'])
        self.save()
        if 'posterFrames' in data:
            self.update_icon()
Ejemplo n.º 7
0
    def edit(self, data, user):
        for key in data:
            if key == 'query' and not data['query']:
                setattr(self, key, {"static":True})
            elif key == 'query':
                setattr(self, key, data[key])
            elif key == 'type':
                if data[key] == 'static':
                    self.query = {"static":True}
                    self.type = 'static'
                else:
                    self.type = 'dynamic'
                    if self.query.get('static', False):
                         self.query = {}
            elif key == 'status':
                value = data[key]
                if value not in self._status:
                    value = self._status[0]
                if value == 'private':
                    for user in self.subscribed_users.all():
                        self.subscribed_users.remove(user)
                    qs = Position.objects.filter(user=user, list=self)
                    if qs.count() > 1:
                        pos = qs[0]
                        pos.section = 'personal'
                        pos.save()
                elif value == 'featured':
                    if user.get_profile().capability('canEditFeaturedLists'):
                        pos, created = Position.objects.get_or_create(list=self, user=user,
                                                                             section='featured')
                        if created:
                            qs = Position.objects.filter(user=user, section='featured')
                            pos.position = qs.aggregate(Max('position'))['position__max'] + 1
                            pos.save()
                        Position.objects.filter(list=self).exclude(id=pos.id).delete()
                    else:
                        value = self.status
                elif self.status == 'featured' and value == 'public':
                    Position.objects.filter(list=self).delete()
                    pos, created = Position.objects.get_or_create(list=self,
                                                  user=self.user, section='personal')
                    qs = Position.objects.filter(user=self.user, section='personal')
                    pos.position = qs.aggregate(Max('position'))['position__max'] + 1
                    pos.save()
                    for u in self.subscribed_users.all():
                        pos, created = Position.objects.get_or_create(list=self, user=u,
                                                                             section='public')
                        qs = Position.objects.filter(user=u, section='public')
                        pos.position = qs.aggregate(Max('position'))['position__max'] + 1
                        pos.save()

                self.status = value
            elif key == 'name':
                data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip()
                if not data['name']:
                    data['name'] = "Untitled"
                name = data['name']
                num = 1
                while List.objects.filter(name=name, user=self.user).exclude(id=self.id).count()>0:
                    num += 1
                    name = data['name'] + ' [%d]' % num
                self.name = name
            elif key == 'description':
                self.description = ox.sanitize_html(data['description'])

        if 'position' in data:
            pos, created = Position.objects.get_or_create(list=self, user=user)
            pos.position = data['position']
            pos.section = 'featured'
            if self.status == 'private':
                pos.section = 'personal'
            pos.save()
        if 'posterFrames' in data:
            self.poster_frames = tuple(data['posterFrames'])
        if 'view' in data:
            self.view = data['view']
        if 'sort' in data:
            self.sort= tuple(data['sort'])
        self.save()
        if 'posterFrames' in data:
            self.update_icon()
Ejemplo n.º 8
0
    def edit(self, data, user):
        for key in data:
            if key == 'status':
                value = data[key]
                if value not in self._status:
                    value = self._status[0]
                if value == 'private':
                    for user in self.subscribed_users.all():
                        self.subscribed_users.remove(user)
                    qs = Position.objects.filter(user=user,
                                                 section='section', text=self)
                    if qs.count() > 1:
                        pos = qs[0]
                        pos.section = 'personal'
                        pos.save()
                elif value == 'featured':
                    if user.get_profile().capability('canEditFeaturedTexts'):
                        pos, created = Position.objects.get_or_create(text=self, user=user,
                                                                             section='featured')
                        if created:
                            qs = Position.objects.filter(user=user, section='featured')
                            pos.position = qs.aggregate(Max('position'))['position__max'] + 1
                            pos.save()
                        Position.objects.filter(text=self).exclude(id=pos.id).delete()
                    else:
                        value = self.status
                elif self.status == 'featured' and value == 'public':
                    Position.objects.filter(text=self).delete()
                    pos, created = Position.objects.get_or_create(text=self,
                                                  user=self.user,section='personal')
                    qs = Position.objects.filter(user=self.user,
                                                        section='personal')
                    pos.position = qs.aggregate(Max('position'))['position__max'] + 1
                    pos.save()
                    for u in self.subscribed_users.all():
                        pos, created = Position.objects.get_or_create(text=self, user=u,
                                                                             section='public')
                        qs = Position.objects.filter(user=u, section='public')
                        pos.position = qs.aggregate(Max('position'))['position__max'] + 1
                        pos.save()

                self.status = value
            elif key == 'name':
                data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip()
                if not data['name']:
                    data['name'] = "Untitled"
                name = data['name']
                num = 1
                while Text.objects.filter(name=name, user=self.user).exclude(id=self.id).count()>0:
                    num += 1
                    name = data['name'] + ' [%d]' % num
                self.name = name
            elif key == 'description':
                self.description = ox.sanitize_html(data['description'])
            elif key == 'text':
                self.text = ox.sanitize_html(data['text'])
            elif key == 'rightslevel':
                self.rightslevel = int(data['rightslevel'])

        if 'position' in data:
            pos, created = Position.objects.get_or_create(text=self, user=user)
            pos.position = data['position']
            pos.section = 'featured'
            if self.status == 'private':
                pos.section = 'personal'
            pos.save()
        if 'type' in data:
            self.type = data['type'] == 'pdf' and 'pdf' or 'html'
        if 'posterFrames' in data:
            self.poster_frames = tuple(data['posterFrames'])
        if 'embeds' in data:
            self.embeds = tuple(data['embeds'])
        self.save()
        if 'posterFrames' in data:
            self.update_icon()
    def edit(self, data, user):
        for key in data:
            if key == 'query' and not data['query']:
                setattr(self, key, {"static": True})
            elif key == 'query':
                setattr(self, key, data[key])
            elif key == 'type':
                if data[key] == 'static':
                    self.query = {"static": True}
                    self.type = 'static'
                else:
                    self.type = 'dynamic'
                    if self.query.get('static', False):
                        self.query = {}
            elif key == 'status':
                value = data[key]
                if value not in self._status:
                    value = self._status[0]
                if value == 'private':
                    for user in self.subscribed_users.all():
                        self.subscribed_users.remove(user)
                    qs = Position.objects.filter(user=user, list=self)
                    if qs.count() > 1:
                        pos = qs[0]
                        pos.section = 'personal'
                        pos.save()
                elif value == 'featured':
                    if user.get_profile().capability('canEditFeaturedLists'):
                        pos, created = Position.objects.get_or_create(
                            list=self, user=user, section='featured')
                        if created:
                            qs = Position.objects.filter(user=user,
                                                         section='featured')
                            pos.position = qs.aggregate(
                                Max('position'))['position__max'] + 1
                            pos.save()
                        Position.objects.filter(list=self).exclude(
                            id=pos.id).delete()
                    else:
                        value = self.status
                elif self.status == 'featured' and value == 'public':
                    Position.objects.filter(list=self).delete()
                    pos, created = Position.objects.get_or_create(
                        list=self, user=self.user, section='personal')
                    qs = Position.objects.filter(user=self.user,
                                                 section='personal')
                    pos.position = qs.aggregate(
                        Max('position'))['position__max'] + 1
                    pos.save()
                    for u in self.subscribed_users.all():
                        pos, created = Position.objects.get_or_create(
                            list=self, user=u, section='public')
                        qs = Position.objects.filter(user=u, section='public')
                        pos.position = qs.aggregate(
                            Max('position'))['position__max'] + 1
                        pos.save()

                self.status = value
            elif key == 'name':
                data['name'] = re.sub(' \[\d+\]$', '', data['name']).strip()
                if not data['name']:
                    data['name'] = "Untitled"
                name = data['name']
                num = 1
                while List.objects.filter(name=name, user=self.user).exclude(
                        id=self.id).count() > 0:
                    num += 1
                    name = data['name'] + ' [%d]' % num
                self.name = name
            elif key == 'description':
                self.description = ox.sanitize_html(data['description'])

        if 'position' in data:
            pos, created = Position.objects.get_or_create(list=self, user=user)
            pos.position = data['position']
            pos.section = 'featured'
            if self.status == 'private':
                pos.section = 'personal'
            pos.save()
        if 'posterFrames' in data:
            self.poster_frames = tuple(data['posterFrames'])
        if 'view' in data:
            self.view = data['view']
        if 'sort' in data:
            self.sort = tuple(data['sort'])
        self.save()
        if 'posterFrames' in data:
            self.update_icon()