Example #1
0
class VideoForm(forms.Form):
    title = forms.CharField(required=True, error_messages=ERROR_MESSAGES)
    text = forms.CharField(required=True, error_messages=ERROR_MESSAGES)
    youtube_id = forms.CharField(required=True, error_messages=ERROR_MESSAGES)
    published_at = forms.DateTimeField(required=True,
                                       error_messages=ERROR_MESSAGES)
    introductions = forms.MultipleChoiceField(
        required=False,
        widget=forms.CheckboxSelectMultiple,
        choices=lambda: [(v.id, v.id) for v in Introduction.get_all()],
        error_messages=ERROR_MESSAGES)
    topics = forms.MultipleChoiceField(
        required=False,
        widget=forms.CheckboxSelectMultiple,
        choices=lambda: [(v.id, v.id) for v in Topic.get_all()],
        error_messages=ERROR_MESSAGES)
    categories = forms.MultipleChoiceField(
        required=False,
        widget=forms.CheckboxSelectMultiple,
        choices=lambda: [(v.id, v.id) for v in Category.get_all()],
        error_messages=ERROR_MESSAGES)
    videos = forms.MultipleChoiceField(
        required=False,
        widget=forms.CheckboxSelectMultiple,
        choices=lambda: [(v.id, v.id) for v in Video.get_all()],
        error_messages=ERROR_MESSAGES)
Example #2
0
    def remove_category(cls, video_id):
        all_category_ids = [v.id for v in Category.get_all()]
        try:
            video = cls.objects.get(id=video_id)
            for v in all_category_ids:
                video.category.remove(v)

        except:
            pass
Example #3
0
    def add_category(cls, video_id, category_ids):
        category_ids = list(map(int, category_ids))
        all_category_ids = [v.id for v in Category.get_all()]
        try:
            video = cls.objects.get(id=video_id)
            for v in all_category_ids:
                if v in category_ids:
                    try:
                        video.category.add(v)
                    except:
                        pass
                else:
                    video.category.remove(v)

        except:
            pass
Example #4
0
 def get(self):
     try:
         email = tornado.escape.xhtml_escape(self.current_user["email"])
         if email not in settings.ADMIN_EMAILS:
             self.render('denied.html')
         c = Category()
         try:
             result = c.get_all()
         except:
             result = {}
             #when no index structure exists
         #self.write(json.dumps(result))
         self.render("bo_category.html", categories=result)
     except Exception,e:
         logging.exception(e)
         self.render("404.html")
Example #5
0
 def get(self, request, *args, **kwargs):
     # NOTE: all end node category
     categories = Category.get_all()
     return Response([CategorySerializer(cate).data for cate in categories])