コード例 #1
0
    def update_event(self, event):
        ret = []

        if not self.is_valid():
            ret.append(
                Message(_('Entered data was invalid, no changes made.'),
                        type=Message.ERROR))
            for field, errors in self.errors.items():
                for error in errors:
                    ret.append(
                        Message(error=error, field=self.fields[field].label))
            return ret

        story = Story(
            event=event,
            player_id=self.cleaned_data['player'],
            date=self.cleaned_data['date'],
            text=self.cleaned_data['text'],
        )
        story.save()

        # Translators: Stories are the dots on a player's rating chart
        ret.append(Message(_('Added a story.'), type=Message.SUCCESS))

        return ret
コード例 #2
0
ファイル: tasks.py プロジェクト: ysperetz/thesis
def fetch_from_reddit():
    for name in settings.SUBREDDITS:
        reddit = praw.Reddit(user_agent=name + ' user agent')
        subreddit = reddit.get_subreddit(name)
        submissions = subreddit.get_hot(limit=settings.MAX_STORIES)
        for x in submissions:
            if Story.objects.filter(id36=x.id).count() == 0:
                story = Story(id36=x.id,
                              content=x.title,
                              label=0,
                              subreddit=name)
                story.save()
コード例 #3
0
ファイル: results_views.py プロジェクト: KenanY/aligulac
    def update_event(self, event):
        ret = []

        if not self.is_valid():
            ret.append(Message(_('Entered data was invalid, no changes made.'), type=Message.ERROR))
            for field, errors in self.errors.items():
                for error in errors:
                    ret.append(Message(error=error, field=self.fields[field].label))
            return ret

        if self.action in ['upd', 'del']:
            try:
                print('id:', self.cleaned_data['story_id'])
                story = Story.objects.get(id=self.cleaned_data['story_id'])
            except:
                ret.append(Message(_('Story could not be found.'), type=Message.ERROR))
                return ret

            if self.action == 'upd':
                story.date = self.cleaned_data['date']
                story.message = self.cleaned_data['text']
                story.params = self.cleaned_data['params']

                print(story.params)

                if story.verify():
                    story.save()
                    ret.append(Message(_('Story was successfully changed.'), type=Message.SUCCESS))
                else:
                    ret.append(Message(_('Parameter verification failed.'), type=Message.ERROR))

            elif self.action == 'del':
                story.delete()
                ret.append(Message(_('Story was successfully deleted.'), type=Message.SUCCESS))

        elif self.action == 'new':
            story = Story(
                player=Player.objects.get(id=self.cleaned_data['player']),
                event=event,
                date=self.cleaned_data['date'],
                message=self.cleaned_data['text'],
                params=self.cleaned_data['params']
            )
            if story.verify():
                story.save()
                ret.append(Message(_('Story was successfully created.'), type=Message.SUCCESS))
            else:
                ret.append(Message(_('Parameter verification failed.'), type=Message.ERROR))

        return ret
コード例 #4
0
    def update_event(self, event):
        ret = []

        if not self.is_valid():
            ret.append(Message(_('Entered data was invalid, no changes made.'), type=Message.ERROR))
            for field, errors in self.errors.items():
                for error in errors:
                    ret.append(Message(error=error, field=self.fields[field].label))
            return ret

        if self.action in ['upd', 'del']:
            try:
                print('id:', self.cleaned_data['story_id'])
                story = Story.objects.get(id=self.cleaned_data['story_id'])
            except:
                ret.append(Message(_('Story could not be found.'), type=Message.ERROR))
                return ret

            if self.action == 'upd':
                story.date = self.cleaned_data['date']
                story.message = self.cleaned_data['text']
                story.params = self.cleaned_data['params']

                print(story.params)

                if story.verify():
                    story.save()
                    ret.append(Message(_('Story was successfully changed.'), type=Message.SUCCESS))
                else:
                    ret.append(Message(_('Parameter verification failed.'), type=Message.ERROR))

            elif self.action == 'del':
                story.delete()
                ret.append(Message(_('Story was successfully deleted.'), type=Message.SUCCESS))

        elif self.action == 'new':
            story = Story(
                player=Player.objects.get(id=self.cleaned_data['player']),
                event=event,
                date=self.cleaned_data['date'],
                message=self.cleaned_data['text'],
                params=self.cleaned_data['params']
            )
            if story.verify():
                story.save()
                ret.append(Message(_('Story was successfully created.'), type=Message.SUCCESS))
            else:
                ret.append(Message(_('Parameter verification failed.'), type=Message.ERROR))

        return ret
コード例 #5
0
ファイル: results_views.py プロジェクト: HotspurHN/aligulac
    def update_event(self, event):
        ret = []

        if not self.is_valid():
            ret.append(Message('Entered data was invalid, no changes made.', type=Message.ERROR))
            for field, errors in self.errors.items():
                for error in errors:
                    ret.append(Message(error=error, field=self.fields[field].label))
            return ret

        story = Story(
            event=event,
            player_id=self.cleaned_data['player'],
            date=self.cleaned_data['date'],
            text=self.cleaned_data['text'],
        )
        story.save()

        ret.append(Message('Added a story.', type=Message.SUCCESS))

        return ret