コード例 #1
0
ファイル: user.py プロジェクト: yaser24276/askbot-devel
 def save(self, *args, **kwargs):
     type = self.feed_type
     subscriber = self.subscriber
     similar = self.__class__.objects\
         .filter(feed_type=type, subscriber=subscriber)\
         .exclude(pk=self.id)
     if similar.exists():
         raise IntegrityError('email feed setting already exists')
     super(EmailFeedSetting, self).save(*args, **kwargs)
コード例 #2
0
ファイル: views.py プロジェクト: chrigu6/vocabulary
def populate_words(request):
    if request.method == 'POST':
        language = Language.objects.get(name=request.POST['language'])
        file = request.FILES['file']
        words = []
        for line in file:
            if line == "\n" or line == " \n":
                continue
            word = Word(word=line, language=language)
            words.append(word.word)
            try:
                word.save()
            except:
                IntegrityError()

        context = {"words": words}
        return render(request, 'trainer/upload_success.html', context)

    else:
        form = UploadFileForm()
        return render(request, 'trainer/populate.html', {'form': form})

    return render(request, 'trainer/populate.html')