Beispiel #1
0
 def create(self, validated_data):
     bookmark = Bookmark()
     bookmark.url = validated_data['url']
     bookmark.title = validated_data['title']
     bookmark.description = validated_data['description']
     tag_string = build_tag_string(validated_data['tag_names'], ' ')
     return create_bookmark(bookmark, tag_string, self.context['user'])
Beispiel #2
0
def delicious_import(request):
    if request.method == 'POST':
        form = DeliciousImportForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                soup = BeautifulStoneSoup(request.FILES['delicious_html'],
                    convertEntities="html", smartQuotesTo="html")
            except TypeError:
                raise forms.ValidationError("Not a delicious HTML file")
            rows = soup.findAll(['dt','dd'])
            for row in rows:
                if row.name == 'dd':
                    continue
                else:
                    bookmark = Bookmark()
                    link = row.first()
                    bookmark.title = link.text
                    bookmark.url = link['href']
                    bookmark.owner = request.user
                    pub_date = datetime.utcfromtimestamp(int(link['add_date']))
                    bookmark.pub_date = pub_date
                    bookmark.private = link['private'] == u"1"
                    if row.find('dd'):
                        bookmark.description = row.find('dd').text
                    bookmark.save()
                    if link.has_key('tags'):
                        tags = link['tags'].split(',')
                        for tag in tags:
                            if len(tag) > 0:
                                bookmark.tags.add(tag)
                        bookmark.save()
            url = reverse("user-list", args=[request.user.username])
            return HttpResponseRedirect(url)
    else:
        form = DeliciousImportForm()
    template_name = "bookmarks/delicious_import.html"
    context = {'form': form}
    return(template_name, context)
Beispiel #3
0
def _merge_bookmark_data(from_bookmark: Bookmark, to_bookmark: Bookmark):
    to_bookmark.title = from_bookmark.title
    to_bookmark.description = from_bookmark.description
Beispiel #4
0
 def update(self, instance: Bookmark, validated_data):
     instance.url = validated_data['url']
     instance.title = validated_data['title']
     instance.description = validated_data['description']
     tag_string = build_tag_string(validated_data['tag_names'], ' ')
     return update_bookmark(instance, tag_string, self.context['user'])