예제 #1
0
    def add(user,
            url,
            title,
            timestamp=None,
            kind=None,
            description=None,
            content=None,
            tags=None,
            colour=None):
        d = Datasheet(user=user, url=url, title=unicode(title))
        d.description = unicode(description)
        d.content = unicode(content)

        if timestamp:
            d.timestamp = timestamp
        if tags:
            d.tags = [unicode(tag) for tag in tags]
        if lookup_in_tuple(ADDITIONAL_TYPES, kind):
            d.kind = unicode(kind)
        if lookup_in_tuple(COLOUR_CODES, colour):
            d.colour = colour
        try:
            log.info('Saving highlight %s' % d)
            d.save()
        except:
            log.error('Failed to save highlight for user: %s' % user)

        # Updating the tag structures
        if tags:
            tc = TagContol(user)
            [tc.tagIncrement(tag) for tag in d.tags]
예제 #2
0
	def clean_kind(self):
		kind = self.cleaned_data['kind']
		if not kind:
			return None
		if not lookup_in_tuple(ADDITIONAL_TYPES, kind.upper()):
			raise forms.ValidationError("Unsupported datasheet kind requested.")
		return kind.upper()
예제 #3
0
    def modify(user,
               d_id,
               url=None,
               title=None,
               kind=None,
               description=None,
               content=None,
               tags=None,
               colour=None):
        try:
            d = Datasheet.objects.get(id=d_id)
        except:
            return

        if url:
            d.url = unicode(url)
        if title:
            d.title = unicode(title)
        if lookup_in_tuple(ADDITIONAL_TYPES, kind):
            d.kind = unicode(kind)

        # The following can be empty
        d.description = unicode(description)
        d.content = unicode(content)

        # Updating tag structures
        tc = TagContol(user)
        # Decrement old tags (Tag Model)
        if d.tags:
            [tc.tagDecrement(tag) for tag in d.tags]
        # Updating to new tags (Webpage Model)
        if tags:
            d.tags = [unicode(tag) for tag in tags]
        else:
            d.tags = None
        # Increment new tags (Tag Model)
        if tags:
            [tc.tagIncrement(tag) for tag in tags]

        try:
            d.save()
        except:
            log.error('Failed to modify highlight for user: %s' % user)