def subscribe(request): user = request.user categories = MCategory.serialize() category_titles = [c['title'] for c in categories['categories']] subscribe_category_titles = request.REQUEST.getlist('category') invalid_category_title = False for category_title in subscribe_category_titles: if category_title not in category_titles: invalid_category_title = True if not subscribe_category_titles or invalid_category_title: message = "Choose one or more of these categories: %s" % ', '.join( category_titles) return dict(code=-1, message=message) for category_title in subscribe_category_titles: MCategory.subscribe(user.pk, category_title) usf = UserSubscriptionFolders.objects.get(user=user.pk) return dict(code=1, message="Subscribed to %s %s" % ( len(subscribe_category_titles), 'category' if len(subscribe_category_titles) == 1 else 'categories', ), folders=json.decode(usf.folders))
def handle(self, *args, **options): feed_id = options.get('feed') category_title = options.get('title') if feed_id and category_title: category_site_db = { "feed_id": feed_id, "category_title": category_title } MCategorySite.objects.create(**category_site_db) MCategory.reload_sites(category_title) print " ---> All notification sent!"
def subscribe(request): user = request.user categories = MCategory.serialize() category_titles = [c['title'] for c in categories['categories']] subscribe_category_titles = request.REQUEST.getlist('category') or request.REQUEST.getlist('category[]') invalid_category_title = False for category_title in subscribe_category_titles: if category_title not in category_titles: invalid_category_title = True if not subscribe_category_titles or invalid_category_title: message = "Choose one or more of these categories: %s" % ', '.join(category_titles) return dict(code=-1, message=message) for category_title in subscribe_category_titles: MCategory.subscribe(user.pk, category_title) usf = UserSubscriptionFolders.objects.get(user=user.pk) return dict(code=1, message="Subscribed to %s %s" % ( len(subscribe_category_titles), 'category' if len(subscribe_category_titles) == 1 else 'categories', ), folders=json.decode(usf.folders))
def all_categories(request): categories = MCategory.serialize() return categories