def eos_delete(self) -> str: config = Settings.get_solo() uri = f'{config.eosgate}/form' payload = { 'form': self.uid, } r = requests.delete(uri, json=payload) return r.content.decode()
def send_to_eos(self): settings = Settings.get_solo() uri = f'{settings.eosgate}/response' payload = { 'form': self._survey.uid, 'answers': list(self.cleaned_data.values()) } participation = Participation(user=self._user, survey=self._survey) r = requests.post(uri, json=payload) data = r.content.decode() if r.status_code == 200: participation.txid = data participation.save() return r.content.decode()
def get_responses_curl(self) -> str: """ cURL link to retrieve data in JSON format :return: string """ settings = Settings.get_solo() endpoint = f'{settings.eos_node_uri}/v1/chain/get_table_rows' data = json.dumps({ 'code': settings.eos_account, 'table': 'response', 'scope': self.uid, 'limit': 10000, 'json': True }) return f'curl --request "POST" ' \ f'--url {endpoint} ' \ f'--data \'{data}\''
def eos_publish(self) -> str: """ Send the command to the EOSGate service and return trxid or error message :return: """ config = Settings.get_solo() uri = f'{config.eosgate}/form' payload = { 'form': self.uid, 'questions': list(self.questions.values_list('name', flat=True)) } r = requests.post(uri, json=payload) if r.status_code == 200: self.status = SurveyStatus.PUBLISHED.value self.save() return r.content.decode()
def reset_password(self): config = Settings.get_solo() otp = OTP('reset_password', self.id) link = reverse('users:reset-pass-finish', kwargs={ 'id': self.id, 'code': otp.code, }) ctx = {'domain': config.domain, 'link': f'{config.domain}{link}'} rts = render_to_string msg = rts(self.get_email_template('reset_password'), ctx) msg_html = rts(self.get_email_template('reset_password', 'html'), ctx) kwargs = { 'subject': _('[eosform] Reset password'), 'message': msg, 'html_message': msg_html, } self.email_user(**kwargs)
def request_confirm_email(self): config = Settings.get_solo() otp = OTP('confirm_signup', self.id) rts = render_to_string link = reverse('users:confirm-signup', kwargs={ 'pk': self.id, 'code': otp.code, }) ctx = { 'domain': config.domain, # TODO finish the URL 'link': f'{config.domain}{link}' } msg = rts(self.get_email_template('confirm_signup'), ctx) msg_html = rts(self.get_email_template('confirm_signup', 'html'), ctx) kwargs = { 'subject': _('[eosform] Confirm signup'), 'message': msg, 'html_message': msg_html, } self.email_user(**kwargs)
def get_response_url(self): settings = Settings.get_solo() return f'{settings.domain}' \ f'{reverse("surveys:response", args=(self.uid,))}'
def __init__(self): self.settings = Settings.get_solo() self.uri = self.settings.eosgate self.api = self.settings.eos_node_uri