def new(request): if not request.user: return HttpResponseRedirect(reverse('registration.views.login')) source = None fields = None sn_types = SNType.objects.all() if 'src' in request.GET: source = request.GET['src'] #rss feed if source == 'rss': error = 0 if request.POST: response = str(feedtest(request)) if response.find('Feed ok') == -1: error = 1 else: pp = PostPlace() pp.sn_type = SNType.objects.get(code='rss') pp.url = request.POST['feedurl'] pp.user = request.user pp.save() s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) fields = [ {'name': 'feedurl', 'type': 'text', 'size': 50, 'label': 'Feed URL', 'sort': 0}, #{'name': 'feederror', 'type': 'error', 'message': '!!!!!'}, {'name': 'testfeed', 'type': 'button', 'size': 5, 'value': 'Test feed', 'onclick': 'feedtest();', 'sort': 3}, {'name': 'testfeedresult', 'type': 'alertdiv', 'sort': 4}, {'name': 'feeduptime', 'type': 'select', 'values': [{'value': 30, 'name': '30 min'}], 'label': 'Refresh time', 'sort': 5}, {'name': 'feedsave', 'type': 'submit', 'value': 'Далее', 'sort': 6}, ] if error: import operator fields.append({'name': 'feederror', 'type': 'error', 'message': "Не получается разобрать RSS канал. Может в URL ошиблись?", 'sort': 1}) fields.sort(key=operator.itemgetter('sort')) # vkontakte if source == 'vk': pp = vkauth(request) if pp: s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) fields = [ #{'name': 'message', 'type': 'message', 'message': vk_notice}, {'name': 'vkauth', 'type': 'button', 'size': 5, 'value': 'Авторизация через сайт Vkontakte', 'onclick': 'vkontakteauth(\'%s%s?%s\');' % (HTTP_HOST, reverse('my.views.new'), 'src=vk')}, #{'name': 'token', 'type': 'text', 'size': 50, 'label': 'Token'}, #{'name': 'feedsave', 'type': 'submit', 'value': 'Далее'}, ] # twitter if source == 'twitter': pp = twauth(request) if pp: s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) tw = Tweet(twitter_settings) register = tw.register( callbackurl="%s%s?src=twitter" % (HTTP_HOST, reverse('my.views.new'))) request.session['oauth_token_secret'] = register['data']['oauth_token_secret'] request.session['oauth_token'] = register['data']['oauth_token'] fields = [ {'name': 'twauth', 'type': 'button', 'size': 5, 'value': 'Авторизоваться через Twitter', 'onclick': 'twitterauth(\'%s?src=twitter\', \'%s\');' % ( reverse('my.views.new'), register['url'])}, ] #facebook if source == 'fb': pp = fbauth(request) if pp: s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) fb_settings['redirect_uri'] = "%s%s?src=fb" % (HTTP_HOST, reverse('my.views.new')) fb = FB(fb_settings) url = fb.register() fields = [ {'name': 'fbauth', 'type': 'button', 'size': 5, 'value': 'Авторизоваться через Facebook', 'onclick': 'facebookauth(\'%s\');' % url}, ] # forsquare if source == 'fs': callbackurl = "%s%s%%3Fsrc%%3Dfs" % (HTTP_HOST, reverse('my.views.new')) pp = fsauth(request, callbackurl) if pp: s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) fields = [ {'name': 'fsauth', 'type': 'button', 'size': 5, 'value': 'Авторизация через сайт Foursquare', 'onclick': 'foursquareauth(\'%s\');' % callbackurl}, ] #livejournal if source == 'lj': if request.POST: pp = PostPlace() pp.sn_type = SNType.objects.get(code='lj') pp.user = request.user pp.login = request.POST['user'] pp.password = md5.md5(request.POST['password']).hexdigest() pp.save() s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) fields = [ {'name': 'message', 'type': 'message', 'message': lj_notice}, {'name': 'user', 'type': 'text', 'size': 50, 'label': 'Lj user'}, {'name': 'password', 'type': 'password', 'size': 50, 'label': 'Password'}, {'name': 'feedsave', 'type': 'submit', 'value': 'Продолжить'}, ] return {'sn_types': sn_types, 'source': source, 'fields': fields}
def processSource(self): #rss feed fields = None if self.sntype.code == 'rss': if self.request.POST: pp = PostPlace() pp.sn_type = SNType.objects.get(code='rss') pp.url = self.request.POST['feedurl'] pp.user = self.request.user pp.save() s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) fields = [ {'name': 'feedurl', 'type': 'text', 'size': 50, 'label': 'Feed URL'}, {'name': 'testfeed', 'type': 'button', 'size': 5, 'value': 'Test feed', 'onclick': 'feedtest();'}, {'name': 'testfeedresult', 'type': 'alertdiv'}, {'name': 'feeduptime', 'type': 'select', 'values': [{'value': 30, 'name': '30 min'}], 'label': 'Refresh time'}, {'name': 'feedsave', 'type': 'submit', 'value': 'Save feed'}, ] # vkontakte if self.sntype.code == 'vk': pp = vkauth(self.request) if pp: s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) fields = [ {'name': 'vkauth', 'type': 'button', 'size': 5, 'value': 'Авторизация через сайт Vkontakte', 'onclick': 'vkontakteauth(\'%s%s?%s\');' % (HTTP_HOST, reverse('my.views.new'), 'src=vk')}, ] # twitter if self.sntype.code == 'twitter': pp = twauth(self.request) if pp: s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) tw = Tweet(twitter_settings) register = tw.register( callbackurl="%s%s?src=twitter" % (HTTP_HOST, reverse('my.views.new'))) request.session['oauth_token_secret'] = register['data']['oauth_token_secret'] request.session['oauth_token'] = register['data']['oauth_token'] fields = [ {'name': 'twauth', 'type': 'button', 'size': 5, 'value': 'Twitter auth', 'onclick': 'twitterauth(\'%s?src=twitter\', \'%s\');' % ( reverse('my.views.new'), register['url'])}, ] #facebook if self.sntype.code == 'fb': pp = fbauth(request) if pp: s = Sync() s.source = pp s.user = pp.user s.save() return HttpResponseRedirect(reverse('my.views.sync', args=[s.id])) fb_settings['redirect_uri'] = "%s%s?src=fb" % (HTTP_HOST, reverse('my.views.new')) fb = FB(fb_settings) url = fb.register() fields = [ {'name': 'fbauth', 'type': 'button', 'size': 5, 'value': 'Авторизоваться через Facebook', 'onclick': 'facebookauth(\'%s\');' % url}, ] return {'fileds' : fields}