Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1from crispy_forms.bootstrap import FormActions 

2from crispy_forms.helper import FormHelper 

3from crispy_forms.layout import HTML, Div, Field, Layout, Submit 

4from django import forms 

5from django.forms import ModelForm 

6 

7from discuss_data.ddusers.models import Affiliation, Project, User 

8 

9UPDATED_MSG = """ 

10 {% if updated %}<div id='updated-msg' class='alert alert-success' ic-trigger-on='scrolled-into-view' ic-action='delay:2500;fadeOut;remove' role='alert'> 

11 <span class='spinner-sm'></span><strong>{{ target|title }} saved</strong></div>{% endif %} 

12 {% if err %}<div id='updated-msg' class='alert alert-danger' role='alert'> 

13 <span class='spinner-sm'></span><strong>Error! {{ target|title }} could not be saved. Error encountered in fields {% for field in err %} {{ field }}, {% endfor %}</strong></div> {% endif %}""" 

14 

15ADD_EDIT_HEADING = ( 

16 "<h2>{% if new %}Add{% else %}Edit{% endif %} {{ target|title }}</h2><hr>" 

17) 

18REQ_FIELD = "<p class='help-block'>[*] required field</p>" 

19 

20ACCESSIBILTY_TEXT = """ 

21 <div class="col-md-6"> 

22 <div class="card border-primary mb-3"> 

23 <div class="card-body text-primary"> 

24 <p class="card-text"> 

25 Set <b>Profile accessibility</b> to <b>public</b> if you want your profile to be found by everyone. Set to <b>internal</b> to limit your profile views to registered Discuss Data users and to <b>hidden</b> if you don't want your profile to be viewed and found at all. 

26 </p> 

27 </div> 

28 </div> 

29 </div>""" 

30 

31 

32class UserForm(ModelForm): 

33 class Meta: 

34 model = User 

35 fields = [ 

36 # "name_prefix", 

37 # "name_suffix", 

38 "first_name", 

39 # "middle_name", 

40 "last_name", 

41 "email", 

42 "research_profile_short", 

43 "research_profile_full", 

44 "external_profile", 

45 "profile_accessibility", 

46 ] 

47 

48 first_name = forms.CharField(disabled=True) 

49 last_name = forms.CharField(disabled=True) 

50 email = forms.EmailField(disabled=True) 

51 

52 helper = FormHelper() 

53 helper.form_tag = False 

54 helper.layout = Layout( 

55 # HTML(ADD_EDIT_HEADING), 

56 Div( 

57 # Div("name_prefix", css_class="col-md-2",), 

58 Div("first_name", css_class="col-md-4",), 

59 # Div("middle_name", css_class="col-md-2",), 

60 Div("last_name", css_class="col-md-4",), 

61 Div("email", css_class="col-md-4",), 

62 # Div("name_suffix", css_class="col-md-2",), 

63 css_class="row", 

64 ), 

65 Div( 

66 Div("research_profile_short", css_class="col-md-6",), 

67 Div("research_profile_full", css_class="col-md-6",), 

68 css_class="row", 

69 ), 

70 Div(Div("external_profile", css_class="col-md-12",), css_class="row",), 

71 Div( 

72 Div("profile_accessibility", css_class="col-md-6",), 

73 # HTML(ACCESSIBILTY_TEXT), 

74 css_class="row", 

75 ), 

76 HTML(REQ_FIELD), 

77 HTML("<span id='indicator'><span class='spinner-sm'></span> Saving...</span>"), 

78 FormActions( 

79 Submit( 

80 "save", 

81 "Save {{ target }}", 

82 data_toggle="collapse", 

83 data_target="#collapse-userdata-edit", 

84 ), 

85 ), 

86 Div(HTML(UPDATED_MSG),), 

87 ) 

88 

89 

90class UserImageForm(ModelForm): 

91 class Meta: 

92 model = User 

93 fields = [ 

94 "photo", 

95 ] 

96 

97 

98class AffiliationForm(ModelForm): 

99 class Meta: 

100 model = Affiliation 

101 fields = [ 

102 "name_of_institution", 

103 "website_of_institution", 

104 "place_of_institution", 

105 "country_of_institution", 

106 "position", 

107 "main", 

108 ] 

109 

110 helper = FormHelper() 

111 helper.form_tag = False 

112 helper.layout = Layout( 

113 Div( 

114 Div("name_of_institution", css_class="col-md-12",), 

115 Div("website_of_institution", css_class="col-md-12",), 

116 Div("place_of_institution", css_class="col-md-6",), 

117 Div("country_of_institution", css_class="col-md-6",), 

118 Div("position", css_class="col-md-12",), 

119 Field( 

120 "main", css_class="custom-control-input", template="core/_checkbox.html" 

121 ), 

122 css_class="row", 

123 ), 

124 HTML(REQ_FIELD), 

125 HTML("<span id='indicator'><span class='spinner-sm'></span> Saving...</span>"), 

126 FormActions(Submit("save", "Save {{ target }}", ic_indicator="#indicator"),), 

127 Div(HTML(UPDATED_MSG),), 

128 ) 

129 

130 

131class ProjectForm(ModelForm): 

132 class Meta: 

133 model = Project 

134 fields = [ 

135 "name", 

136 "url", 

137 "description", 

138 ] 

139 

140 helper = FormHelper() 

141 helper.form_tag = False 

142 helper.layout = Layout( 

143 Div( 

144 Div("name", css_class="col-md-12",), 

145 Div("url", css_class="col-md-12",), 

146 Div("description", css_class="col-md-12",), 

147 css_class="row", 

148 ), 

149 HTML(REQ_FIELD), 

150 FormActions(Submit("save", "Save {{ target }}"),), 

151 Div(HTML(UPDATED_MSG),), 

152 ) 

153 

154 

155class DariahTermsOfUse(ModelForm): 

156 class Meta: 

157 model = User 

158 fields = [ 

159 "accepted_dariah_tou", 

160 ] 

161 

162 helper = FormHelper() 

163 helper.form_tag = False 

164 

165 helper.layout = Layout( 

166 Div(Div("accepted_dariah_tou", css_class="col-md-8",), css_class="row",), 

167 FormActions(Submit("save", "Save {{ target }}"),), 

168 Div(HTML(UPDATED_MSG),), 

169 )